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

Commit 2327eae

Browse files
authored
Use define_benchmarks! (#926)
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
1 parent d07da1c commit 2327eae

File tree

4 files changed

+91
-90
lines changed

4 files changed

+91
-90
lines changed

parachain-template/runtime/src/lib.rs

+19-15
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,21 @@ construct_runtime!(
629629
}
630630
);
631631

632+
#[cfg(feature = "runtime-benchmarks")]
633+
#[macro_use]
634+
extern crate frame_benchmarking;
635+
636+
#[cfg(feature = "runtime-benchmarks")]
637+
mod benches {
638+
define_benchmarks!(
639+
[frame_system, SystemBench::<Runtime>]
640+
[pallet_balances, Balances]
641+
[pallet_session, SessionBench::<Runtime>]
642+
[pallet_timestamp, Timestamp]
643+
[pallet_collator_selection, CollatorSelection]
644+
);
645+
}
646+
632647
impl_runtime_apis! {
633648
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
634649
fn slot_duration() -> sp_consensus_aura::SlotDuration {
@@ -755,28 +770,22 @@ impl_runtime_apis! {
755770
Vec<frame_benchmarking::BenchmarkList>,
756771
Vec<frame_support::traits::StorageInfo>,
757772
) {
758-
use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
773+
use frame_benchmarking::{Benchmarking, BenchmarkList};
759774
use frame_support::traits::StorageInfoTrait;
760775
use frame_system_benchmarking::Pallet as SystemBench;
761776
use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
762777

763778
let mut list = Vec::<BenchmarkList>::new();
764-
765-
list_benchmark!(list, extra, frame_system, SystemBench::<Runtime>);
766-
list_benchmark!(list, extra, pallet_balances, Balances);
767-
list_benchmark!(list, extra, pallet_session, SessionBench::<Runtime>);
768-
list_benchmark!(list, extra, pallet_timestamp, Timestamp);
769-
list_benchmark!(list, extra, pallet_collator_selection, CollatorSelection);
779+
list_benchmarks!(list, extra);
770780

771781
let storage_info = AllPalletsWithSystem::storage_info();
772-
773782
return (list, storage_info)
774783
}
775784

776785
fn dispatch_benchmark(
777786
config: frame_benchmarking::BenchmarkConfig
778787
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
779-
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
788+
use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey};
780789

781790
use frame_system_benchmarking::Pallet as SystemBench;
782791
impl frame_system_benchmarking::Config for Runtime {}
@@ -799,12 +808,7 @@ impl_runtime_apis! {
799808

800809
let mut batches = Vec::<BenchmarkBatch>::new();
801810
let params = (&config, &whitelist);
802-
803-
add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
804-
add_benchmark!(params, batches, pallet_balances, Balances);
805-
add_benchmark!(params, batches, pallet_session, SessionBench::<Runtime>);
806-
add_benchmark!(params, batches, pallet_timestamp, Timestamp);
807-
add_benchmark!(params, batches, pallet_collator_selection, CollatorSelection);
811+
add_benchmarks!(params, batches);
808812

809813
if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
810814
Ok(batches)

polkadot-parachains/statemine/src/lib.rs

+24-25
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,26 @@ impl frame_support::traits::OnRuntimeUpgrade for UniquesV1Migration {
802802
}
803803
}
804804

805+
#[cfg(feature = "runtime-benchmarks")]
806+
#[macro_use]
807+
extern crate frame_benchmarking;
808+
809+
#[cfg(feature = "runtime-benchmarks")]
810+
mod benches {
811+
define_benchmarks!(
812+
[frame_system, SystemBench::<Runtime>]
813+
[pallet_assets, Assets]
814+
[pallet_balances, Balances]
815+
[pallet_multisig, Multisig]
816+
[pallet_proxy, Proxy]
817+
[pallet_session, SessionBench::<Runtime>]
818+
[pallet_uniques, Uniques]
819+
[pallet_utility, Utility]
820+
[pallet_timestamp, Timestamp]
821+
[pallet_collator_selection, CollatorSelection]
822+
);
823+
}
824+
805825
impl_runtime_apis! {
806826
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
807827
fn slot_duration() -> sp_consensus_aura::SlotDuration {
@@ -928,33 +948,22 @@ impl_runtime_apis! {
928948
Vec<frame_benchmarking::BenchmarkList>,
929949
Vec<frame_support::traits::StorageInfo>,
930950
) {
931-
use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
951+
use frame_benchmarking::{Benchmarking, BenchmarkList};
932952
use frame_support::traits::StorageInfoTrait;
933953
use frame_system_benchmarking::Pallet as SystemBench;
934954
use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
935955

936956
let mut list = Vec::<BenchmarkList>::new();
937-
938-
list_benchmark!(list, extra, frame_system, SystemBench::<Runtime>);
939-
list_benchmark!(list, extra, pallet_assets, Assets);
940-
list_benchmark!(list, extra, pallet_balances, Balances);
941-
list_benchmark!(list, extra, pallet_multisig, Multisig);
942-
list_benchmark!(list, extra, pallet_proxy, Proxy);
943-
list_benchmark!(list, extra, pallet_session, SessionBench::<Runtime>);
944-
list_benchmark!(list, extra, pallet_uniques, Uniques);
945-
list_benchmark!(list, extra, pallet_utility, Utility);
946-
list_benchmark!(list, extra, pallet_timestamp, Timestamp);
947-
list_benchmark!(list, extra, pallet_collator_selection, CollatorSelection);
957+
list_benchmarks!(list, extra);
948958

949959
let storage_info = AllPalletsWithSystem::storage_info();
950-
951960
return (list, storage_info)
952961
}
953962

954963
fn dispatch_benchmark(
955964
config: frame_benchmarking::BenchmarkConfig
956965
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
957-
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
966+
use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey};
958967

959968
use frame_system_benchmarking::Pallet as SystemBench;
960969
impl frame_system_benchmarking::Config for Runtime {}
@@ -977,17 +986,7 @@ impl_runtime_apis! {
977986

978987
let mut batches = Vec::<BenchmarkBatch>::new();
979988
let params = (&config, &whitelist);
980-
981-
add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
982-
add_benchmark!(params, batches, pallet_assets, Assets);
983-
add_benchmark!(params, batches, pallet_balances, Balances);
984-
add_benchmark!(params, batches, pallet_multisig, Multisig);
985-
add_benchmark!(params, batches, pallet_proxy, Proxy);
986-
add_benchmark!(params, batches, pallet_session, SessionBench::<Runtime>);
987-
add_benchmark!(params, batches, pallet_uniques, Uniques);
988-
add_benchmark!(params, batches, pallet_utility, Utility);
989-
add_benchmark!(params, batches, pallet_timestamp, Timestamp);
990-
add_benchmark!(params, batches, pallet_collator_selection, CollatorSelection);
989+
add_benchmarks!(params, batches);
991990

992991
if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
993992
Ok(batches)

polkadot-parachains/statemint/src/lib.rs

+24-25
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,26 @@ pub type Executive = frame_executive::Executive<
797797
AllPalletsWithSystem,
798798
>;
799799

800+
#[cfg(feature = "runtime-benchmarks")]
801+
#[macro_use]
802+
extern crate frame_benchmarking;
803+
804+
#[cfg(feature = "runtime-benchmarks")]
805+
mod benches {
806+
define_benchmarks!(
807+
[frame_system, SystemBench::<Runtime>]
808+
[pallet_assets, Assets]
809+
[pallet_balances, Balances]
810+
[pallet_multisig, Multisig]
811+
[pallet_proxy, Proxy]
812+
[pallet_session, SessionBench::<Runtime>]
813+
[pallet_uniques, Uniques]
814+
[pallet_utility, Utility]
815+
[pallet_timestamp, Timestamp]
816+
[pallet_collator_selection, CollatorSelection]
817+
);
818+
}
819+
800820
impl_runtime_apis! {
801821
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
802822
fn slot_duration() -> sp_consensus_aura::SlotDuration {
@@ -923,33 +943,22 @@ impl_runtime_apis! {
923943
Vec<frame_benchmarking::BenchmarkList>,
924944
Vec<frame_support::traits::StorageInfo>,
925945
) {
926-
use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
946+
use frame_benchmarking::{Benchmarking, BenchmarkList};
927947
use frame_support::traits::StorageInfoTrait;
928948
use frame_system_benchmarking::Pallet as SystemBench;
929949
use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
930950

931951
let mut list = Vec::<BenchmarkList>::new();
932-
933-
list_benchmark!(list, extra, frame_system, SystemBench::<Runtime>);
934-
list_benchmark!(list, extra, pallet_assets, Assets);
935-
list_benchmark!(list, extra, pallet_balances, Balances);
936-
list_benchmark!(list, extra, pallet_multisig, Multisig);
937-
list_benchmark!(list, extra, pallet_proxy, Proxy);
938-
list_benchmark!(list, extra, pallet_session, SessionBench::<Runtime>);
939-
list_benchmark!(list, extra, pallet_uniques, Uniques);
940-
list_benchmark!(list, extra, pallet_utility, Utility);
941-
list_benchmark!(list, extra, pallet_timestamp, Timestamp);
942-
list_benchmark!(list, extra, pallet_collator_selection, CollatorSelection);
952+
list_benchmarks!(list, extra);
943953

944954
let storage_info = AllPalletsWithSystem::storage_info();
945-
946955
return (list, storage_info)
947956
}
948957

949958
fn dispatch_benchmark(
950959
config: frame_benchmarking::BenchmarkConfig
951960
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
952-
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
961+
use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey};
953962

954963
use frame_system_benchmarking::Pallet as SystemBench;
955964
impl frame_system_benchmarking::Config for Runtime {}
@@ -972,17 +981,7 @@ impl_runtime_apis! {
972981

973982
let mut batches = Vec::<BenchmarkBatch>::new();
974983
let params = (&config, &whitelist);
975-
976-
add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
977-
add_benchmark!(params, batches, pallet_assets, Assets);
978-
add_benchmark!(params, batches, pallet_balances, Balances);
979-
add_benchmark!(params, batches, pallet_multisig, Multisig);
980-
add_benchmark!(params, batches, pallet_proxy, Proxy);
981-
add_benchmark!(params, batches, pallet_session, SessionBench::<Runtime>);
982-
add_benchmark!(params, batches, pallet_uniques, Uniques);
983-
add_benchmark!(params, batches, pallet_utility, Utility);
984-
add_benchmark!(params, batches, pallet_timestamp, Timestamp);
985-
add_benchmark!(params, batches, pallet_collator_selection, CollatorSelection);
984+
add_benchmarks!(params, batches);
986985

987986
if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
988987
Ok(batches)

polkadot-parachains/westmint/src/lib.rs

+24-25
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,26 @@ impl frame_support::traits::OnRuntimeUpgrade for RemoveCollectiveFlip {
780780
}
781781
}
782782

783+
#[cfg(feature = "runtime-benchmarks")]
784+
#[macro_use]
785+
extern crate frame_benchmarking;
786+
787+
#[cfg(feature = "runtime-benchmarks")]
788+
mod benches {
789+
define_benchmarks!(
790+
[frame_system, SystemBench::<Runtime>]
791+
[pallet_assets, Assets]
792+
[pallet_balances, Balances]
793+
[pallet_multisig, Multisig]
794+
[pallet_proxy, Proxy]
795+
[pallet_session, SessionBench::<Runtime>]
796+
[pallet_uniques, Uniques]
797+
[pallet_utility, Utility]
798+
[pallet_timestamp, Timestamp]
799+
[pallet_collator_selection, CollatorSelection]
800+
);
801+
}
802+
783803
impl_runtime_apis! {
784804
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
785805
fn slot_duration() -> sp_consensus_aura::SlotDuration {
@@ -906,33 +926,22 @@ impl_runtime_apis! {
906926
Vec<frame_benchmarking::BenchmarkList>,
907927
Vec<frame_support::traits::StorageInfo>,
908928
) {
909-
use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
929+
use frame_benchmarking::{Benchmarking, BenchmarkList};
910930
use frame_support::traits::StorageInfoTrait;
911931
use frame_system_benchmarking::Pallet as SystemBench;
912932
use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
913933

914934
let mut list = Vec::<BenchmarkList>::new();
915-
916-
list_benchmark!(list, extra, frame_system, SystemBench::<Runtime>);
917-
list_benchmark!(list, extra, pallet_assets, Assets);
918-
list_benchmark!(list, extra, pallet_balances, Balances);
919-
list_benchmark!(list, extra, pallet_multisig, Multisig);
920-
list_benchmark!(list, extra, pallet_proxy, Proxy);
921-
list_benchmark!(list, extra, pallet_session, SessionBench::<Runtime>);
922-
list_benchmark!(list, extra, pallet_uniques, Uniques);
923-
list_benchmark!(list, extra, pallet_utility, Utility);
924-
list_benchmark!(list, extra, pallet_timestamp, Timestamp);
925-
list_benchmark!(list, extra, pallet_collator_selection, CollatorSelection);
935+
list_benchmarks!(list, extra);
926936

927937
let storage_info = AllPalletsWithSystem::storage_info();
928-
929938
return (list, storage_info)
930939
}
931940

932941
fn dispatch_benchmark(
933942
config: frame_benchmarking::BenchmarkConfig
934943
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
935-
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
944+
use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey};
936945

937946
use frame_system_benchmarking::Pallet as SystemBench;
938947
impl frame_system_benchmarking::Config for Runtime {}
@@ -955,17 +964,7 @@ impl_runtime_apis! {
955964

956965
let mut batches = Vec::<BenchmarkBatch>::new();
957966
let params = (&config, &whitelist);
958-
959-
add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
960-
add_benchmark!(params, batches, pallet_assets, Assets);
961-
add_benchmark!(params, batches, pallet_balances, Balances);
962-
add_benchmark!(params, batches, pallet_multisig, Multisig);
963-
add_benchmark!(params, batches, pallet_proxy, Proxy);
964-
add_benchmark!(params, batches, pallet_session, SessionBench::<Runtime>);
965-
add_benchmark!(params, batches, pallet_uniques, Uniques);
966-
add_benchmark!(params, batches, pallet_utility, Utility);
967-
add_benchmark!(params, batches, pallet_timestamp, Timestamp);
968-
add_benchmark!(params, batches, pallet_collator_selection, CollatorSelection);
967+
add_benchmarks!(params, batches);
969968

970969
if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
971970
Ok(batches)

0 commit comments

Comments
 (0)