forked from paritytech/substrate
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add execution overhead benchmarking (paritytech#10977)
* Add benchmark-block Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Remove first approach This reverts commit 9ce7f32. * Add block and extrinsic benchmarks * Doc Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Fix template Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Beauty fixes Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Check for non-empty chain Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Add tests for Stats Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Review fixes Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Review fixes Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Apply suggestions from code review Co-authored-by: Shawn Tabrizi <[email protected]> * Review fixes Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Review fixes Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Push first version again Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Push first version again Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Cleanup Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Cleanup Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Cleanup Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Beauty fixes Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Apply suggestions from code review Co-authored-by: Bastian Köcher <[email protected]> * Update utils/frame/benchmarking-cli/src/overhead/template.rs Co-authored-by: Bastian Köcher <[email protected]> * Review fixes Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Doc + Template fixes Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Review fixes Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Comment fix Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Add test Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Pust merge fixup Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Fixup Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Move code to better place Signed-off-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: Shawn Tabrizi <[email protected]> Co-authored-by: Bastian Köcher <[email protected]>
- Loading branch information
1 parent
5471479
commit 8e345e0
Showing
17 changed files
with
852 additions
and
53 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// This file is part of Substrate. | ||
|
||
// Copyright (C) 2022 Parity Technologies (UK) Ltd. | ||
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
|
||
// This program 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. | ||
|
||
// This program 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 this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
//! Contains code to setup the command invocations in [`super::command`] which would | ||
//! otherwise bloat that module. | ||
use crate::service::{create_extrinsic, FullClient}; | ||
|
||
use node_runtime::SystemCall; | ||
use sc_cli::Result; | ||
use sp_inherents::{InherentData, InherentDataProvider}; | ||
use sp_keyring::Sr25519Keyring; | ||
use sp_runtime::OpaqueExtrinsic; | ||
|
||
use std::{sync::Arc, time::Duration}; | ||
|
||
/// Generates extrinsics for the `benchmark-overhead` command. | ||
pub struct ExtrinsicBuilder { | ||
client: Arc<FullClient>, | ||
} | ||
|
||
impl ExtrinsicBuilder { | ||
/// Creates a new [`Self`] from the given client. | ||
pub fn new(client: Arc<FullClient>) -> Self { | ||
Self { client } | ||
} | ||
} | ||
|
||
impl frame_benchmarking_cli::ExtrinsicBuilder for ExtrinsicBuilder { | ||
fn remark(&self, nonce: u32) -> std::result::Result<OpaqueExtrinsic, &'static str> { | ||
let acc = Sr25519Keyring::Bob.pair(); | ||
let extrinsic: OpaqueExtrinsic = create_extrinsic( | ||
self.client.as_ref(), | ||
acc, | ||
SystemCall::remark { remark: vec![] }, | ||
Some(nonce), | ||
) | ||
.into(); | ||
|
||
Ok(extrinsic) | ||
} | ||
} | ||
|
||
/// Generates inherent data for the `benchmark-overhead` command. | ||
pub fn inherent_data() -> Result<InherentData> { | ||
let mut inherent_data = InherentData::new(); | ||
let d = Duration::from_millis(0); | ||
let timestamp = sp_timestamp::InherentDataProvider::new(d.into()); | ||
|
||
timestamp | ||
.provide_inherent_data(&mut inherent_data) | ||
.map_err(|e| format!("creating inherent data: {:?}", e))?; | ||
Ok(inherent_data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// This file is part of Substrate. | ||
|
||
// Copyright (C) 2022 Parity Technologies (UK) Ltd. | ||
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
|
||
// This program 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. | ||
|
||
// This program 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 this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
use assert_cmd::cargo::cargo_bin; | ||
use std::process::Command; | ||
use tempfile::tempdir; | ||
|
||
/// Tests that the `benchmark-overhead` command works for the substrate dev runtime. | ||
#[test] | ||
fn benchmark_overhead_works() { | ||
let tmp_dir = tempdir().expect("could not create a temp dir"); | ||
let base_path = tmp_dir.path(); | ||
|
||
// Only put 10 extrinsics into the block otherwise it takes forever to build it | ||
// especially for a non-release build. | ||
let status = Command::new(cargo_bin("substrate")) | ||
.args(&["benchmark-overhead", "--dev", "-d"]) | ||
.arg(base_path) | ||
.arg("--weight-path") | ||
.arg(base_path) | ||
.args(["--warmup", "10", "--repeat", "10"]) | ||
.args(["--add", "100", "--mul", "1.2", "--metric", "p75"]) | ||
.args(["--max-ext-per-block", "10"]) | ||
.status() | ||
.unwrap(); | ||
assert!(status.success()); | ||
|
||
// Weight files have been created. | ||
assert!(base_path.join("block_weights.rs").exists()); | ||
assert!(base_path.join("extrinsic_weights.rs").exists()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.