From 9166c593ab77a64e80c214d7e51f39a43a33f196 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 12 Jul 2023 16:55:44 +0200 Subject: [PATCH 1/4] Add DeferGuard::new Signed-off-by: Oliver Tale-Yazdi --- primitives/core/src/defer.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/primitives/core/src/defer.rs b/primitives/core/src/defer.rs index c5ff502593692..efa9ee5cebb70 100644 --- a/primitives/core/src/defer.rs +++ b/primitives/core/src/defer.rs @@ -25,6 +25,13 @@ #[must_use] pub struct DeferGuard(pub Option); +impl DeferGuard { + /// Creates a new `DeferGuard` with the given closure. + pub fn new(f: F) -> Self { + Self(Some(f)) + } +} + impl Drop for DeferGuard { fn drop(&mut self) { self.0.take().map(|f| f()); From 8ee001c1fd4da9cc580d904557922b414b24994d Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 12 Jul 2023 16:56:07 +0200 Subject: [PATCH 2/4] Re-add deprecated 'execution' arg to benchmark pallet cmd. Signed-off-by: Oliver Tale-Yazdi --- utils/frame/benchmarking-cli/src/pallet/command.rs | 10 ++++++++++ utils/frame/benchmarking-cli/src/pallet/mod.rs | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/utils/frame/benchmarking-cli/src/pallet/command.rs b/utils/frame/benchmarking-cli/src/pallet/command.rs index 1d2d81e357724..d98111d1f0999 100644 --- a/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -147,6 +147,16 @@ impl PalletCmd { <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, ExtraHostFunctions: sp_wasm_interface::HostFunctions, { + let _d = self.execution.as_ref().map(|exec| { + // We print the warning at the end, since there is often A LOT of output. + sp_core::defer::DeferGuard::new(move || { + log::warn!( + target: LOG_TARGET, + "⚠️ Argument `--execution` is deprecated. Its value of `{exec}` has on effect.", + ) + }) + }); + if let Some(output_path) = &self.output { if !output_path.is_dir() && output_path.file_name().is_none() { return Err("Output file or path is invalid!".into()) diff --git a/utils/frame/benchmarking-cli/src/pallet/mod.rs b/utils/frame/benchmarking-cli/src/pallet/mod.rs index 5090a601f0c9a..c69ce1765fc9d 100644 --- a/utils/frame/benchmarking-cli/src/pallet/mod.rs +++ b/utils/frame/benchmarking-cli/src/pallet/mod.rs @@ -150,6 +150,10 @@ pub struct PalletCmd { )] pub wasmtime_instantiation_strategy: WasmtimeInstantiationStrategy, + /// DEPRECATED: This argument has no effect. + #[arg(long = "execution")] + pub execution: Option, + /// Limit the memory the database cache can use. #[arg(long = "db-cache", value_name = "MiB", default_value_t = 1024)] pub database_cache_size: u32, From 3dcbb9403f1fd03362ee55fe9f0067cb9bdd0515 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 12 Jul 2023 16:56:38 +0200 Subject: [PATCH 3/4] Extend tests Signed-off-by: Oliver Tale-Yazdi --- bin/node/cli/tests/benchmark_block_works.rs | 2 +- bin/node/cli/tests/benchmark_extrinsic_works.rs | 1 + bin/node/cli/tests/benchmark_overhead_works.rs | 1 + bin/node/cli/tests/benchmark_pallet_works.rs | 17 +++++++++++------ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/bin/node/cli/tests/benchmark_block_works.rs b/bin/node/cli/tests/benchmark_block_works.rs index 09c2f262e2c29..1387b1516ca14 100644 --- a/bin/node/cli/tests/benchmark_block_works.rs +++ b/bin/node/cli/tests/benchmark_block_works.rs @@ -39,7 +39,7 @@ async fn benchmark_block_works() { .arg(base_dir.path()) .args(["--from", "1", "--to", "1"]) .args(["--repeat", "1"]) - .args(["--wasm-execution", "compiled"]) + .args(["--execution=wasm", "--wasm-execution=compiled"]) .status() .unwrap(); diff --git a/bin/node/cli/tests/benchmark_extrinsic_works.rs b/bin/node/cli/tests/benchmark_extrinsic_works.rs index 9cdb971def522..da70a59db2d7f 100644 --- a/bin/node/cli/tests/benchmark_extrinsic_works.rs +++ b/bin/node/cli/tests/benchmark_extrinsic_works.rs @@ -39,6 +39,7 @@ fn benchmark_extrinsic(pallet: &str, extrinsic: &str) { .args(&["--pallet", pallet, "--extrinsic", extrinsic]) // Run with low repeats for faster execution. .args(["--warmup=10", "--repeat=10", "--max-ext-per-block=10"]) + .args(["--execution=wasm", "--wasm-execution=compiled"]) .status() .unwrap(); diff --git a/bin/node/cli/tests/benchmark_overhead_works.rs b/bin/node/cli/tests/benchmark_overhead_works.rs index 92ab93b7f6f26..eefc144dc0bfc 100644 --- a/bin/node/cli/tests/benchmark_overhead_works.rs +++ b/bin/node/cli/tests/benchmark_overhead_works.rs @@ -36,6 +36,7 @@ fn benchmark_overhead_works() { .args(["--warmup", "10", "--repeat", "10"]) .args(["--add", "100", "--mul", "1.2", "--metric", "p75"]) .args(["--max-ext-per-block", "10"]) + .args(["--execution=wasm", "--wasm-execution=compiled"]) .status() .unwrap(); assert!(status.success()); diff --git a/bin/node/cli/tests/benchmark_pallet_works.rs b/bin/node/cli/tests/benchmark_pallet_works.rs index 2d9946543eed2..2639c1daf4deb 100644 --- a/bin/node/cli/tests/benchmark_pallet_works.rs +++ b/bin/node/cli/tests/benchmark_pallet_works.rs @@ -34,16 +34,21 @@ fn benchmark_pallet_works() { } fn benchmark_pallet(steps: u32, repeat: u32, should_work: bool) { - let output = Command::new(cargo_bin("substrate")) + let status = Command::new(cargo_bin("substrate")) .args(["benchmark", "pallet", "--dev"]) // Use the `addition` benchmark since is the fastest. .args(["--pallet", "frame-benchmarking", "--extrinsic", "addition"]) .args(["--steps", &format!("{}", steps), "--repeat", &format!("{}", repeat)]) - .output() + .args([ + "--execution=wasm", + "--wasm-execution=compiled", + "--no-storage-info", + "--no-median-slopes", + "--no-min-squares", + "--heap-pages=4096", + ]) + .status() .unwrap(); - if output.status.success() != should_work { - let log = String::from_utf8_lossy(&output.stderr).to_string(); - panic!("Test failed:\n{}", log); - } + assert_eq!(status.success(), should_work); } From 488ba9b4646d9bf9188d82872b7929905dbf478c Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 12 Jul 2023 17:21:03 +0200 Subject: [PATCH 4/4] Remove from tests Signed-off-by: Oliver Tale-Yazdi --- bin/node/cli/tests/benchmark_block_works.rs | 2 +- bin/node/cli/tests/benchmark_extrinsic_works.rs | 2 +- bin/node/cli/tests/benchmark_overhead_works.rs | 2 +- bin/node/cli/tests/benchmark_pallet_works.rs | 1 - 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/bin/node/cli/tests/benchmark_block_works.rs b/bin/node/cli/tests/benchmark_block_works.rs index 1387b1516ca14..19a074081c550 100644 --- a/bin/node/cli/tests/benchmark_block_works.rs +++ b/bin/node/cli/tests/benchmark_block_works.rs @@ -39,7 +39,7 @@ async fn benchmark_block_works() { .arg(base_dir.path()) .args(["--from", "1", "--to", "1"]) .args(["--repeat", "1"]) - .args(["--execution=wasm", "--wasm-execution=compiled"]) + .args(["--wasm-execution=compiled"]) .status() .unwrap(); diff --git a/bin/node/cli/tests/benchmark_extrinsic_works.rs b/bin/node/cli/tests/benchmark_extrinsic_works.rs index da70a59db2d7f..8e6363b7d0665 100644 --- a/bin/node/cli/tests/benchmark_extrinsic_works.rs +++ b/bin/node/cli/tests/benchmark_extrinsic_works.rs @@ -39,7 +39,7 @@ fn benchmark_extrinsic(pallet: &str, extrinsic: &str) { .args(&["--pallet", pallet, "--extrinsic", extrinsic]) // Run with low repeats for faster execution. .args(["--warmup=10", "--repeat=10", "--max-ext-per-block=10"]) - .args(["--execution=wasm", "--wasm-execution=compiled"]) + .args(["--wasm-execution=compiled"]) .status() .unwrap(); diff --git a/bin/node/cli/tests/benchmark_overhead_works.rs b/bin/node/cli/tests/benchmark_overhead_works.rs index eefc144dc0bfc..3273e6f868112 100644 --- a/bin/node/cli/tests/benchmark_overhead_works.rs +++ b/bin/node/cli/tests/benchmark_overhead_works.rs @@ -36,7 +36,7 @@ fn benchmark_overhead_works() { .args(["--warmup", "10", "--repeat", "10"]) .args(["--add", "100", "--mul", "1.2", "--metric", "p75"]) .args(["--max-ext-per-block", "10"]) - .args(["--execution=wasm", "--wasm-execution=compiled"]) + .args(["--wasm-execution=compiled"]) .status() .unwrap(); assert!(status.success()); diff --git a/bin/node/cli/tests/benchmark_pallet_works.rs b/bin/node/cli/tests/benchmark_pallet_works.rs index 2639c1daf4deb..9c3e7e2995391 100644 --- a/bin/node/cli/tests/benchmark_pallet_works.rs +++ b/bin/node/cli/tests/benchmark_pallet_works.rs @@ -40,7 +40,6 @@ fn benchmark_pallet(steps: u32, repeat: u32, should_work: bool) { .args(["--pallet", "frame-benchmarking", "--extrinsic", "addition"]) .args(["--steps", &format!("{}", steps), "--repeat", &format!("{}", repeat)]) .args([ - "--execution=wasm", "--wasm-execution=compiled", "--no-storage-info", "--no-median-slopes",