mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 17:31:05 +00:00
Consolidate frame benchmarking into a frame crate (#4977)
This prs cleans up some of the frame benchmarking stuff: - Move CLI into `frame-benchmarking-cli`. No frame related CLI should exists in the default Substrate CLI. - Move all traits and types related to frame benchmarking into the `frame-benchmarking` trait. Frame types should be isolated in Frame.
This commit is contained in:
@@ -12,6 +12,7 @@ sp-std = { version = "2.0.0", default-features = false, path = "../../primitives
|
||||
sp-io = { version = "2.0.0", default-features = false, path = "../../primitives/io" }
|
||||
sp-runtime = { version = "2.0.0", default-features = false, path = "../../primitives/runtime" }
|
||||
sp-inherents = { version = "2.0.0", default-features = false, path = "../../primitives/inherents" }
|
||||
frame-benchmarking = { version = "2.0.0", default-features = false, path = "../benchmarking" }
|
||||
frame-support = { version = "2.0.0", default-features = false, path = "../support" }
|
||||
frame-system = { version = "2.0.0", default-features = false, path = "../system" }
|
||||
sp-timestamp = { version = "2.0.0", default-features = false, path = "../../primitives/timestamp" }
|
||||
@@ -28,6 +29,7 @@ std = [
|
||||
"codec/std",
|
||||
"sp-std/std",
|
||||
"sp-runtime/std",
|
||||
"frame-benchmarking/std",
|
||||
"frame-support/std",
|
||||
"serde",
|
||||
"frame-system/std",
|
||||
|
||||
@@ -21,8 +21,11 @@ use super::*;
|
||||
use sp_std::prelude::*;
|
||||
|
||||
use frame_system::RawOrigin;
|
||||
use sp_runtime::{BenchmarkResults, BenchmarkParameter, selected_benchmark};
|
||||
use sp_runtime::traits::{Benchmarking, BenchmarkingSetup, Dispatchable};
|
||||
use frame_benchmarking::{
|
||||
BenchmarkResults, BenchmarkParameter, selected_benchmark, benchmarking,
|
||||
Benchmarking, BenchmarkingSetup,
|
||||
};
|
||||
use sp_runtime::traits::Dispatchable;
|
||||
|
||||
/// Benchmark `set` extrinsic.
|
||||
struct Set;
|
||||
@@ -54,10 +57,10 @@ impl<T: Trait> Benchmarking<BenchmarkResults> for Module<T> {
|
||||
b"set" => SelectedBenchmark::Set,
|
||||
_ => return Err("Could not find extrinsic."),
|
||||
};
|
||||
|
||||
|
||||
// Warm up the DB
|
||||
sp_io::benchmarking::commit_db();
|
||||
sp_io::benchmarking::wipe_db();
|
||||
benchmarking::commit_db();
|
||||
benchmarking::wipe_db();
|
||||
|
||||
let components = <SelectedBenchmark as BenchmarkingSetup<T, crate::Call<T>, RawOrigin<T::AccountId>>>::components(&selected_benchmark);
|
||||
let mut results: Vec<BenchmarkResults> = Vec::new();
|
||||
@@ -87,15 +90,15 @@ impl<T: Trait> Benchmarking<BenchmarkResults> for Module<T> {
|
||||
>>::instance(&selected_benchmark, &c)?;
|
||||
// Commit the externalities to the database, flushing the DB cache.
|
||||
// This will enable worst case scenario for reading from the database.
|
||||
sp_io::benchmarking::commit_db();
|
||||
benchmarking::commit_db();
|
||||
// Run the benchmark.
|
||||
let start = sp_io::benchmarking::current_time();
|
||||
let start = benchmarking::current_time();
|
||||
call.dispatch(caller.into())?;
|
||||
let finish = sp_io::benchmarking::current_time();
|
||||
let finish = benchmarking::current_time();
|
||||
let elapsed = finish - start;
|
||||
results.push((c.clone(), elapsed));
|
||||
// Wipe the DB back to the genesis state.
|
||||
sp_io::benchmarking::wipe_db();
|
||||
benchmarking::wipe_db();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user