From 30dbc1918732013e28a578e09bc98c2399e7461c Mon Sep 17 00:00:00 2001 From: mrisholukamba Date: Sun, 25 Sep 2022 15:48:42 +0300 Subject: [PATCH 1/6] replaced println with log Closes #12338 --- .../benchmarking-cli/src/pallet/command.rs | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/utils/frame/benchmarking-cli/src/pallet/command.rs b/utils/frame/benchmarking-cli/src/pallet/command.rs index 0fc7cc4d783f7..0814b4029d850 100644 --- a/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -39,6 +39,10 @@ use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStorePtr}; use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; use sp_state_machine::StateMachine; use std::{collections::HashMap, fmt::Debug, fs, sync::Arc, time}; +use log; + +/// Logging target +const LOG_TARGET:&'static str = "frame::benchmark::pallet"; /// The inclusive range of a component. #[derive(Serialize, Debug, Clone, Eq, PartialEq)] @@ -228,7 +232,7 @@ impl PalletCmd { let mut component_ranges = HashMap::<(Vec, Vec), Vec>::new(); for (pallet, extrinsic, components) in benchmarks_to_run { - log::info!( + log::info!(target:LOG_TARGET, "Starting benchmark: {}::{}", String::from_utf8(pallet.clone()).expect("Encoded from String; qed"), String::from_utf8(extrinsic.clone()).expect("Encoded from String; qed"), @@ -376,7 +380,7 @@ impl PalletCmd { if let Ok(elapsed) = timer.elapsed() { if elapsed >= time::Duration::from_secs(5) { timer = time::SystemTime::now(); - log::info!( + log::info!(target:LOG_TARGET, "Running Benchmark: {}.{}({} args) {}/{} {}/{}", String::from_utf8(pallet.clone()) .expect("Encoded from String; qed"), @@ -422,7 +426,7 @@ impl PalletCmd { if let Some(path) = &self.json_file { fs::write(path, json)?; } else { - println!("{}", json); + log::info!(target:LOG_TARGET,"{}", json); return Ok(true) } } @@ -438,7 +442,7 @@ impl PalletCmd { ) { for batch in batches.iter() { // Print benchmark metadata - println!( + log::info!(target:LOG_TARGET, "Pallet: {:?}, Extrinsic: {:?}, Lowest values: {:?}, Highest values: {:?}, Steps: {:?}, Repeat: {:?}", String::from_utf8(batch.pallet.clone()).expect("Encoded from String; qed"), String::from_utf8(batch.benchmark.clone()).expect("Encoded from String; qed"), @@ -456,51 +460,51 @@ impl PalletCmd { if !self.no_storage_info { let mut comments: Vec = Default::default(); writer::add_storage_comments(&mut comments, &batch.db_results, storage_info); - println!("Raw Storage Info\n========"); + log::warn!(target:LOG_TARGET,"Raw Storage Info\n========"); for comment in comments { - println!("{}", comment); + log::warn!(target:LOG_TARGET,"{}", comment); } - println!(); + log::warn!(target:LOG_TARGET,""); } // Conduct analysis. if !self.no_median_slopes { - println!("Median Slopes Analysis\n========"); + log::warn!(target:LOG_TARGET,"Median Slopes Analysis\n========"); if let Some(analysis) = Analysis::median_slopes(&batch.time_results, BenchmarkSelector::ExtrinsicTime) { - println!("-- Extrinsic Time --\n{}", analysis); + log::warn!(target:LOG_TARGET,"-- Extrinsic Time --\n{}", analysis); } if let Some(analysis) = Analysis::median_slopes(&batch.db_results, BenchmarkSelector::Reads) { - println!("Reads = {:?}", analysis); + log::warn!(target:LOG_TARGET,"Reads = {:?}", analysis); } if let Some(analysis) = Analysis::median_slopes(&batch.db_results, BenchmarkSelector::Writes) { - println!("Writes = {:?}", analysis); + log::warn!(target:LOG_TARGET,"Writes = {:?}", analysis); } - println!(); + log::warn!(target:LOG_TARGET,""); } if !self.no_min_squares { - println!("Min Squares Analysis\n========"); + log::warn!(target:LOG_TARGET,"Min Squares Analysis\n========"); if let Some(analysis) = Analysis::min_squares_iqr(&batch.time_results, BenchmarkSelector::ExtrinsicTime) { - println!("-- Extrinsic Time --\n{}", analysis); + log::warn!(target:LOG_TARGET,"-- Extrinsic Time --\n{}", analysis); } if let Some(analysis) = Analysis::min_squares_iqr(&batch.db_results, BenchmarkSelector::Reads) { - println!("Reads = {:?}", analysis); + log::warn!(target:LOG_TARGET,"Reads = {:?}", analysis); } if let Some(analysis) = Analysis::min_squares_iqr(&batch.db_results, BenchmarkSelector::Writes) { - println!("Writes = {:?}", analysis); + log::warn!(target:LOG_TARGET,"Writes = {:?}", analysis); } - println!(); + log::warn!(target:LOG_TARGET,""); } } } @@ -521,8 +525,8 @@ impl CliConfiguration for PalletCmd { /// List the benchmarks available in the runtime, in a CSV friendly format. fn list_benchmark(benchmarks_to_run: Vec<(Vec, Vec, Vec<(BenchmarkParameter, u32, u32)>)>) { - println!("pallet, benchmark"); + log::info!(target:LOG_TARGET,"pallet, benchmark"); for (pallet, extrinsic, _components) in benchmarks_to_run { - println!("{}, {}", String::from_utf8_lossy(&pallet), String::from_utf8_lossy(&extrinsic)); + log::info!(target:LOG_TARGET,"{}, {}", String::from_utf8_lossy(&pallet), String::from_utf8_lossy(&extrinsic)); } } From 5a6ca3920233b7da9d95655787a977562f93ba26 Mon Sep 17 00:00:00 2001 From: mrisholukamba Date: Mon, 26 Sep 2022 13:07:22 +0300 Subject: [PATCH 2/6] fixed println --- .../benchmarking-cli/src/pallet/command.rs | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/utils/frame/benchmarking-cli/src/pallet/command.rs b/utils/frame/benchmarking-cli/src/pallet/command.rs index 0814b4029d850..02347912c2fd4 100644 --- a/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -442,7 +442,7 @@ impl PalletCmd { ) { for batch in batches.iter() { // Print benchmark metadata - log::info!(target:LOG_TARGET, + println!( "Pallet: {:?}, Extrinsic: {:?}, Lowest values: {:?}, Highest values: {:?}, Steps: {:?}, Repeat: {:?}", String::from_utf8(batch.pallet.clone()).expect("Encoded from String; qed"), String::from_utf8(batch.benchmark.clone()).expect("Encoded from String; qed"), @@ -460,51 +460,51 @@ impl PalletCmd { if !self.no_storage_info { let mut comments: Vec = Default::default(); writer::add_storage_comments(&mut comments, &batch.db_results, storage_info); - log::warn!(target:LOG_TARGET,"Raw Storage Info\n========"); + println!("Raw Storage Info\n========"); for comment in comments { - log::warn!(target:LOG_TARGET,"{}", comment); + println!("{}", comment); } - log::warn!(target:LOG_TARGET,""); + println!(); } // Conduct analysis. if !self.no_median_slopes { - log::warn!(target:LOG_TARGET,"Median Slopes Analysis\n========"); + println!("Median Slopes Analysis\n========"); if let Some(analysis) = Analysis::median_slopes(&batch.time_results, BenchmarkSelector::ExtrinsicTime) { - log::warn!(target:LOG_TARGET,"-- Extrinsic Time --\n{}", analysis); + println!("-- Extrinsic Time --\n{}", analysis); } if let Some(analysis) = Analysis::median_slopes(&batch.db_results, BenchmarkSelector::Reads) { - log::warn!(target:LOG_TARGET,"Reads = {:?}", analysis); + println!("Reads = {:?}", analysis); } if let Some(analysis) = Analysis::median_slopes(&batch.db_results, BenchmarkSelector::Writes) { - log::warn!(target:LOG_TARGET,"Writes = {:?}", analysis); + println!("Writes = {:?}", analysis); } - log::warn!(target:LOG_TARGET,""); + println!(); } if !self.no_min_squares { - log::warn!(target:LOG_TARGET,"Min Squares Analysis\n========"); + println!("Min Squares Analysis\n========"); if let Some(analysis) = Analysis::min_squares_iqr(&batch.time_results, BenchmarkSelector::ExtrinsicTime) { - log::warn!(target:LOG_TARGET,"-- Extrinsic Time --\n{}", analysis); + println!("-- Extrinsic Time --\n{}", analysis); } if let Some(analysis) = Analysis::min_squares_iqr(&batch.db_results, BenchmarkSelector::Reads) { - log::warn!(target:LOG_TARGET,"Reads = {:?}", analysis); + println!("Reads = {:?}", analysis); } if let Some(analysis) = Analysis::min_squares_iqr(&batch.db_results, BenchmarkSelector::Writes) { - log::warn!(target:LOG_TARGET,"Writes = {:?}", analysis); + println!("Writes = {:?}", analysis); } - log::warn!(target:LOG_TARGET,""); + println!(); } } } @@ -525,8 +525,8 @@ impl CliConfiguration for PalletCmd { /// List the benchmarks available in the runtime, in a CSV friendly format. fn list_benchmark(benchmarks_to_run: Vec<(Vec, Vec, Vec<(BenchmarkParameter, u32, u32)>)>) { - log::info!(target:LOG_TARGET,"pallet, benchmark"); + println!("pallet, benchmark"); for (pallet, extrinsic, _components) in benchmarks_to_run { - log::info!(target:LOG_TARGET,"{}, {}", String::from_utf8_lossy(&pallet), String::from_utf8_lossy(&extrinsic)); + println!("{}, {}", String::from_utf8_lossy(&pallet), String::from_utf8_lossy(&extrinsic)); } } From 3da3816be4dd4eab317c3a6368d474c6138a13db Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 27 Oct 2022 18:43:22 -0400 Subject: [PATCH 3/6] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- utils/frame/benchmarking-cli/src/pallet/command.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/utils/frame/benchmarking-cli/src/pallet/command.rs b/utils/frame/benchmarking-cli/src/pallet/command.rs index c9d092f3c2409..6916f52e33b4f 100644 --- a/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -39,7 +39,6 @@ use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStorePtr}; use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; use sp_state_machine::StateMachine; use std::{collections::HashMap, fmt::Debug, fs, sync::Arc, time}; -use log; /// Logging target const LOG_TARGET:&'static str = "frame::benchmark::pallet"; @@ -247,7 +246,8 @@ impl PalletCmd { for (pallet, extrinsic, components) in benchmarks_to_run { - log::info!(target:LOG_TARGET, + log::info!( + target: LOG_TARGET, println!( @@ -411,7 +411,8 @@ impl PalletCmd { if elapsed >= time::Duration::from_secs(5) { timer = time::SystemTime::now(); - log::info!(target:LOG_TARGET, + log::info!( + target: LOG_TARGET, println!( @@ -504,7 +505,7 @@ impl PalletCmd { if let Some(path) = &self.json_file { fs::write(path, json)?; } else { - log::info!(target:LOG_TARGET,"{}", json); + print!("{json}"); return Ok(true) } } From 8a393b608e68371190543130264c0b13b2b61f96 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 27 Oct 2022 18:43:49 -0400 Subject: [PATCH 4/6] Update utils/frame/benchmarking-cli/src/pallet/command.rs --- utils/frame/benchmarking-cli/src/pallet/command.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/utils/frame/benchmarking-cli/src/pallet/command.rs b/utils/frame/benchmarking-cli/src/pallet/command.rs index 6916f52e33b4f..c694ac2eeef66 100644 --- a/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -415,7 +415,6 @@ impl PalletCmd { target: LOG_TARGET, println!( - "Running Benchmark: {}.{}({} args) {}/{} {}/{}", String::from_utf8(pallet.clone()) .expect("Encoded from String; qed"), From a2401ad65f2d62866f5dfc8fd7afe294e1fbdb12 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 27 Oct 2022 18:44:37 -0400 Subject: [PATCH 5/6] Apply suggestions from code review --- utils/frame/benchmarking-cli/src/pallet/command.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/utils/frame/benchmarking-cli/src/pallet/command.rs b/utils/frame/benchmarking-cli/src/pallet/command.rs index c694ac2eeef66..f2671e3258c1c 100644 --- a/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -248,9 +248,6 @@ impl PalletCmd { log::info!( target: LOG_TARGET, - - println!( - "Starting benchmark: {}::{}", String::from_utf8(pallet.clone()).expect("Encoded from String; qed"), String::from_utf8(extrinsic.clone()).expect("Encoded from String; qed"), @@ -413,8 +410,6 @@ impl PalletCmd { log::info!( target: LOG_TARGET, - - println!( "Running Benchmark: {}.{}({} args) {}/{} {}/{}", String::from_utf8(pallet.clone()) .expect("Encoded from String; qed"), From 997560a4cfabe3d990ecd22cf7e75a99bd447aca Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Fri, 28 Oct 2022 08:52:39 +0000 Subject: [PATCH 6/6] ".git/.scripts/fmt.sh" 1 --- utils/frame/benchmarking-cli/src/pallet/command.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils/frame/benchmarking-cli/src/pallet/command.rs b/utils/frame/benchmarking-cli/src/pallet/command.rs index f2671e3258c1c..242f0e685290f 100644 --- a/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -41,7 +41,7 @@ use sp_state_machine::StateMachine; use std::{collections::HashMap, fmt::Debug, fs, sync::Arc, time}; /// Logging target -const LOG_TARGET:&'static str = "frame::benchmark::pallet"; +const LOG_TARGET: &'static str = "frame::benchmark::pallet"; /// The inclusive range of a component. #[derive(Serialize, Debug, Clone, Eq, PartialEq)] @@ -245,7 +245,6 @@ impl PalletCmd { let mut component_ranges = HashMap::<(Vec, Vec), Vec>::new(); for (pallet, extrinsic, components) in benchmarks_to_run { - log::info!( target: LOG_TARGET, "Starting benchmark: {}::{}",