mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 21:41:12 +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:
@@ -20,8 +20,11 @@ use super::*;
|
||||
|
||||
use frame_system::RawOrigin;
|
||||
use sp_io::hashing::blake2_256;
|
||||
use sp_runtime::{BenchmarkResults, BenchmarkParameter, selected_benchmark};
|
||||
use sp_runtime::traits::{Bounded, Benchmarking, BenchmarkingSetup, Dispatchable};
|
||||
use frame_benchmarking::{
|
||||
BenchmarkResults, BenchmarkParameter, selected_benchmark, benchmarking, Benchmarking,
|
||||
BenchmarkingSetup,
|
||||
};
|
||||
use sp_runtime::traits::{Bounded, Dispatchable};
|
||||
|
||||
use crate::Module as Identity;
|
||||
|
||||
@@ -102,7 +105,7 @@ impl<T: Trait> BenchmarkingSetup<T, crate::Call<T>, RawOrigin<T::AccountId>> for
|
||||
{
|
||||
// Add r registrars
|
||||
let r = components.iter().find(|&c| c.0 == BenchmarkParameter::R).unwrap().1;
|
||||
benchmarking::add_registrars::<T>(r)?;
|
||||
add_registrars::<T>(r)?;
|
||||
|
||||
// Return the `add_registrar` r + 1 call
|
||||
Ok((crate::Call::<T>::add_registrar(account::<T>("registrar", r + 1)), RawOrigin::Root))
|
||||
@@ -126,7 +129,7 @@ impl<T: Trait> BenchmarkingSetup<T, crate::Call<T>, RawOrigin<T::AccountId>> for
|
||||
{
|
||||
// Add r registrars
|
||||
let r = components.iter().find(|&c| c.0 == BenchmarkParameter::R).unwrap().1;
|
||||
benchmarking::add_registrars::<T>(r)?;
|
||||
add_registrars::<T>(r)?;
|
||||
|
||||
// The target user
|
||||
let caller = account::<T>("caller", r);
|
||||
@@ -135,7 +138,7 @@ impl<T: Trait> BenchmarkingSetup<T, crate::Call<T>, RawOrigin<T::AccountId>> for
|
||||
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
|
||||
// Add an initial identity
|
||||
let initial_info = benchmarking::create_identity_info::<T>(1);
|
||||
let initial_info = create_identity_info::<T>(1);
|
||||
Identity::<T>::set_identity(caller_origin.clone(), initial_info)?;
|
||||
|
||||
// User requests judgement from all the registrars, and they approve
|
||||
@@ -152,7 +155,7 @@ impl<T: Trait> BenchmarkingSetup<T, crate::Call<T>, RawOrigin<T::AccountId>> for
|
||||
// Create identity info with x additional fields
|
||||
let x = components.iter().find(|&c| c.0 == BenchmarkParameter::X).unwrap().1;
|
||||
// 32 byte data that we reuse below
|
||||
let info = benchmarking::create_identity_info::<T>(x);
|
||||
let info = create_identity_info::<T>(x);
|
||||
|
||||
// Return the `set_identity` call
|
||||
Ok((crate::Call::<T>::set_identity(info), RawOrigin::Signed(caller)))
|
||||
@@ -181,7 +184,7 @@ impl<T: Trait> BenchmarkingSetup<T, crate::Call<T>, RawOrigin<T::AccountId>> for
|
||||
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
|
||||
// Create their main identity
|
||||
let info = benchmarking::create_identity_info::<T>(1);
|
||||
let info = create_identity_info::<T>(1);
|
||||
Identity::<T>::set_identity(caller_origin.clone(), info)?;
|
||||
|
||||
// Give them s many sub accounts
|
||||
@@ -221,16 +224,16 @@ impl<T: Trait> BenchmarkingSetup<T, crate::Call<T>, RawOrigin<T::AccountId>> for
|
||||
|
||||
// Register r registrars
|
||||
let r = components.iter().find(|&c| c.0 == BenchmarkParameter::R).unwrap().1;
|
||||
benchmarking::add_registrars::<T>(r)?;
|
||||
add_registrars::<T>(r)?;
|
||||
|
||||
// Create their main identity with x additional fields
|
||||
let x = components.iter().find(|&c| c.0 == BenchmarkParameter::X).unwrap().1;
|
||||
let info = benchmarking::create_identity_info::<T>(x);
|
||||
let info = create_identity_info::<T>(x);
|
||||
Identity::<T>::set_identity(caller_origin.clone(), info)?;
|
||||
|
||||
// Give them s many sub accounts
|
||||
let s = components.iter().find(|&c| c.0 == BenchmarkParameter::S).unwrap().1;
|
||||
let _ = benchmarking::add_sub_accounts::<T>(caller.clone(), s)?;
|
||||
let _ = add_sub_accounts::<T>(caller.clone(), s)?;
|
||||
|
||||
// User requests judgement from all the registrars, and they approve
|
||||
for i in 0..r {
|
||||
@@ -270,11 +273,11 @@ impl<T: Trait> BenchmarkingSetup<T, crate::Call<T>, RawOrigin<T::AccountId>> for
|
||||
|
||||
// Register r registrars
|
||||
let r = components.iter().find(|&c| c.0 == BenchmarkParameter::R).unwrap().1;
|
||||
benchmarking::add_registrars::<T>(r)?;
|
||||
add_registrars::<T>(r)?;
|
||||
|
||||
// Create their main identity with x additional fields
|
||||
let x = components.iter().find(|&c| c.0 == BenchmarkParameter::X).unwrap().1;
|
||||
let info = benchmarking::create_identity_info::<T>(x);
|
||||
let info = create_identity_info::<T>(x);
|
||||
Identity::<T>::set_identity(caller_origin.clone(), info)?;
|
||||
|
||||
// Return the `request_judgement` call
|
||||
@@ -304,11 +307,11 @@ impl<T: Trait> BenchmarkingSetup<T, crate::Call<T>, RawOrigin<T::AccountId>> for
|
||||
|
||||
// Register r registrars
|
||||
let r = components.iter().find(|&c| c.0 == BenchmarkParameter::R).unwrap().1;
|
||||
benchmarking::add_registrars::<T>(r)?;
|
||||
add_registrars::<T>(r)?;
|
||||
|
||||
// Create their main identity with x additional fields
|
||||
let x = components.iter().find(|&c| c.0 == BenchmarkParameter::X).unwrap().1;
|
||||
let info = benchmarking::create_identity_info::<T>(x);
|
||||
let info = create_identity_info::<T>(x);
|
||||
Identity::<T>::set_identity(caller_origin.clone(), info)?;
|
||||
|
||||
// Request judgement
|
||||
@@ -337,7 +340,7 @@ impl<T: Trait> BenchmarkingSetup<T, crate::Call<T>, RawOrigin<T::AccountId>> for
|
||||
|
||||
// Register r registrars
|
||||
let r = components.iter().find(|&c| c.0 == BenchmarkParameter::R).unwrap().1;
|
||||
benchmarking::add_registrars::<T>(r)?;
|
||||
add_registrars::<T>(r)?;
|
||||
|
||||
// Add caller as registrar
|
||||
Identity::<T>::add_registrar(RawOrigin::Root.into(), caller.clone())?;
|
||||
@@ -366,7 +369,7 @@ impl<T: Trait> BenchmarkingSetup<T, crate::Call<T>, RawOrigin<T::AccountId>> for
|
||||
|
||||
// Register r registrars
|
||||
let r = components.iter().find(|&c| c.0 == BenchmarkParameter::R).unwrap().1;
|
||||
benchmarking::add_registrars::<T>(r)?;
|
||||
add_registrars::<T>(r)?;
|
||||
|
||||
// Add caller as registrar
|
||||
Identity::<T>::add_registrar(RawOrigin::Root.into(), caller.clone())?;
|
||||
@@ -395,7 +398,7 @@ impl<T: Trait> BenchmarkingSetup<T, crate::Call<T>, RawOrigin<T::AccountId>> for
|
||||
|
||||
// Register r registrars
|
||||
let r = components.iter().find(|&c| c.0 == BenchmarkParameter::R).unwrap().1;
|
||||
benchmarking::add_registrars::<T>(r)?;
|
||||
add_registrars::<T>(r)?;
|
||||
|
||||
// Add caller as registrar
|
||||
Identity::<T>::add_registrar(RawOrigin::Root.into(), caller.clone())?;
|
||||
@@ -428,7 +431,7 @@ impl<T: Trait> BenchmarkingSetup<T, crate::Call<T>, RawOrigin<T::AccountId>> for
|
||||
{
|
||||
// Add r registrars
|
||||
let r = components.iter().find(|&c| c.0 == BenchmarkParameter::R).unwrap().1;
|
||||
benchmarking::add_registrars::<T>(r)?;
|
||||
add_registrars::<T>(r)?;
|
||||
|
||||
// The user
|
||||
let user = account::<T>("user", r);
|
||||
@@ -438,7 +441,7 @@ impl<T: Trait> BenchmarkingSetup<T, crate::Call<T>, RawOrigin<T::AccountId>> for
|
||||
|
||||
// Create their main identity with x additional fields
|
||||
let x = components.iter().find(|&c| c.0 == BenchmarkParameter::X).unwrap().1;
|
||||
let info = benchmarking::create_identity_info::<T>(x);
|
||||
let info = create_identity_info::<T>(x);
|
||||
Identity::<T>::set_identity(user_origin.clone(), info)?;
|
||||
|
||||
// The caller registrar
|
||||
@@ -486,16 +489,16 @@ impl<T: Trait> BenchmarkingSetup<T, crate::Call<T>, RawOrigin<T::AccountId>> for
|
||||
|
||||
// Register r registrars
|
||||
let r = components.iter().find(|&c| c.0 == BenchmarkParameter::R).unwrap().1;
|
||||
benchmarking::add_registrars::<T>(r)?;
|
||||
add_registrars::<T>(r)?;
|
||||
|
||||
// Create their main identity with x additional fields
|
||||
let x = components.iter().find(|&c| c.0 == BenchmarkParameter::X).unwrap().1;
|
||||
let info = benchmarking::create_identity_info::<T>(x);
|
||||
let info = create_identity_info::<T>(x);
|
||||
Identity::<T>::set_identity(caller_origin.clone(), info)?;
|
||||
|
||||
// Give them s many sub accounts
|
||||
let s = components.iter().find(|&c| c.0 == BenchmarkParameter::S).unwrap().1;
|
||||
let _ = benchmarking::add_sub_accounts::<T>(caller.clone(), s)?;
|
||||
let _ = add_sub_accounts::<T>(caller.clone(), s)?;
|
||||
|
||||
// User requests judgement from all the registrars, and they approve
|
||||
for i in 0..r {
|
||||
@@ -547,8 +550,8 @@ impl<T: Trait> Benchmarking<BenchmarkResults> for Module<T> {
|
||||
};
|
||||
|
||||
// Warm up the DB
|
||||
sp_io::benchmarking::commit_db();
|
||||
sp_io::benchmarking::wipe_db();
|
||||
benchmarking::commit_db();
|
||||
benchmarking::wipe_db();
|
||||
|
||||
// first one is set_identity.
|
||||
let components = <SelectedBenchmark as BenchmarkingSetup<T, crate::Call<T>, RawOrigin<T::AccountId>>>::components(&selected_benchmark);
|
||||
@@ -575,15 +578,15 @@ impl<T: Trait> Benchmarking<BenchmarkResults> for Module<T> {
|
||||
let (call, caller) = <SelectedBenchmark as BenchmarkingSetup<T, crate::Call<T>, RawOrigin<T::AccountId>>>::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