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

Add benchmark machine #11198

Merged
merged 28 commits into from Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4660595
Move new_rng to shared code
ggwpez Apr 9, 2022
e3241ad
Add bechmark machine command
ggwpez Apr 9, 2022
9301a05
Merge remote-tracking branch 'origin/master' into oty-benchmark-machine
ggwpez Apr 11, 2022
0e8bfa2
Use sc-sysinfo
ggwpez Apr 11, 2022
d4ee982
Add --no-hardware-benchmarks
ggwpez Apr 11, 2022
b49dc41
Lockfile
ggwpez Apr 11, 2022
dbb1e99
Do not create components if not needed
ggwpez Apr 11, 2022
dc8a89f
Fix tests
ggwpez Apr 11, 2022
279789e
Revert "Add --no-hardware-benchmarks"
ggwpez Apr 11, 2022
2cb3bab
Fix tests
ggwpez Apr 11, 2022
d625bc8
Update Cargo deps
ggwpez Apr 12, 2022
38d7679
Move sr255119::verify bench to sc-sysinfo
ggwpez Apr 12, 2022
1b9eb13
Move sr255119::verify bench to sc-sysinfo
ggwpez Apr 12, 2022
ea4b8fe
Switch benchmarks to return f64
ggwpez Apr 12, 2022
025fbb1
Review fixes
ggwpez Apr 12, 2022
0330f52
fmt
ggwpez Apr 12, 2022
74988b2
Hide command until completed
ggwpez Apr 12, 2022
9b53207
Merge remote-tracking branch 'origin/master' into oty-benchmark-machine
ggwpez Apr 13, 2022
9448088
Use concrete rand implementation
ggwpez Apr 14, 2022
124fb32
Put clobber into a function
ggwpez Apr 14, 2022
aa89d52
Add test
ggwpez Apr 14, 2022
7bc3083
Add comment
ggwpez Apr 14, 2022
2c4ba75
Update cargo to match polkadot
ggwpez Apr 14, 2022
69ab6a5
Remove doc that does not format in the console
ggwpez Apr 14, 2022
b53f8f9
Limit benchmark by time
ggwpez Apr 14, 2022
b478436
Add ExecutionLimit and make function infallible
ggwpez Apr 14, 2022
14b36a5
CI
ggwpez Apr 14, 2022
1ad85ea
Add doc
ggwpez Apr 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
86 changes: 78 additions & 8 deletions Cargo.lock

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

11 changes: 8 additions & 3 deletions bin/node-template/node/src/command.rs
Expand Up @@ -109,8 +109,6 @@ pub fn run() -> sc_cli::Result<()> {
let runner = cli.create_runner(cmd)?;

runner.sync_run(|config| {
let PartialComponents { client, backend, .. } = service::new_partial(&config)?;

// This switch needs to be in the client, since the client decides
// which sub-commands it wants to support.
match cmd {
Expand All @@ -125,18 +123,25 @@ pub fn run() -> sc_cli::Result<()> {

cmd.run::<Block, service::ExecutorDispatch>(config)
},
BenchmarkCmd::Block(cmd) => cmd.run(client),
BenchmarkCmd::Block(cmd) => {
let PartialComponents { client, .. } = service::new_partial(&config)?;
cmd.run(client)
},
BenchmarkCmd::Storage(cmd) => {
let PartialComponents { client, backend, .. } =
service::new_partial(&config)?;
let db = backend.expose_db();
let storage = backend.expose_storage();

cmd.run(config, client, db, storage)
},
BenchmarkCmd::Overhead(cmd) => {
let PartialComponents { client, .. } = service::new_partial(&config)?;
let ext_builder = BenchmarkExtrinsicBuilder::new(client.clone());

cmd.run(config, client, inherent_benchmark_data()?, Arc::new(ext_builder))
},
BenchmarkCmd::Machine(cmd) => cmd.run(&config),
}
})
},
Expand Down
10 changes: 7 additions & 3 deletions bin/node/cli/src/command.rs
Expand Up @@ -99,8 +99,6 @@ pub fn run() -> Result<()> {
let runner = cli.create_runner(cmd)?;

runner.sync_run(|config| {
let PartialComponents { client, backend, .. } = new_partial(&config)?;

// This switch needs to be in the client, since the client decides
// which sub-commands it wants to support.
match cmd {
Expand All @@ -115,18 +113,24 @@ pub fn run() -> Result<()> {

cmd.run::<Block, ExecutorDispatch>(config)
},
BenchmarkCmd::Block(cmd) => cmd.run(client),
BenchmarkCmd::Block(cmd) => {
let PartialComponents { client, .. } = new_partial(&config)?;
cmd.run(client)
},
BenchmarkCmd::Storage(cmd) => {
let PartialComponents { client, backend, .. } = new_partial(&config)?;
let db = backend.expose_db();
let storage = backend.expose_storage();

cmd.run(config, client, db, storage)
},
BenchmarkCmd::Overhead(cmd) => {
let PartialComponents { client, .. } = new_partial(&config)?;
let ext_builder = BenchmarkExtrinsicBuilder::new(client.clone());

cmd.run(config, client, inherent_benchmark_data()?, Arc::new(ext_builder))
},
BenchmarkCmd::Machine(cmd) => cmd.run(&config),
}
})
},
Expand Down
2 changes: 1 addition & 1 deletion bin/node/cli/tests/benchmark_block_works.rs
Expand Up @@ -30,7 +30,7 @@ pub mod common;
async fn benchmark_block_works() {
let base_dir = tempdir().expect("could not create a temp dir");

common::run_node_for_a_while(base_dir.path(), &["--dev"]).await;
common::run_node_for_a_while(base_dir.path(), &["--dev", "--no-hardware-benchmarks"]).await;

// Invoke `benchmark block` with all options to make sure that they are valid.
let status = Command::new(cargo_bin("substrate"))
Expand Down
32 changes: 32 additions & 0 deletions bin/node/cli/tests/benchmark_machine_works.rs
@@ -0,0 +1,32 @@
// 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;

/// Tests that the `benchmark machine` command works for the substrate dev runtime.
#[test]
fn benchmark_machine_works() {
let status = Command::new(cargo_bin("substrate"))
.args(["benchmark", "machine", "--dev"])
.args(["--verify-duration", "0.1"])
.status()
.unwrap();

assert!(status.success());
}
2 changes: 2 additions & 0 deletions client/sysinfo/Cargo.toml
Expand Up @@ -23,4 +23,6 @@ libc = "0.2"
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.79"
sp-core = { version = "6.0.0", path = "../../primitives/core" }
sp-io = { version = "6.0.0", path = "../../primitives/io" }
sp-std = { version = "4.0.0", path = "../../primitives/std" }
sc-telemetry = { version = "4.0.0-dev", path = "../telemetry" }
38 changes: 37 additions & 1 deletion client/sysinfo/src/lib.rs
Expand Up @@ -20,12 +20,16 @@
//! and software telemetry information about the node on which we're running.

use futures::prelude::*;
use std::time::Duration;

mod sysinfo;
#[cfg(target_os = "linux")]
mod sysinfo_linux;

pub use sysinfo::{gather_hwbench, gather_sysinfo};
pub use sysinfo::{
benchmark_cpu, benchmark_disk_random_writes, benchmark_disk_sequential_writes,
benchmark_memory, benchmark_sr25519_verify, gather_hwbench, gather_sysinfo,
};

/// The operating system part of the current target triplet.
pub const TARGET_OS: &str = include_str!(concat!(env!("OUT_DIR"), "/target_os.txt"));
Expand All @@ -49,6 +53,38 @@ pub struct HwBench {
pub disk_random_write_score: Option<u64>,
}

/// Limit the execution time of a benchmark.
pub enum ExecutionLimit {
/// Limit by the maximal duration.
MaxDuration(Duration),

/// Limit by the maximal number of iterations.
MaxIterations(usize),

/// Limit by the maximal duration and maximal number of iterations.
Both { max_iterations: usize, max_duration: Duration },
}

impl ExecutionLimit {
/// Returns the duration limit or `MAX` if none is present.
pub fn max_duration(&self) -> Duration {
match self {
Self::MaxDuration(d) => *d,
Self::Both { max_duration, .. } => *max_duration,
_ => Duration::from_secs(u64::MAX),
}
}

/// Returns the iterations limit or `MAX` if none is present.
pub fn max_iterations(&self) -> usize {
match self {
Self::MaxIterations(d) => *d,
Self::Both { max_iterations, .. } => *max_iterations,
_ => usize::MAX,
}
}
}

/// Prints out the system software/hardware information in the logs.
pub fn print_sysinfo(sysinfo: &sc_telemetry::SysInfo) {
log::info!("💻 Operating system: {}", TARGET_OS);
Expand Down