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

Commit 15444a6

Browse files
authored
Add hardware benchmark telemetry (Companion for Substrate#11062) (#5206)
* Align to changes in Substrate * Align to the newest changes in substrate * Rename `--disable-hardware-benchmarks` to `--no-hardware-benchmarks` * Fix `polkadot-test-service` compilation * Fix compilation of test parachains
1 parent b069d23 commit 15444a6

11 files changed

Lines changed: 49 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master", o
3232
sc-service = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
3333
polkadot-node-metrics = { path = "../node/metrics" }
3434
sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
35+
sc-sysinfo = { git = "https://github.com/paritytech/substrate", branch = "master" }
3536

3637
# this crate is used only to enable `trie-memory-tracker` feature
3738
# see https://github.com/paritytech/substrate/pull/6745

cli/src/cli.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ pub struct RunCmd {
128128
/// commonly `127.0.0.1:4040`.
129129
#[clap(long)]
130130
pub pyroscope_server: Option<String>,
131+
132+
/// Disable automatic hardware benchmarks.
133+
///
134+
/// By default these benchmarks are automatically ran at startup and measure
135+
/// the CPU speed, the memory bandwidth and the disk speed.
136+
///
137+
/// The results are then printed out in the logs, and also sent as part of
138+
/// telemetry, if telemetry is enabled.
139+
#[clap(long)]
140+
pub no_hardware_benchmarks: bool,
131141
}
132142

133143
#[allow(missing_docs)]

cli/src/command.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,15 @@ where
302302
};
303303

304304
runner.run_node_until_exit(move |config| async move {
305+
let hwbench = if !cli.run.no_hardware_benchmarks {
306+
config.database.path().map(|database_path| {
307+
let _ = std::fs::create_dir_all(&database_path);
308+
sc_sysinfo::gather_hwbench(Some(database_path))
309+
})
310+
} else {
311+
None
312+
};
313+
305314
let role = config.role.clone();
306315

307316
match role {
@@ -315,6 +324,7 @@ where
315324
None,
316325
false,
317326
overseer_gen,
327+
hwbench,
318328
)
319329
.map(|full| full.task_manager)
320330
.map_err(Into::into),

node/service/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ sc-sync-state-rpc = { git = "https://github.com/paritytech/substrate", branch =
2525
sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
2626
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "master" }
2727
sc-offchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
28+
sc-sysinfo = { git = "https://github.com/paritytech/substrate", branch = "master" }
2829
service = { package = "sc-service", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
2930
telemetry = { package = "sc-telemetry", git = "https://github.com/paritytech/substrate", branch = "master" }
3031

node/service/src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ pub fn new_full<RuntimeApi, ExecutorDispatch, OverseerGenerator>(
681681
program_path: Option<std::path::PathBuf>,
682682
overseer_enable_anyways: bool,
683683
overseer_gen: OverseerGenerator,
684+
hwbench: Option<sc_sysinfo::HwBench>,
684685
) -> Result<NewFull<Arc<FullClient<RuntimeApi, ExecutorDispatch>>>, Error>
685686
where
686687
RuntimeApi: ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>
@@ -920,6 +921,19 @@ where
920921
telemetry: telemetry.as_mut(),
921922
})?;
922923

924+
if let Some(hwbench) = hwbench {
925+
sc_sysinfo::print_hwbench(&hwbench);
926+
927+
if let Some(ref mut telemetry) = telemetry {
928+
let telemetry_handle = telemetry.handle();
929+
task_manager.spawn_handle().spawn(
930+
"telemetry_hwbench",
931+
None,
932+
sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench),
933+
);
934+
}
935+
}
936+
923937
let (block_import, link_half, babe_link, beefy_links) = import_setup;
924938

925939
let overseer_client = client.clone();
@@ -1290,6 +1304,7 @@ pub fn build_full(
12901304
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
12911305
overseer_enable_anyways: bool,
12921306
overseer_gen: impl OverseerGen,
1307+
hwbench: Option<sc_sysinfo::HwBench>,
12931308
) -> Result<NewFull<Client>, Error> {
12941309
#[cfg(feature = "rococo-native")]
12951310
if config.chain_spec.is_rococo() ||
@@ -1306,6 +1321,7 @@ pub fn build_full(
13061321
None,
13071322
overseer_enable_anyways,
13081323
overseer_gen,
1324+
hwbench,
13091325
)
13101326
.map(|full| full.with_client(Client::Rococo))
13111327
}
@@ -1322,6 +1338,7 @@ pub fn build_full(
13221338
None,
13231339
overseer_enable_anyways,
13241340
overseer_gen,
1341+
hwbench,
13251342
)
13261343
.map(|full| full.with_client(Client::Kusama))
13271344
}
@@ -1338,6 +1355,7 @@ pub fn build_full(
13381355
None,
13391356
overseer_enable_anyways,
13401357
overseer_gen,
1358+
hwbench,
13411359
)
13421360
.map(|full| full.with_client(Client::Westend))
13431361
}
@@ -1354,6 +1372,7 @@ pub fn build_full(
13541372
None,
13551373
overseer_enable_anyways,
13561374
overseer_gen,
1375+
hwbench,
13571376
)
13581377
.map(|full| full.with_client(Client::Polkadot))
13591378
}

node/test/service/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub fn new_full(
9797
worker_program_path,
9898
false,
9999
polkadot_service::RealOverseerGen,
100+
None,
100101
)
101102
}
102103

parachain/test-parachains/adder/collator/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ fn main() -> Result<()> {
7070
None,
7171
false,
7272
polkadot_service::RealOverseerGen,
73+
None,
7374
)
7475
.map_err(|e| e.to_string())?;
7576
let mut overseer_handle = full_node

parachain/test-parachains/undying/collator/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ fn main() -> Result<()> {
7070
None,
7171
false,
7272
polkadot_service::RealOverseerGen,
73+
None,
7374
)
7475
.map_err(|e| e.to_string())?;
7576
let mut overseer_handle = full_node

tests/purge_chain_works.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ async fn purge_chain_rocksdb_works() {
3535
.arg(tmpdir.path())
3636
.arg("--port")
3737
.arg("33034")
38+
.arg("--no-hardware-benchmarks")
3839
.spawn()
3940
.unwrap();
4041

@@ -78,6 +79,7 @@ async fn purge_chain_paritydb_works() {
7879
.arg(tmpdir.path())
7980
.arg("--database")
8081
.arg("paritydb-experimental")
82+
.arg("--no-hardware-benchmarks")
8183
.spawn()
8284
.unwrap();
8385

0 commit comments

Comments
 (0)