Add host info to weight templates (#11583)

* Add host info to weight templates

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* cargo run --quiet --profile=production  --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark pallet --chain=dev --steps=50 --repeat=20 --pallet=frame_system --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/system/src/weights.rs --template=./.maintain/frame-weight-template.hbs

Co-authored-by: Parity Bot <admin@parity.io>
This commit is contained in:
Oliver Tale-Yazdi
2022-06-03 21:46:14 +02:00
committed by GitHub
parent 038e52f5e0
commit a2afadb123
14 changed files with 103 additions and 13 deletions
@@ -35,7 +35,7 @@ use crate::{
bench::{Benchmark, BenchmarkParams, BenchmarkType},
template::TemplateData,
},
shared::WeightParams,
shared::{HostInfoParams, WeightParams},
};
/// Benchmark the execution overhead per-block and per-extrinsic.
@@ -64,6 +64,10 @@ pub struct OverheadParams {
#[allow(missing_docs)]
#[clap(flatten)]
pub bench: BenchmarkParams,
#[allow(missing_docs)]
#[clap(flatten)]
pub hostinfo: HostInfoParams,
}
/// Used by the benchmark to build signed extrinsics.
@@ -47,6 +47,10 @@ pub(crate) struct TemplateData {
version: String,
/// Date that the template was filled out.
date: String,
/// Hostname of the machine that executed the benchmarks.
hostname: String,
/// CPU name of the machine that executed the benchmarks.
cpuname: String,
/// Command line arguments that were passed to the CLI.
args: Vec<String>,
/// Params of the executed command.
@@ -73,6 +77,8 @@ impl TemplateData {
runtime_name: cfg.chain_spec.name().into(),
version: VERSION.into(),
date: chrono::Utc::now().format("%Y-%m-%d (Y/M/D)").to_string(),
hostname: params.hostinfo.hostname(),
cpuname: params.hostinfo.cpuname(),
args: env::args().collect::<Vec<String>>(),
params: params.clone(),
stats: stats.clone(),
@@ -17,6 +17,7 @@
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}}
//! DATE: {{date}}
//! HOSTNAME: `{{hostname}}`, CPU: `{{cpuname}}`
//!
//! SHORT-NAME: `{{short_name}}`, LONG-NAME: `{{long_name}}`, RUNTIME: `{{runtime_name}}`
//! WARMUPS: `{{params.bench.warmup}}`, REPEAT: `{{params.bench.repeat}}`
@@ -18,6 +18,7 @@
mod command;
mod writer;
use crate::shared::HostInfoParams;
use sc_cli::{
ExecutionStrategy, WasmExecutionMethod, WasmtimeInstantiationStrategy,
DEFAULT_WASMTIME_INSTANTIATION_STRATEGY, DEFAULT_WASM_EXECUTION_METHOD,
@@ -91,6 +92,10 @@ pub struct PalletCmd {
#[clap(long)]
pub template: Option<PathBuf>,
#[allow(missing_docs)]
#[clap(flatten)]
pub hostinfo_params: HostInfoParams,
/// Which analysis function to use when outputting benchmarks:
/// * min-squares (default)
/// * median-slopes
@@ -3,6 +3,7 @@
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}}
//! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: {{cmd.repeat}}, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}`
//! HOSTNAME: `{{hostname}}`, CPU: `{{cpuname}}`
//! EXECUTION: {{cmd.execution}}, WASM-EXECUTION: {{cmd.wasm_execution}}, CHAIN: {{cmd.chain}}, DB CACHE: {{cmd.db_cache}}
// Executed Command:
@@ -43,6 +43,8 @@ const TEMPLATE: &str = include_str!("./template.hbs");
struct TemplateData {
args: Vec<String>,
date: String,
hostname: String,
cpuname: String,
version: String,
pallet: String,
instance: String,
@@ -322,6 +324,8 @@ pub fn write_results(
let hbs_data = TemplateData {
args: args.clone(),
date: date.clone(),
hostname: cmd.hostinfo_params.hostname(),
cpuname: cmd.hostinfo_params.cpuname(),
version: VERSION.to_string(),
pallet: pallet.to_string(),
instance: instance.to_string(),
@@ -25,7 +25,10 @@ pub use record::BenchRecord;
pub use stats::{StatSelect, Stats};
pub use weight_params::WeightParams;
use clap::Args;
use rand::prelude::*;
use sc_sysinfo::gather_sysinfo;
use serde::Serialize;
/// A Handlebars helper to add an underscore after every 3rd character,
/// i.e. a separator for large numbers.
@@ -89,3 +92,43 @@ pub fn check_build_profile() -> Result<(), String> {
Ok(())
}
}
/// Parameters to configure how the host info will be determined.
#[derive(Debug, Default, Serialize, Clone, PartialEq, Args)]
#[clap(rename_all = "kebab-case")]
pub struct HostInfoParams {
/// Manually override the hostname to use.
#[clap(long)]
pub hostname_override: Option<String>,
/// Specify a fallback hostname if no-one could be detected automatically.
///
/// Note: This only exists to make the `hostname` function infallible.
#[clap(long, default_value = "<UNKNOWN>")]
pub hostname_fallback: String,
/// Specify a fallback CPU name if no-one could be detected automatically.
///
/// Note: This only exists to make the `cpuname` function infallible.
#[clap(long, default_value = "<UNKNOWN>")]
pub cpuname_fallback: String,
}
impl HostInfoParams {
/// Returns the hostname of the machine.
///
/// Can be used to track on which machine a benchmark was run.
pub fn hostname(&self) -> String {
self.hostname_override
.clone()
.or(gethostname::gethostname().into_string().ok())
.unwrap_or(self.hostname_fallback.clone())
}
/// Returns the CPU name of the current machine.
///
/// Can be used to track on which machine a benchmark was run.
pub fn cpuname(&self) -> String {
gather_sysinfo().cpu.unwrap_or(self.cpuname_fallback.clone())
}
}
@@ -34,7 +34,7 @@ use sp_runtime::generic::BlockId;
use std::{fmt::Debug, path::PathBuf, sync::Arc};
use super::template::TemplateData;
use crate::shared::{new_rng, WeightParams};
use crate::shared::{new_rng, HostInfoParams, WeightParams};
/// Benchmark the storage speed of a chain snapshot.
#[derive(Debug, Parser)]
@@ -63,6 +63,10 @@ pub struct StorageParams {
#[clap(flatten)]
pub weight_params: WeightParams,
#[allow(missing_docs)]
#[clap(flatten)]
pub hostinfo: HostInfoParams,
/// Skip the `read` benchmark.
#[clap(long)]
pub skip_read: bool,
@@ -41,6 +41,10 @@ pub(crate) struct TemplateData {
version: String,
/// Date that the template was filled out.
date: String,
/// Hostname of the machine that executed the benchmarks.
hostname: String,
/// CPU name of the machine that executed the benchmarks.
cpuname: String,
/// Command line arguments that were passed to the CLI.
args: Vec<String>,
/// Storage params of the executed command.
@@ -65,6 +69,8 @@ impl TemplateData {
runtime_name: cfg.chain_spec.name().into(),
version: VERSION.into(),
date: chrono::Utc::now().format("%Y-%m-%d (Y/M/D)").to_string(),
hostname: params.hostinfo.hostname(),
cpuname: params.hostinfo.cpuname(),
args: env::args().collect::<Vec<String>>(),
params: params.clone(),
..Default::default()
@@ -17,6 +17,7 @@
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}}
//! DATE: {{date}}
//! HOSTNAME: `{{hostname}}`, CPU: `{{cpuname}}`
//!
//! DATABASE: `{{db_name}}`, RUNTIME: `{{runtime_name}}`
//! BLOCK-NUM: `{{block_number}}`