Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 9 additions & 39 deletions frame/benchmarking/src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1826,9 +1826,9 @@ pub fn show_benchmark_debug_info(
/// ```
#[macro_export]
macro_rules! add_benchmark {
( $params:ident, $batches:ident, $name:path, $( $location:tt )* ) => (
( $params:ident, $batches:ident, $name:path, $location:ty ) => (
let name_string = stringify!($name).as_bytes();
let instance_string = stringify!( $( $location )* ).as_bytes();
let instance_string = stringify!( $location ).as_bytes();
let (config, whitelist) = $params;
let $crate::BenchmarkConfig {
pallet,
Expand All @@ -1838,7 +1838,7 @@ macro_rules! add_benchmark {
internal_repeats,
} = config;
if &pallet[..] == &name_string[..] {
let benchmark_result = $( $location )*::run_benchmark(
let benchmark_result = <$location>::run_benchmark(
&benchmark[..],
&selected_components[..],
whitelist,
Expand Down Expand Up @@ -1903,20 +1903,6 @@ macro_rules! add_benchmark {
)
}

/// Callback for `define_benchmarks` to call `add_benchmark`.
#[macro_export]
macro_rules! cb_add_benchmarks {
// anchor
( $params:ident, $batches:ident, [ $name:path, $( $location:tt )* ] ) => {
$crate::add_benchmark!( $params, $batches, $name, $( $location )* );
};
// recursion tail
( $params:ident, $batches:ident, [ $name:path, $( $location:tt )* ] $([ $names:path, $( $locations:tt )* ])+ ) => {
$crate::cb_add_benchmarks!( $params, $batches, [ $name, $( $location )* ] );
$crate::cb_add_benchmarks!( $params, $batches, $([ $names, $( $locations )* ])+ );
}
}

/// This macro allows users to easily generate a list of benchmarks for the pallets configured
/// in the runtime.
///
Expand All @@ -1938,10 +1924,10 @@ macro_rules! cb_add_benchmarks {
/// This should match what exists with the `add_benchmark!` macro.
#[macro_export]
macro_rules! list_benchmark {
( $list:ident, $extra:ident, $name:path, $( $location:tt )* ) => (
( $list:ident, $extra:ident, $name:path, $location:ty ) => (
let pallet_string = stringify!($name).as_bytes();
let instance_string = stringify!( $( $location )* ).as_bytes();
let benchmarks = $( $location )*::benchmarks($extra);
let instance_string = stringify!( $location ).as_bytes();
let benchmarks = <$location>::benchmarks($extra);
let pallet_benchmarks = BenchmarkList {
pallet: pallet_string.to_vec(),
instance: instance_string.to_vec(),
Expand All @@ -1951,26 +1937,12 @@ macro_rules! list_benchmark {
)
}

/// Callback for `define_benchmarks` to call `list_benchmark`.
#[macro_export]
macro_rules! cb_list_benchmarks {
// anchor
( $list:ident, $extra:ident, [ $name:path, $( $location:tt )* ] ) => {
$crate::list_benchmark!( $list, $extra, $name, $( $location )* );
};
// recursion tail
( $list:ident, $extra:ident, [ $name:path, $( $location:tt )* ] $([ $names:path, $( $locations:tt )* ])+ ) => {
$crate::cb_list_benchmarks!( $list, $extra, [ $name, $( $location )* ] );
$crate::cb_list_benchmarks!( $list, $extra, $([ $names, $( $locations )* ])+ );
}
}

/// Defines pallet configs that `add_benchmarks` and `list_benchmarks` use.
/// Should be preferred instead of having a repetitive list of configs
/// in `add_benchmark` and `list_benchmark`.
#[macro_export]
macro_rules! define_benchmarks {
( $([ $names:path, $( $locations:tt )* ])* ) => {
( $([ $names:path, $locations:ty ])* ) => {
/// Calls `list_benchmark` with all configs from `define_benchmarks`
/// and passes the first two parameters on.
///
Expand All @@ -1981,7 +1953,7 @@ macro_rules! define_benchmarks {
#[macro_export]
macro_rules! list_benchmarks {
( $list:ident, $extra:ident ) => {
$crate::cb_list_benchmarks!( $list, $extra, $([ $names, $( $locations )* ])+ );
$( $crate::list_benchmark!( $list, $extra, $names, $locations); )*
}
}

Expand All @@ -1995,7 +1967,7 @@ macro_rules! define_benchmarks {
#[macro_export]
macro_rules! add_benchmarks {
( $params:ident, $batches:ident ) => {
$crate::cb_add_benchmarks!( $params, $batches, $([ $names, $( $locations )* ])+ );
$( $crate::add_benchmark!( $params, $batches, $names, $locations ); )*
}
}
}
Expand All @@ -2007,8 +1979,6 @@ pub use benchmarks;
pub use benchmarks_instance;
pub use benchmarks_instance_pallet;
pub use benchmarks_iter;
pub use cb_add_benchmarks;
pub use cb_list_benchmarks;
pub use define_benchmarks;
pub use impl_bench_case_tests;
pub use impl_bench_name_tests;
Expand Down