Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchmark framework #700

Merged
merged 5 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
116 changes: 110 additions & 6 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ dev = [

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

runtime-benchmarks = ["darwinia-cli/runtime-benchmarks"]

[workspace]
members = [
"cli",
Expand Down
7 changes: 7 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ sc-network = { optional = true, git = "https://github.com/darwinia-network/
sc-service = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
sc-tracing = { optional = true, git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
try-runtime-cli = { optional = true, git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
# benchmark
frame-benchmarking-cli = { optional = true, git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
# substrate primitives
sp-core = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
# this crate is used only to enable `trie-memory-tracker` feature
Expand Down Expand Up @@ -74,3 +76,8 @@ try-runtime = [
"darwinia-service/try-runtime",
"try-runtime-cli",
]

runtime-benchmarks = [
"frame-benchmarking-cli",
"darwinia-service/runtime-benchmarks",
]
5 changes: 5 additions & 0 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ pub enum Subcommand {
/// testing.
#[cfg(feature = "try-runtime")]
TryRuntime(try_runtime_cli::TryRuntimeCmd),

/// The custom benchmark subcommmand benchmarking runtime pallets.
#[cfg(feature = "runtime-benchmarks")]
#[structopt(name = "benchmark", about = "Benchmark runtime pallets.")]
Benchmark(frame_benchmarking_cli::BenchmarkCmd),
}

#[derive(Debug, StructOpt)]
Expand Down
16 changes: 16 additions & 0 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,5 +410,21 @@ pub fn run() -> sc_cli::Result<()> {
unreachable!()
}
}
#[cfg(feature = "runtime-benchmarks")]
Some(Subcommand::Benchmark(cmd)) => {
let runner = cli.create_runner(cmd)?;
let chain_spec = &runner.config().chain_spec;

if chain_spec.is_crab() {
runner.sync_run(|config| cmd.run::<crab_runtime::Block, CrabExecutor>(config))
} else if chain_spec.is_darwinia() {
runner
.sync_run(|config| cmd.run::<darwinia_runtime::Block, DarwiniaExecutor>(config))
} else {
Err("Benchmarking wasn't enabled when building the node. \
You can enable it with `--features runtime-benchmarks`."
.into())
}
}
}
}
17 changes: 17 additions & 0 deletions file_header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// This file is part of Darwinia.
//
// Copyright (C) 2018-2021 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.
6 changes: 6 additions & 0 deletions node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ sc-service = { git = "https://github.com/darwinia-network/substrate.
sc-telemetry = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
sc-transaction-pool = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
# substrate frame
frame-benchmarking = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
frame-system-rpc-runtime-api = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
pallet-im-online = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
Expand Down Expand Up @@ -92,3 +93,8 @@ try-runtime = [
"crab-runtime/try-runtime",
"darwinia-runtime/try-runtime",
]

runtime-benchmarks = [
"crab-runtime/runtime-benchmarks",
"darwinia-runtime/runtime-benchmarks",
]
1 change: 1 addition & 0 deletions node/service/src/service/crab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ native_executor_instance!(
pub CrabExecutor,
crab_runtime::api::dispatch,
crab_runtime::native_version,
frame_benchmarking::benchmarking::HostFunctions,
);

impl_runtime_apis!(dvm_rpc_runtime_api::EthereumRuntimeRPCApi<Block>);
Expand Down
1 change: 1 addition & 0 deletions node/service/src/service/darwinia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ native_executor_instance!(
pub DarwiniaExecutor,
darwinia_runtime::api::dispatch,
darwinia_runtime::native_version,
frame_benchmarking::benchmarking::HostFunctions,
);

impl_runtime_apis!();
Expand Down
11 changes: 11 additions & 0 deletions runtime/crab/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ ethereum-primitives = { default-features = false, git = "https://github.com/darw
# darwinia runtime
darwinia-runtime-common = { default-features = false, path = "../common" }
# substrate frame
frame-benchmarking = { optional=true, default-features = false, git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
frame-system-benchmarking = { optional=true, default-features = false, git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
frame-executive = { default-features = false, git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
frame-support = { default-features = false, git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
frame-system = { default-features = false, git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.2" }
Expand Down Expand Up @@ -193,3 +195,12 @@ try-runtime = [
on-chain-release-build = [
"sp-api/disable-logging",
]

runtime-benchmarks = [
"frame-benchmarking",
"frame-system-benchmarking",
"frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-society/runtime-benchmarks",
]
22 changes: 22 additions & 0 deletions runtime/crab/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,28 @@ sp_api::impl_runtime_apis! {
Ok((weight, RuntimeBlockWeights::get().max_block))
}
}

#[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime {
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_system_benchmarking::Pallet as SystemBench;
impl frame_system_benchmarking::Config for Runtime {}

let whitelist: Vec<TrackedStorageKey> = vec![];

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


add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);

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

pub struct TransactionConverter;
Expand Down
Loading