This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add execution overhead benchmarking #10977
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
9ce7f32
Add benchmark-block
ggwpez f07941f
Remove first approach
ggwpez 60d2ebd
Add block and extrinsic benchmarks
ggwpez 5fb334b
Merge remote-tracking branch 'origin/master' into oty-block-bench
ggwpez 8a3a8a8
Doc
ggwpez 8928d9f
Fix template
ggwpez 6631602
Beauty fixes
ggwpez e683edb
Check for non-empty chain
ggwpez 3f2eaf4
Add tests for Stats
ggwpez a4ec657
Review fixes
ggwpez a73644b
Review fixes
ggwpez e004a5d
Apply suggestions from code review
ggwpez 48bc8fd
Review fixes
ggwpez b935d34
Review fixes
ggwpez aede827
Push first version again
ggwpez 902cae3
Push first version again
ggwpez 316209b
Cleanup
ggwpez 3b5e897
Merge remote-tracking branch 'origin/master' into oty-block-bench
ggwpez b40b650
Cleanup
ggwpez 9f1659b
Cleanup
ggwpez e6acb0c
Beauty fixes
ggwpez 0ed8303
Apply suggestions from code review
ggwpez a440311
Update utils/frame/benchmarking-cli/src/overhead/template.rs
ggwpez 0878563
Review fixes
ggwpez 6076428
Doc + Template fixes
ggwpez 59f478e
Review fixes
ggwpez 533667c
Comment fix
ggwpez a2c788a
Add test
ggwpez fc9f675
Merge remote-tracking branch 'origin/master' into oty-block-bench
ggwpez 7c6b2c0
Pust merge fixup
ggwpez 2bca7bb
Fixup
ggwpez cf2e763
Move code to better place
ggwpez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kicked this feature check out since it is not needed.