mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 22:27:56 +00:00
Batch benchmarks together with * notation. (#5436)
* Batch benchmarks together with `*` notation. * Fix short structopt conflict * Return error if `batches` is empty * Move fast benchmarks macro into `frame_benchmarking` (#5445) * Move macro into `frame_benchmarking` * Update docs * Extra line * Return error if `batches` is empty Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -505,15 +505,19 @@ macro_rules! impl_benchmark {
|
||||
NO_INSTANCE $( $name:ident ),*
|
||||
) => {
|
||||
impl<T: Trait> $crate::Benchmarking<$crate::BenchmarkResults> for Module<T> {
|
||||
fn benchmarks() -> Vec<&'static [u8]> {
|
||||
vec![ $( stringify!($name).as_ref() ),* ]
|
||||
}
|
||||
|
||||
fn run_benchmark(
|
||||
extrinsic: Vec<u8>,
|
||||
lowest_range_values: Vec<u32>,
|
||||
highest_range_values: Vec<u32>,
|
||||
steps: Vec<u32>,
|
||||
extrinsic: &[u8],
|
||||
lowest_range_values: &[u32],
|
||||
highest_range_values: &[u32],
|
||||
steps: &[u32],
|
||||
repeat: u32,
|
||||
) -> Result<Vec<$crate::BenchmarkResults>, &'static str> {
|
||||
// Map the input to the selected benchmark.
|
||||
let extrinsic = sp_std::str::from_utf8(extrinsic.as_slice())
|
||||
let extrinsic = sp_std::str::from_utf8(extrinsic)
|
||||
.map_err(|_| "`extrinsic` is not a valid utf8 string!")?;
|
||||
let selected_benchmark = match extrinsic {
|
||||
$( stringify!($name) => SelectedBenchmark::$name, )*
|
||||
@@ -597,15 +601,19 @@ macro_rules! impl_benchmark {
|
||||
INSTANCE $( $name:ident ),*
|
||||
) => {
|
||||
impl<T: Trait<I>, I: Instance> $crate::Benchmarking<$crate::BenchmarkResults> for Module<T, I> {
|
||||
fn benchmarks() -> Vec<&'static [u8]> {
|
||||
vec![ $( stringify!($name).as_ref() ),* ]
|
||||
}
|
||||
|
||||
fn run_benchmark(
|
||||
extrinsic: Vec<u8>,
|
||||
lowest_range_values: Vec<u32>,
|
||||
highest_range_values: Vec<u32>,
|
||||
steps: Vec<u32>,
|
||||
extrinsic: &[u8],
|
||||
lowest_range_values: &[u32],
|
||||
highest_range_values: &[u32],
|
||||
steps: &[u32],
|
||||
repeat: u32,
|
||||
) -> Result<Vec<$crate::BenchmarkResults>, &'static str> {
|
||||
// Map the input to the selected benchmark.
|
||||
let extrinsic = sp_std::str::from_utf8(extrinsic.as_slice())
|
||||
let extrinsic = sp_std::str::from_utf8(extrinsic)
|
||||
.map_err(|_| "`extrinsic` is not a valid utf8 string!")?;
|
||||
let selected_benchmark = match extrinsic {
|
||||
$( stringify!($name) => SelectedBenchmark::$name, )*
|
||||
@@ -686,3 +694,65 @@ macro_rules! impl_benchmark {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// This macro adds pallet benchmarks to a `Vec<BenchmarkBatch>` object.
|
||||
///
|
||||
/// First create an object that holds in the input parameters for the benchmark:
|
||||
///
|
||||
/// ```ignore
|
||||
/// let params = (&pallet, &benchmark, &lowest_range_values, &highest_range_values, &steps, repeat);
|
||||
/// ```
|
||||
///
|
||||
/// Then define a mutable local variable to hold your `BenchmarkBatch` object:
|
||||
///
|
||||
/// ```ignore
|
||||
/// let mut batches = Vec::<BenchmarkBatch>::new();
|
||||
/// ````
|
||||
///
|
||||
/// Then add the pallets you want to benchmark to this object, including the string
|
||||
/// you want to use target a particular pallet:
|
||||
///
|
||||
/// ```ignore
|
||||
/// add_benchmark!(params, batches, b"balances", Balances);
|
||||
/// add_benchmark!(params, batches, b"identity", Identity);
|
||||
/// add_benchmark!(params, batches, b"session", SessionBench::<Runtime>);
|
||||
/// ...
|
||||
/// ```
|
||||
///
|
||||
/// At the end of `dispatch_benchmark`, you should return this batches object.
|
||||
#[macro_export]
|
||||
macro_rules! add_benchmark {
|
||||
( $params:ident, $batches:ident, $name:literal, $( $location:tt )* ) => (
|
||||
let (pallet, benchmark, lowest_range_values, highest_range_values, steps, repeat) = $params;
|
||||
if &pallet[..] == &$name[..] || &pallet[..] == &b"*"[..] {
|
||||
if &pallet[..] == &b"*"[..] || &benchmark[..] == &b"*"[..] {
|
||||
for benchmark in $( $location )*::benchmarks().into_iter() {
|
||||
$batches.push($crate::BenchmarkBatch {
|
||||
results: $( $location )*::run_benchmark(
|
||||
benchmark,
|
||||
&lowest_range_values[..],
|
||||
&highest_range_values[..],
|
||||
&steps[..],
|
||||
repeat,
|
||||
)?,
|
||||
pallet: pallet.to_vec(),
|
||||
benchmark: benchmark.to_vec(),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
$batches.push($crate::BenchmarkBatch {
|
||||
results: $( $location )*::run_benchmark(
|
||||
&benchmark[..],
|
||||
&lowest_range_values[..],
|
||||
&highest_range_values[..],
|
||||
&steps[..],
|
||||
repeat,
|
||||
)?,
|
||||
pallet: pallet.to_vec(),
|
||||
benchmark: benchmark.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user