diff --git a/node/perf-test/src/command.rs b/node/perf-test/src/command.rs index c78769185e..d75b532ae0 100644 --- a/node/perf-test/src/command.rs +++ b/node/perf-test/src/command.rs @@ -450,7 +450,19 @@ impl PerfCmd { let mut all_test_results: Vec = Default::default(); + let (have_filter, enabled_tests) = if let Some(filter) = &cmd.tests { + let enabled_tests: Vec<&str> = filter.split(',').collect(); + (true, enabled_tests) + } else { + (false, Default::default()) + }; + for mut test in tests { + if have_filter { + if !enabled_tests.contains(&test.name().as_str()) { + continue; + } + } let mut results: Vec = (*test.run(&runner)?).to_vec(); all_test_results.append(&mut results); } diff --git a/node/perf-test/src/lib.rs b/node/perf-test/src/lib.rs index c345229ae6..d7c69f3fb9 100644 --- a/node/perf-test/src/lib.rs +++ b/node/perf-test/src/lib.rs @@ -41,4 +41,11 @@ pub struct PerfCmd { help = "File where results should be printed (STDOUT if omitted)." )] pub output_file: Option, + + // TODO: allow multiple tests (like the -l switch for logging) + #[structopt( + long = "tests", + help = "Comma-separated list of tests to run (if omitted, runs all tests)" + )] + pub tests: Option, } diff --git a/node/perf-test/src/tests/block_creation.rs b/node/perf-test/src/tests/block_creation.rs index bde13ad595..7d980cc94e 100644 --- a/node/perf-test/src/tests/block_creation.rs +++ b/node/perf-test/src/tests/block_creation.rs @@ -44,6 +44,10 @@ where RuntimeApiCollection>, Executor: NativeExecutionDispatch + 'static, { + fn name(&self) -> String { + "block_creation".into() + } + fn run( &mut self, context: &TestContext, diff --git a/node/perf-test/src/tests/fibonacci.rs b/node/perf-test/src/tests/fibonacci.rs index acb266e6fd..06202a51e0 100644 --- a/node/perf-test/src/tests/fibonacci.rs +++ b/node/perf-test/src/tests/fibonacci.rs @@ -65,6 +65,10 @@ where RuntimeApiCollection>, Executor: NativeExecutionDispatch + 'static, { + fn name(&self) -> String { + "fibonacci".into() + } + fn run( &mut self, context: &TestContext, diff --git a/node/perf-test/src/tests/mod.rs b/node/perf-test/src/tests/mod.rs index 22d2db4477..c946a2f646 100644 --- a/node/perf-test/src/tests/mod.rs +++ b/node/perf-test/src/tests/mod.rs @@ -86,6 +86,11 @@ where RuntimeApiCollection>, Executor: NativeExecutionDispatch + 'static, { + /// Return a globally unique name for this test. This is used as a filter on the command line + /// so a CLI-friendly name is preferred. + fn name(&self) -> String; + + /// Run the test fn run( &mut self, context: &TestContext, diff --git a/node/perf-test/src/tests/storage.rs b/node/perf-test/src/tests/storage.rs index 40bd962cea..80d1fba148 100644 --- a/node/perf-test/src/tests/storage.rs +++ b/node/perf-test/src/tests/storage.rs @@ -78,6 +78,10 @@ where RuntimeApiCollection>, Executor: NativeExecutionDispatch + 'static, { + fn name(&self) -> String { + "storage".into() + } + fn run( &mut self, context: &TestContext,