Skip to content

Commit 74523df

Browse files
Add benchmark for darwinia
1 parent cbe463e commit 74523df

File tree

7 files changed

+47
-1
lines changed

7 files changed

+47
-1
lines changed

Cargo.lock

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ dev = [
3333

3434
try-runtime = ["darwinia-cli/try-runtime"]
3535

36+
runtime-benchmarks = [
37+
"darwinia-cli/runtime-benchmarks",
38+
]
39+
40+
3641
[workspace]
3742
members = [
3843
"cli",

cli/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ darwinia-cli = { optional = true, git = "https://github.com/darwinia-network/dar
2929
darwinia-service = { default-features = false, path = "../node/service" }
3030
# substrate client
3131
sc-cli = { optional = true, git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
32+
"frame-benchmarking-cli" = { optional = true, git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
3233
sc-client-api = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
3334
sc-executor = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
3435
sc-network = { optional = true, git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
@@ -75,4 +76,6 @@ try-runtime = [
7576
"try-runtime-cli",
7677
]
7778

78-
runtime-benchmarks = []
79+
runtime-benchmarks = [
80+
"frame-benchmarking-cli",
81+
]

node/service/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,5 @@ try-runtime = [
9898
runtime-benchmarks = [
9999
"frame-benchmarking-cli",
100100
"crab-runtime/runtime-benchmarks",
101+
"darwinia-runtime/runtime-benchmarks",
101102
]

node/service/src/service/darwinia.rs

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ native_executor_instance!(
6363
pub DarwiniaExecutor,
6464
darwinia_runtime::api::dispatch,
6565
darwinia_runtime::native_version,
66+
frame_benchmarking::benchmarking::HostFunctions,
6667
);
6768

6869
impl_runtime_apis!();

runtime/darwinia/Cargo.toml

+12
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ darwinia-support = { default-features = false, git = "https:/
3636
darwinia-treasury = { default-features = false, git = "https://github.com/darwinia-network/darwinia-common.git", tag = "darwinia-v0.11.2" }
3737
darwinia-tron-backing = { default-features = false, git = "https://github.com/darwinia-network/darwinia-common.git", tag = "darwinia-v0.11.2" }
3838
darwinia-vesting = { default-features = false, git = "https://github.com/darwinia-network/darwinia-common.git", tag = "darwinia-v0.11.2" }
39+
frame-benchmarking = { optional=true, default-features = false, git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
40+
frame-system-benchmarking = { optional=true, default-features = false, git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
3941
# darwinia primitives
4042
darwinia-primitives = { default-features = false, path = "../../primitives" }
4143
ethereum-primitives = { default-features = false, git = "https://github.com/darwinia-network/darwinia-common.git", tag = "darwinia-v0.11.2" }
@@ -118,6 +120,7 @@ std = [
118120
"darwinia-runtime-common/std",
119121
"frame-executive/std",
120122
"frame-support/std",
123+
"frame-benchmarking/std",
121124
"frame-system/std",
122125
"frame-system-rpc-runtime-api/std",
123126
"frame-try-runtime/std",
@@ -173,3 +176,12 @@ try-runtime = [
173176
on-chain-release-build = [
174177
"sp-api/disable-logging",
175178
]
179+
180+
runtime-benchmarks = [
181+
"frame-benchmarking",
182+
"frame-system-benchmarking",
183+
"frame-system/runtime-benchmarks",
184+
"frame-support/runtime-benchmarks",
185+
"pallet-collective/runtime-benchmarks",
186+
"pallet-society/runtime-benchmarks",
187+
]

runtime/darwinia/src/lib.rs

+21
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,27 @@ impl_runtime_apis! {
564564
Ok((weight, RuntimeBlockWeights::get().max_block))
565565
}
566566
}
567+
568+
#[cfg(feature = "runtime-benchmarks")]
569+
impl frame_benchmarking::Benchmark<Block> for Runtime {
570+
fn dispatch_benchmark(
571+
config: frame_benchmarking::BenchmarkConfig
572+
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
573+
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
574+
use frame_system_benchmarking::Pallet as SystemBench;
575+
impl frame_system_benchmarking::Config for Runtime {}
576+
577+
let whitelist: Vec<TrackedStorageKey> = vec![];
578+
579+
let mut batches = Vec::<BenchmarkBatch>::new();
580+
let params = (&config, &whitelist);
581+
582+
add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
583+
584+
if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
585+
Ok(batches)
586+
}
587+
}
567588
}
568589

569590
const PARCEL: &[u8] = &[

0 commit comments

Comments
 (0)