Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
change $location from tt* to ty and remove unnecessary cb_* versions (#…
Browse files Browse the repository at this point in the history
…14571)

* change $location from tt* to ty and remove unnecessary cb_* versions

* fmt

* ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_balances

---------

Co-authored-by: Liam Aharon <[email protected]>
Co-authored-by: parity-processbot <>
  • Loading branch information
deepink-mas and liamaharon authored Jul 14, 2023
1 parent b06e109 commit a7f3652
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 86 deletions.
81 changes: 40 additions & 41 deletions frame/balances/src/weights.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 13 additions & 45 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 All @@ -1855,9 +1855,7 @@ macro_rules! add_benchmark {
$crate::str::from_utf8(benchmark)
.expect("benchmark name is always a valid string!")
);
result.keys.insert(0,
(b"Benchmark Override".to_vec(), 0, 0, false)
);
result.keys.insert(0, (b"Benchmark Override".to_vec(), 0, 0, false));
Some($crate::vec![result])
},
Err($crate::BenchmarkError::Stop(e)) => {
Expand All @@ -1868,7 +1866,7 @@ macro_rules! add_benchmark {
verify,
e,
);
return Err(e.into());
return Err(e.into())
},
Err($crate::BenchmarkError::Skip) => {
$crate::log::error!(
Expand All @@ -1886,9 +1884,9 @@ macro_rules! add_benchmark {
);
Some(vec![$crate::BenchmarkResult {
components: selected_components.clone(),
.. Default::default()
..Default::default()
}])
}
},
};

if let Some(final_results) = final_results {
Expand All @@ -1900,21 +1898,7 @@ 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
Expand All @@ -1938,39 +1922,25 @@ 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(),
benchmarks: benchmarks.to_vec(),
};
$list.push(pallet_benchmarks)
)
}

/// 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 +1951,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 +1965,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 +1977,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

0 comments on commit a7f3652

Please sign in to comment.