diff --git a/substrate/bin/node/runtime/src/weights/frame_system.rs b/substrate/bin/node/runtime/src/weights/frame_system.rs index b1fdf69640602d7a042579332ce36b56ba240ec2..6831dad0620d6738ae7bff0f8e58a44d07715207 100644 --- a/substrate/bin/node/runtime/src/weights/frame_system.rs +++ b/substrate/bin/node/runtime/src/weights/frame_system.rs @@ -24,15 +24,13 @@ use sp_std::marker::PhantomData; pub struct WeightInfo<T>(PhantomData<T>); impl<T: frame_system::Trait> frame_system::WeightInfo for WeightInfo<T> { - // WARNING! Some components were not used: ["b"] - fn remark() -> Weight { + fn remark(_b: u32) -> Weight { (1305000 as Weight) } fn set_heap_pages() -> Weight { (2023000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } - // WARNING! Some components were not used: ["d"] fn set_changes_trie_config() -> Weight { (10026000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) diff --git a/substrate/bin/node/runtime/src/weights/pallet_timestamp.rs b/substrate/bin/node/runtime/src/weights/pallet_timestamp.rs index 9c363898b7f3b3df2620e5ea763fc8fda2deec2a..ee0dd77c63af080412a99d80b13363892daf8612 100644 --- a/substrate/bin/node/runtime/src/weights/pallet_timestamp.rs +++ b/substrate/bin/node/runtime/src/weights/pallet_timestamp.rs @@ -22,13 +22,11 @@ use sp_std::marker::PhantomData; pub struct WeightInfo<T>(PhantomData<T>); impl<T: frame_system::Trait> pallet_timestamp::WeightInfo for WeightInfo<T> { - // WARNING! Some components were not used: ["t"] fn set() -> Weight { (9133000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } - // WARNING! Some components were not used: ["t"] fn on_finalize() -> Weight { (5915000 as Weight) } diff --git a/substrate/bin/node/runtime/src/weights/pallet_treasury.rs b/substrate/bin/node/runtime/src/weights/pallet_treasury.rs index 0bf9e6ab784c4ded672cdbd7fd4f3edd9f3b5952..d8fe9b578b2750f5b2edb9750f81b1a1be5d7e57 100644 --- a/substrate/bin/node/runtime/src/weights/pallet_treasury.rs +++ b/substrate/bin/node/runtime/src/weights/pallet_treasury.rs @@ -46,7 +46,6 @@ impl<T: frame_system::Trait> pallet_treasury::WeightInfo for WeightInfo<T> { .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } - // WARNING! Some components were not used: ["r"] fn retract_tip() -> Weight { (82970000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) diff --git a/substrate/bin/node/runtime/src/weights/pallet_utility.rs b/substrate/bin/node/runtime/src/weights/pallet_utility.rs index 2c508ed6cd42d6f0b89c41c811ad88545c4b2f6c..af48267d9b5de07608c6fd5f1ac5d8f54f5076f3 100644 --- a/substrate/bin/node/runtime/src/weights/pallet_utility.rs +++ b/substrate/bin/node/runtime/src/weights/pallet_utility.rs @@ -29,7 +29,6 @@ impl<T: frame_system::Trait> pallet_utility::WeightInfo for WeightInfo<T> { (16461000 as Weight) .saturating_add((1982000 as Weight).saturating_mul(c as Weight)) } - // WARNING! Some components were not used: ["u"] fn as_derivative() -> Weight { (4086000 as Weight) } diff --git a/substrate/frame/system/benchmarking/src/lib.rs b/substrate/frame/system/benchmarking/src/lib.rs index 653d9536f17972925908290f97ee4d59ee6d6715..9b630520e65d77d79cc9d0124ab500813d01a5ab 100644 --- a/substrate/frame/system/benchmarking/src/lib.rs +++ b/substrate/frame/system/benchmarking/src/lib.rs @@ -61,7 +61,7 @@ benchmarks! { } set_changes_trie_config { - let d in 0 .. 1000; + let d = 1000; let digest_item = DigestItemOf::<T>::Other(vec![]); diff --git a/substrate/frame/system/src/default_weights.rs b/substrate/frame/system/src/default_weights.rs index 8a84cb0b7903a4190ea49c2ac3be81dac3892018..8b0c17a285157e332fd19748dfe617c93a62d3e5 100644 --- a/substrate/frame/system/src/default_weights.rs +++ b/substrate/frame/system/src/default_weights.rs @@ -22,15 +22,13 @@ use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; impl crate::WeightInfo for () { - // WARNING! Some components were not used: ["b"] - fn remark() -> Weight { + fn remark(_b: u32) -> Weight { (1305000 as Weight) } fn set_heap_pages() -> Weight { (2023000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) } - // WARNING! Some components were not used: ["d"] fn set_changes_trie_config() -> Weight { (10026000 as Weight) .saturating_add(DbWeight::get().reads(1 as Weight)) diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index 9518317f7bd54cf1de95ef6c65757a0e43bd2c95..e9b7a6d9f710f6136ff791295ad3f0da3f3551df 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -160,7 +160,7 @@ pub fn extrinsics_data_root<H: Hash>(xts: Vec<Vec<u8>>) -> H::Output { } pub trait WeightInfo { - fn remark() -> Weight; + fn remark(b: u32) -> Weight; fn set_heap_pages() -> Weight; fn set_changes_trie_config() -> Weight; fn set_storage(i: u32, ) -> Weight; @@ -570,7 +570,7 @@ decl_module! { /// - Base Weight: 0.665 µs, independent of remark length. /// - No DB operations. /// # </weight> - #[weight = T::SystemWeightInfo::remark()] + #[weight = T::SystemWeightInfo::remark(_remark.len() as u32)] fn remark(origin, _remark: Vec<u8>) { ensure_signed(origin)?; } diff --git a/substrate/frame/timestamp/src/benchmarking.rs b/substrate/frame/timestamp/src/benchmarking.rs index 1cd0f15ca01b936956694f1ade3e56c0b6f4859e..a0700179a933636cf48ba3e23e547ff0805a8e4a 100644 --- a/substrate/frame/timestamp/src/benchmarking.rs +++ b/substrate/frame/timestamp/src/benchmarking.rs @@ -33,7 +33,7 @@ benchmarks! { _ { } set { - let t in 1 .. MAX_TIME; + let t = MAX_TIME; // Ignore write to `DidUpdate` since it transient. let did_update_key = crate::DidUpdate::hashed_key().to_vec(); frame_benchmarking::benchmarking::add_to_whitelist(TrackedStorageKey { @@ -47,7 +47,7 @@ benchmarks! { } on_finalize { - let t in 1 .. MAX_TIME; + let t = MAX_TIME; Timestamp::<T>::set(RawOrigin::None.into(), t.into())?; ensure!(DidUpdate::exists(), "Time was not set."); // Ignore read/write to `DidUpdate` since it is transient. diff --git a/substrate/frame/timestamp/src/default_weights.rs b/substrate/frame/timestamp/src/default_weights.rs index 726b3444e2532eec6b1cc9df9305ea4f95eb3548..d8db0182282b2ebc9c7cc17dd9f345e7698e0a4f 100644 --- a/substrate/frame/timestamp/src/default_weights.rs +++ b/substrate/frame/timestamp/src/default_weights.rs @@ -22,13 +22,11 @@ use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; impl crate::WeightInfo for () { - // WARNING! Some components were not used: ["t"] fn set() -> Weight { (9133000 as Weight) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } - // WARNING! Some components were not used: ["t"] fn on_finalize() -> Weight { (5915000 as Weight) } diff --git a/substrate/frame/timestamp/src/lib.rs b/substrate/frame/timestamp/src/lib.rs index 959382c07b610e28ae29314b8c5299d45555532d..f2a74d36e0231f603cd2c9a6962fd00a7be6089f 100644 --- a/substrate/frame/timestamp/src/lib.rs +++ b/substrate/frame/timestamp/src/lib.rs @@ -107,7 +107,7 @@ use frame_support::{ use sp_runtime::{ RuntimeString, traits::{ - AtLeast32Bit, Zero, SaturatedConversion, Scale + AtLeast32Bit, Zero, SaturatedConversion, Scale, } }; use frame_system::ensure_none; @@ -159,9 +159,9 @@ decl_module! { /// The dispatch origin for this call must be `Inherent`. /// /// # <weight> - /// - `O(T)` where `T` complexity of `on_timestamp_set` + /// - `O(1)` (Note that implementations of `OnTimestampSet` must also be `O(1)`) /// - 1 storage read and 1 storage mutation (codec `O(1)`). (because of `DidUpdate::take` in `on_finalize`) - /// - 1 event handler `on_timestamp_set` `O(T)`. + /// - 1 event handler `on_timestamp_set`. Must be `O(1)`. /// # </weight> #[weight = ( T::WeightInfo::set(), diff --git a/substrate/frame/treasury/src/benchmarking.rs b/substrate/frame/treasury/src/benchmarking.rs index 637be417f40824ef94cbb78c2a3509570ab95b3a..1d6d7c6afceb76a06359516411e2dee324271282 100644 --- a/substrate/frame/treasury/src/benchmarking.rs +++ b/substrate/frame/treasury/src/benchmarking.rs @@ -203,7 +203,7 @@ benchmarks_instance! { }: _(RawOrigin::Signed(caller), reason, awesome_person) retract_tip { - let r in 0 .. MAX_BYTES; + let r = MAX_BYTES; let (caller, reason, awesome_person) = setup_awesome::<T, _>(r); Treasury::<T, _>::report_awesome( RawOrigin::Signed(caller.clone()).into(), diff --git a/substrate/frame/treasury/src/default_weights.rs b/substrate/frame/treasury/src/default_weights.rs index faf6c1a04573d69fbaa9b9b982bff836ccd81d88..bf4f5fb789a54874c1fbc4a4d7c8805ebcb5142f 100644 --- a/substrate/frame/treasury/src/default_weights.rs +++ b/substrate/frame/treasury/src/default_weights.rs @@ -44,7 +44,6 @@ impl crate::WeightInfo for () { .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } - // WARNING! Some components were not used: ["r"] fn retract_tip() -> Weight { (82970000 as Weight) .saturating_add(DbWeight::get().reads(1 as Weight)) diff --git a/substrate/frame/utility/src/benchmarking.rs b/substrate/frame/utility/src/benchmarking.rs index 8ca0e216f2887a2265f568bbe907be19bfc91021..1c1b3f58150057ce7e4888ddbe1cb3580cb814e9 100644 --- a/substrate/frame/utility/src/benchmarking.rs +++ b/substrate/frame/utility/src/benchmarking.rs @@ -50,13 +50,12 @@ benchmarks! { } as_derivative { - let u in 0 .. 1000; - let caller = account("caller", u, SEED); + let caller = account("caller", SEED, SEED); let call = Box::new(frame_system::Call::remark(vec![]).into()); // Whitelist caller account from further DB operations. let caller_key = frame_system::Account::<T>::hashed_key_for(&caller); frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); - }: _(RawOrigin::Signed(caller), u as u16, call) + }: _(RawOrigin::Signed(caller), SEED as u16, call) } #[cfg(test)] diff --git a/substrate/frame/utility/src/default_weights.rs b/substrate/frame/utility/src/default_weights.rs index d023dbddd4f8087b51820fb3b222980e1a599f98..d63f010612ec135459cd508dd764c9ff49319c1c 100644 --- a/substrate/frame/utility/src/default_weights.rs +++ b/substrate/frame/utility/src/default_weights.rs @@ -27,7 +27,6 @@ impl crate::WeightInfo for () { (16461000 as Weight) .saturating_add((1982000 as Weight).saturating_mul(c as Weight)) } - // WARNING! Some components were not used: ["u"] fn as_derivative() -> Weight { (4086000 as Weight) } diff --git a/substrate/utils/frame/benchmarking-cli/src/command.rs b/substrate/utils/frame/benchmarking-cli/src/command.rs index 99bf9a600c8ec4a018414a2f5c874ee927ff83a7..f5ea83d7b0c47a43cb6363c44cf93b99451d7c6f 100644 --- a/substrate/utils/frame/benchmarking-cli/src/command.rs +++ b/substrate/utils/frame/benchmarking-cli/src/command.rs @@ -102,20 +102,9 @@ impl BenchmarkCmd { // If we are going to output results to a file... if let Some(output_path) = &self.output { if self.trait_def { - crate::writer::write_trait(&batches, output_path, &self.r#trait, self.spaces)?; + crate::writer::write_trait(&batches, output_path, self)?; } else { - crate::writer::write_results( - &batches, - output_path, - &self.lowest_range_values, - &self.highest_range_values, - &self.steps, - self.repeat, - &self.header, - &self.r#struct, - &self.r#trait, - self.spaces - )?; + crate::writer::write_results(&batches, output_path, self)?; } } diff --git a/substrate/utils/frame/benchmarking-cli/src/writer.rs b/substrate/utils/frame/benchmarking-cli/src/writer.rs index a05d867a6d1f5b5aa4a7b7dcffd7b4842309765d..23c1db06fb9c4acea42bdef26a49ed15278e8677 100644 --- a/substrate/utils/frame/benchmarking-cli/src/writer.rs +++ b/substrate/utils/frame/benchmarking-cli/src/writer.rs @@ -17,6 +17,7 @@ // Outputs benchmark results to Rust files that can be ingested by the runtime. +use crate::BenchmarkCmd; use std::fs::{self, File, OpenOptions}; use std::io::prelude::*; use std::path::PathBuf; @@ -51,15 +52,14 @@ fn underscore<Number>(i: Number) -> String pub fn write_trait( batches: &[BenchmarkBatch], path: &PathBuf, - trait_name: &String, - spaces: bool, + cmd: &BenchmarkCmd, ) -> Result<(), std::io::Error> { let mut file_path = path.clone(); file_path.push("trait"); file_path.set_extension("rs"); let mut file = crate::writer::open_file(file_path)?; - let indent = if spaces {" "} else {"\t"}; + let indent = if cmd.spaces {" "} else {"\t"}; let mut current_pallet = Vec::<u8>::new(); @@ -82,7 +82,7 @@ pub fn write_trait( // trait wrapper write!(file, "// {}\n", pallet_string)?; - write!(file, "pub trait {} {{\n", trait_name)?; + write!(file, "pub trait {} {{\n", cmd.r#trait)?; current_pallet = batch.pallet.clone() } @@ -108,17 +108,10 @@ pub fn write_trait( pub fn write_results( batches: &[BenchmarkBatch], path: &PathBuf, - lowest_range_values: &[u32], - highest_range_values: &[u32], - steps: &[u32], - repeat: u32, - header: &Option<PathBuf>, - struct_name: &String, - trait_name: &String, - spaces: bool, + cmd: &BenchmarkCmd, ) -> Result<(), std::io::Error> { - let header_text = match header { + let header_text = match &cmd.header { Some(header_file) => { let text = fs::read_to_string(header_file)?; Some(text) @@ -126,7 +119,7 @@ pub fn write_results( None => None, }; - let indent = if spaces {" "} else {"\t"}; + let indent = if cmd.spaces {" "} else {"\t"}; let date = chrono::Utc::now(); let mut current_pallet = Vec::<u8>::new(); @@ -170,15 +163,25 @@ pub fn write_results( VERSION, )?; - // date of generation + // date of generation + some settings write!( file, - "//! DATE: {}, STEPS: {:?}, REPEAT: {}, LOW RANGE: {:?}, HIGH RANGE: {:?}\n\n", + "//! DATE: {}, STEPS: {:?}, REPEAT: {}, LOW RANGE: {:?}, HIGH RANGE: {:?}\n", date.format("%Y-%m-%d"), - steps, - repeat, - lowest_range_values, - highest_range_values, + cmd.steps, + cmd.repeat, + cmd.lowest_range_values, + cmd.highest_range_values, + )?; + + // more settings + write!( + file, + "//! EXECUTION: {:?}, WASM-EXECUTION: {}, CHAIN: {:?}, DB CACHE: {}\n", + cmd.execution, + cmd.wasm_method, + cmd.shared_params.chain, + cmd.database_cache_size, )?; // allow statements @@ -194,15 +197,15 @@ pub fn write_results( )?; // struct for weights - write!(file, "pub struct {}<T>(PhantomData<T>);\n", struct_name)?; + write!(file, "pub struct {}<T>(PhantomData<T>);\n", cmd.r#struct)?; // trait wrapper write!( file, "impl<T: frame_system::Trait> {}::{} for {}<T> {{\n", pallet_string, - trait_name, - struct_name, + cmd.r#trait, + cmd.r#struct, )?; current_pallet = batch.pallet.clone() @@ -241,17 +244,16 @@ pub fn write_results( .iter() .map(|(name, _)| -> String { return name.to_string() }) .collect::<Vec<String>>(); - if all_components.len() != used_components.len() { - let mut unused_components = all_components; - unused_components.retain(|x| !used_components.contains(&x)); - write!(file, "{}// WARNING! Some components were not used: {:?}\n", indent, unused_components)?; - } // function name write!(file, "{}fn {}(", indent, benchmark_string)?; // params - for component in used_components { - write!(file, "{}: u32, ", component)?; + for component in all_components { + if used_components.contains(&&component) { + write!(file, "{}: u32, ", component)?; + } else { + write!(file, "_{}: u32, ", component)?; + } } // return value write!(file, ") -> Weight {{\n")?;