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

Use define_benchmarks! #4760

Merged
merged 2 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
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
21 changes: 15 additions & 6 deletions bridges/bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,17 @@ pub type Executive = frame_executive::Executive<
AllPallets,
>;

#[cfg(feature = "runtime-benchmarks")]
#[macro_use]
extern crate frame_benchmarking;

#[cfg(feature = "runtime-benchmarks")]
mod benches {
define_benchmarks!(
[pallet_bridge_token_swap, BridgeRialtoTokenSwap]
);
}

impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
Expand Down Expand Up @@ -802,22 +813,20 @@ impl_runtime_apis! {
Vec<frame_benchmarking::BenchmarkList>,
Vec<frame_support::traits::StorageInfo>,
) {
use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
use frame_benchmarking::{Benchmarking, BenchmarkList};
use frame_support::traits::StorageInfoTrait;

let mut list = Vec::<BenchmarkList>::new();

list_benchmark!(list, extra, pallet_bridge_token_swap, BridgeRialtoTokenSwap);
list_benchmarks!(list, extra);

let storage_info = AllPalletsWithSystem::storage_info();

return (list, storage_info)
}

fn dispatch_benchmark(
config: frame_benchmarking::BenchmarkConfig,
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey, add_benchmark};
use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey};

let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
Expand Down Expand Up @@ -850,7 +859,7 @@ impl_runtime_apis! {
}
}

add_benchmark!(params, batches, pallet_bridge_token_swap, BridgeRialtoTokenSwap);
add_benchmarks!(params, batches);

if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)
Expand Down
20 changes: 15 additions & 5 deletions bridges/bin/rialto-parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,19 @@ construct_runtime!(
}
);

#[cfg(feature = "runtime-benchmarks")]
#[macro_use]
extern crate frame_benchmarking;

#[cfg(feature = "runtime-benchmarks")]
mod benches {
define_benchmarks!(
[frame_system, SystemBench::<Runtime>]
[pallet_balances, Balances]
[pallet_timestamp, Timestamp]
);
}

impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
Expand Down Expand Up @@ -586,7 +599,7 @@ impl_runtime_apis! {
fn dispatch_benchmark(
config: frame_benchmarking::BenchmarkConfig
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey};

use frame_system_benchmarking::Pallet as SystemBench;
impl frame_system_benchmarking::Config for Runtime {}
Expand All @@ -606,10 +619,7 @@ impl_runtime_apis! {

let mut batches = Vec::<BenchmarkBatch>::new();
let params = (&config, &whitelist);

add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
add_benchmark!(params, batches, pallet_balances, Balances);
add_benchmark!(params, batches, pallet_timestamp, Timestamp);
add_benchmarks!(params, batches);

if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)
Expand Down
30 changes: 17 additions & 13 deletions bridges/bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,19 @@ pub type Executive = frame_executive::Executive<
AllPallets,
>;

#[cfg(feature = "runtime-benchmarks")]
#[macro_use]
extern crate frame_benchmarking;

#[cfg(feature = "runtime-benchmarks")]
mod benches {
define_benchmarks!(
[pallet_bridge_messages,
MessagesBench::<Runtime, WithMillauMessagesInstance>]
[pallet_bridge_grandpa, BridgeMillauGrandpa]
);
}

impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
Expand Down Expand Up @@ -947,18 +960,15 @@ impl_runtime_apis! {
Vec<frame_benchmarking::BenchmarkList>,
Vec<frame_support::traits::StorageInfo>,
) {
use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
use frame_benchmarking::{Benchmarking, BenchmarkList};
use frame_support::traits::StorageInfoTrait;

use pallet_bridge_messages::benchmarking::Pallet as MessagesBench;

let mut list = Vec::<BenchmarkList>::new();

list_benchmark!(list, extra, pallet_bridge_messages, MessagesBench::<Runtime, WithMillauMessagesInstance>);
list_benchmark!(list, extra, pallet_bridge_grandpa, BridgeMillauGrandpa);
list_benchmarks!(list, extra);

let storage_info = AllPalletsWithSystem::storage_info();

return (list, storage_info)
}

Expand All @@ -968,7 +978,7 @@ impl_runtime_apis! {
Vec<frame_benchmarking::BenchmarkBatch>,
sp_runtime::RuntimeString,
> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey};
use frame_support::traits::StorageInfoTrait;

let whitelist: Vec<TrackedStorageKey> = vec![
Expand Down Expand Up @@ -1153,13 +1163,7 @@ impl_runtime_apis! {
}
}

add_benchmark!(
params,
batches,
pallet_bridge_messages,
MessagesBench::<Runtime, WithMillauMessagesInstance>
);
add_benchmark!(params, batches, pallet_bridge_grandpa, BridgeMillauGrandpa);
add_benchmarks!(params, batches);

Ok(batches)
}
Expand Down
132 changes: 53 additions & 79 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2946,6 +2946,54 @@ impl OnRuntimeUpgrade for SessionHistoricalPalletPrefixMigration {
}
}

#[cfg(feature = "runtime-benchmarks")]
#[macro_use]
extern crate frame_benchmarking;

#[cfg(feature = "runtime-benchmarks")]
mod benches {
define_benchmarks!(
// Polkadot
[runtime_common::auctions, Auctions]
[runtime_common::crowdloan, Crowdloan]
[runtime_common::claims, Claims]
[runtime_common::slots, Slots]
[runtime_common::paras_registrar, Registrar]
[runtime_parachains::configuration, Configuration]
[runtime_parachains::disputes, ParasDisputes]
[runtime_parachains::initializer, Initializer]
[runtime_parachains::paras_inherent, ParaInherent]
[runtime_parachains::paras, Paras]
// Substrate
[pallet_balances, Balances]
[pallet_bags_list, BagsList]
[pallet_bounties, Bounties]
[pallet_collective, Council]
[pallet_collective, TechnicalCommittee]
[pallet_democracy, Democracy]
[pallet_elections_phragmen, PhragmenElection]
[pallet_election_provider_multi_phase, ElectionProviderMultiPhase]
[pallet_gilt, Gilt]
[pallet_identity, Identity]
[pallet_im_online, ImOnline]
[pallet_indices, Indices]
[pallet_membership, TechnicalMembership]
[pallet_multisig, Multisig]
[pallet_offences, OffencesBench::<Runtime>]
[pallet_preimage, Preimage]
[pallet_proxy, Proxy]
[pallet_scheduler, Scheduler]
[pallet_session, SessionBench::<Runtime>]
[pallet_staking, Staking]
[frame_system, SystemBench::<Runtime>]
[pallet_timestamp, Timestamp]
[pallet_tips, Tips]
[pallet_treasury, Treasury]
[pallet_utility, Utility]
[pallet_vesting, Vesting]
);
}

#[cfg(not(feature = "disable-runtime-api"))]
sp_api::impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
Expand Down Expand Up @@ -3279,7 +3327,7 @@ sp_api::impl_runtime_apis! {
Vec<frame_benchmarking::BenchmarkList>,
Vec<frame_support::traits::StorageInfo>,
) {
use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
use frame_benchmarking::{Benchmarking, BenchmarkList};
use frame_support::traits::StorageInfoTrait;

use pallet_session_benchmarking::Pallet as SessionBench;
Expand All @@ -3291,43 +3339,7 @@ sp_api::impl_runtime_apis! {
// Polkadot
// NOTE: Make sure to prefix these `runtime_common::` so that path resolves correctly
// in the generated file.
list_benchmark!(list, extra, runtime_common::auctions, Auctions);
list_benchmark!(list, extra, runtime_common::crowdloan, Crowdloan);
list_benchmark!(list, extra, runtime_common::claims, Claims);
list_benchmark!(list, extra, runtime_common::slots, Slots);
list_benchmark!(list, extra, runtime_common::paras_registrar, Registrar);
list_benchmark!(list, extra, runtime_parachains::configuration, Configuration);
list_benchmark!(list, extra, runtime_parachains::disputes, ParasDisputes);
list_benchmark!(list, extra, runtime_parachains::initializer, Initializer);
list_benchmark!(list, extra, runtime_parachains::paras_inherent, ParaInherent);
list_benchmark!(list, extra, runtime_parachains::paras, Paras);
// Substrate
list_benchmark!(list, extra, pallet_bags_list, BagsList);
list_benchmark!(list, extra, pallet_balances, Balances);
list_benchmark!(list, extra, pallet_bounties, Bounties);
list_benchmark!(list, extra, pallet_collective, Council);
list_benchmark!(list, extra, pallet_collective, TechnicalCommittee);
list_benchmark!(list, extra, pallet_democracy, Democracy);
list_benchmark!(list, extra, pallet_elections_phragmen, PhragmenElection);
list_benchmark!(list, extra, pallet_election_provider_multi_phase, ElectionProviderMultiPhase);
list_benchmark!(list, extra, pallet_gilt, Gilt);
list_benchmark!(list, extra, pallet_identity, Identity);
list_benchmark!(list, extra, pallet_im_online, ImOnline);
list_benchmark!(list, extra, pallet_indices, Indices);
list_benchmark!(list, extra, pallet_membership, TechnicalMembership);
list_benchmark!(list, extra, pallet_multisig, Multisig);
list_benchmark!(list, extra, pallet_offences, OffencesBench::<Runtime>);
list_benchmark!(list, extra, pallet_preimage, Preimage);
list_benchmark!(list, extra, pallet_proxy, Proxy);
list_benchmark!(list, extra, pallet_scheduler, Scheduler);
list_benchmark!(list, extra, pallet_session, SessionBench::<Runtime>);
list_benchmark!(list, extra, pallet_staking, Staking);
list_benchmark!(list, extra, frame_system, SystemBench::<Runtime>);
list_benchmark!(list, extra, pallet_timestamp, Timestamp);
list_benchmark!(list, extra, pallet_tips, Tips);
list_benchmark!(list, extra, pallet_treasury, Treasury);
list_benchmark!(list, extra, pallet_utility, Utility);
list_benchmark!(list, extra, pallet_vesting, Vesting);
list_benchmarks!(list, extra);

let storage_info = AllPalletsWithSystem::storage_info();

Expand All @@ -3340,7 +3352,7 @@ sp_api::impl_runtime_apis! {
Vec<frame_benchmarking::BenchmarkBatch>,
sp_runtime::RuntimeString,
> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey};
// Trying to add benchmarks directly to some pallets caused cyclic dependency issues.
// To get around that, we separated the benchmarks into its own crate.
use pallet_session_benchmarking::Pallet as SessionBench;
Expand Down Expand Up @@ -3368,46 +3380,8 @@ sp_api::impl_runtime_apis! {

let mut batches = Vec::<BenchmarkBatch>::new();
let params = (&config, &whitelist);
// Polkadot
// NOTE: Make sure to prefix these `runtime_common::` so that path resolves correctly
// in the generated file.
add_benchmark!(params, batches, runtime_common::auctions, Auctions);
add_benchmark!(params, batches, runtime_common::crowdloan, Crowdloan);
add_benchmark!(params, batches, runtime_common::claims, Claims);
add_benchmark!(params, batches, runtime_common::slots, Slots);
add_benchmark!(params, batches, runtime_common::paras_registrar, Registrar);
add_benchmark!(params, batches, runtime_parachains::configuration, Configuration);
add_benchmark!(params, batches, runtime_parachains::disputes, ParasDisputes);
add_benchmark!(params, batches, runtime_parachains::initializer, Initializer);
add_benchmark!(params, batches, runtime_parachains::paras_inherent, ParaInherent);
add_benchmark!(params, batches, runtime_parachains::paras, Paras);
// Substrate
add_benchmark!(params, batches, pallet_balances, Balances);
add_benchmark!(params, batches, pallet_bags_list, BagsList);
add_benchmark!(params, batches, pallet_bounties, Bounties);
add_benchmark!(params, batches, pallet_collective, Council);
add_benchmark!(params, batches, pallet_collective, TechnicalCommittee);
add_benchmark!(params, batches, pallet_democracy, Democracy);
add_benchmark!(params, batches, pallet_elections_phragmen, PhragmenElection);
add_benchmark!(params, batches, pallet_election_provider_multi_phase, ElectionProviderMultiPhase);
add_benchmark!(params, batches, pallet_gilt, Gilt);
add_benchmark!(params, batches, pallet_identity, Identity);
add_benchmark!(params, batches, pallet_im_online, ImOnline);
add_benchmark!(params, batches, pallet_indices, Indices);
add_benchmark!(params, batches, pallet_membership, TechnicalMembership);
add_benchmark!(params, batches, pallet_multisig, Multisig);
add_benchmark!(params, batches, pallet_offences, OffencesBench::<Runtime>);
add_benchmark!(params, batches, pallet_preimage, Preimage);
add_benchmark!(params, batches, pallet_proxy, Proxy);
add_benchmark!(params, batches, pallet_scheduler, Scheduler);
add_benchmark!(params, batches, pallet_session, SessionBench::<Runtime>);
add_benchmark!(params, batches, pallet_staking, Staking);
add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
add_benchmark!(params, batches, pallet_timestamp, Timestamp);
add_benchmark!(params, batches, pallet_tips, Tips);
add_benchmark!(params, batches, pallet_treasury, Treasury);
add_benchmark!(params, batches, pallet_utility, Utility);
add_benchmark!(params, batches, pallet_vesting, Vesting);

add_benchmarks!(params, batches);

if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)
Expand Down
Loading