Improve usability of add+list_benchmark! (#10592)

* Improve usability of add_benchmark and list_benchmark.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* node-template: use new define_benchmarks syntax

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* make CI happy

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* remove old imports

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fix TryBuild tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Revert "fix TryBuild tests"

This reverts commit 82ea52fd25c0ef5efa46669217694835a7404d4e.

* review: remove blank lines

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
Oliver Tale-Yazdi
2022-01-19 16:31:14 +01:00
committed by GitHub
parent f2c8fe35a3
commit c8c46fea96
3 changed files with 133 additions and 90 deletions
+65 -2
View File
@@ -1701,7 +1701,6 @@ pub fn show_benchmark_debug_info(
/// type Council2 = TechnicalCommittee;
/// add_benchmark!(params, batches, pallet_collective, Council2); // pallet_collective_council_2.rs
/// ```
#[macro_export]
macro_rules! add_benchmark {
( $params:ident, $batches:ident, $name:path, $( $location:tt )* ) => (
@@ -1770,6 +1769,20 @@ 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 )* ] ) => {
add_benchmark!( $params, $batches, $name, $( $location )* );
};
// recursion tail
( $params:ident, $batches:ident, [ $name:path, $( $location:tt )* ] $([ $names:path, $( $locations:tt )* ])+ ) => {
cb_add_benchmarks!( $params, $batches, [ $name, $( $location )* ] );
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.
///
@@ -1789,7 +1802,6 @@ macro_rules! add_benchmark {
/// ```
///
/// This should match what exists with the `add_benchmark!` macro.
#[macro_export]
macro_rules! list_benchmark {
( $list:ident, $extra:ident, $name:path, $( $location:tt )* ) => (
@@ -1804,3 +1816,54 @@ macro_rules! list_benchmark {
$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 )* ] ) => {
list_benchmark!( $list, $extra, $name, $( $location )* );
};
// recursion tail
( $list:ident, $extra:ident, [ $name:path, $( $location:tt )* ] $([ $names:path, $( $locations:tt )* ])+ ) => {
cb_list_benchmarks!( $list, $extra, [ $name, $( $location )* ] );
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 )* ])* ) => {
/// Calls `list_benchmark` with all configs from `define_benchmarks`
/// and passes the first two parameters on.
///
/// Use as:
/// ```ignore
/// list_benchmarks!(list, extra);
/// ```
#[macro_export]
macro_rules! list_benchmarks {
( $list:ident, $extra:ident ) => {
cb_list_benchmarks!( $list, $extra, $([ $names, $( $locations )* ])+ );
}
}
/// Calls `add_benchmark` with all configs from `define_benchmarks`
/// and passes the first two parameters on.
///
/// Use as:
/// ```ignore
/// add_benchmarks!(params, batches);
/// ```
#[macro_export]
macro_rules! add_benchmarks {
( $params:ident, $batches:ident ) => {
cb_add_benchmarks!( $params, $batches, $([ $names, $( $locations )* ])+ );
}
}
}
}