mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-06 02:08:02 +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:
@@ -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