Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
dccce70
Add new hardware and software metrics
koute Mar 18, 2022
99633f9
Move sysinfo tests into `mod tests`
koute Mar 23, 2022
55c7358
Correct a typo in a comment
koute Mar 23, 2022
909df21
Remove unnecessary `nix` dependency
koute Mar 23, 2022
706e4d3
Fix the version tests
koute Mar 23, 2022
c1e409f
Add a `--disable-hardware-benchmarks` CLI argument
koute Mar 24, 2022
a05159a
Disable hardware benchmarks in the integration tests
koute Mar 25, 2022
fff4573
Remove unused import
koute Mar 25, 2022
3d15f0e
Fix benchmarks compilation
koute Mar 25, 2022
a8c71c1
Merge remote-tracking branch 'origin/master' into master_hwswinfo
koute Mar 25, 2022
d215b39
Move code to a new `sc-sysinfo` crate
koute Mar 28, 2022
c1da1fa
Correct `impl_version` comment
koute Mar 28, 2022
b98bcfa
Move `--disable-hardware-benchmarks` to the chain-specific bin crate
koute Mar 28, 2022
0d25408
Move printing out of hardware bench results to `sc-sysinfo`
koute Mar 28, 2022
46c9de2
Move hardware benchmarks to a separate messages; trigger them manually
koute Mar 29, 2022
56a1e3a
Rename some of the fields in the `HwBench` struct
koute Mar 31, 2022
457b4da
Revert changes to the telemetry crate; manually send hwbench messages
koute Apr 4, 2022
bb26cfa
Move sysinfo logs into the sysinfo crate
koute Apr 4, 2022
77f9c5f
Move the `TARGET_OS_*` constants into the sysinfo crate
koute Apr 4, 2022
73b230a
Minor cleanups
koute Apr 5, 2022
c3214e5
Move the `HwBench` struct to the sysinfo crate
koute Apr 5, 2022
b6d78a0
Derive `Clone` for `HwBench`
koute Apr 5, 2022
19f43ab
Fix broken telemetry connection notification stream
koute Apr 5, 2022
15e5f9e
Prevent the telemetry connection notifiers from leaking if they're di…
koute Apr 5, 2022
e5f210f
Turn the telemetry notification failure log into a debug log
koute Apr 6, 2022
0cafbf8
Rename `--disable-hardware-benchmarks` to `--no-hardware-benchmarks`
koute Apr 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions client/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ futures = "0.3.19"
jsonrpc-pubsub = "18.0"
jsonrpc-core = "18.0"
rand = "0.7.3"
rand_pcg = "0.2.1"
parking_lot = "0.12.0"
log = "0.4.11"
futures-timer = "3.0.1"
Expand Down Expand Up @@ -81,6 +82,9 @@ async-trait = "0.1.50"
tokio = { version = "1.15", features = ["time", "rt-multi-thread", "parking_lot"] }
tempfile = "3.1.0"
directories = "4.0.1"
regex = "1"
libc = "0.2"
nix = "0.23"

[dev-dependencies]
substrate-test-runtime-client = { version = "2.0.0", path = "../../test-utils/runtime/client" }
Expand Down
31 changes: 31 additions & 0 deletions client/service/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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/>.

fn main() {
let out_dir = std::env::var("OUT_DIR").expect("OUT_DIR is always set in build scripts; qed");
let out_dir = std::path::PathBuf::from(out_dir);
let target_os = std::env::var("CARGO_CFG_TARGET_OS")
.expect("CARGO_CFG_TARGET_OS is always set in build scripts; qed");
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH")
.expect("CARGO_CFG_TARGET_ARCH is always set in build scripts; qed");
let target_env = std::env::var("CARGO_CFG_TARGET_ENV")
.expect("CARGO_CFG_TARGET_ENV is always set in build scripts; qed");
std::fs::write(out_dir.join("target_os.txt"), target_os).unwrap();
std::fs::write(out_dir.join("target_arch.txt"), target_arch).unwrap();
std::fs::write(out_dir.join("target_env.txt"), target_env).unwrap();
}
71 changes: 70 additions & 1 deletion client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ use sp_runtime::{
};
use std::{str::FromStr, sync::Arc, time::SystemTime};

const TARGET_OS: &str = include_str!(concat!(env!("OUT_DIR"), "/target_os.txt"));
const TARGET_ARCH: &str = include_str!(concat!(env!("OUT_DIR"), "/target_arch.txt"));
const TARGET_ENV: &str = include_str!(concat!(env!("OUT_DIR"), "/target_env.txt"));

/// A utility trait for building an RPC extension given a `DenyUnsafe` instance.
/// This is useful since at service definition time we don't know whether the
/// specific interface where the RPC extension will be exposed is safe or not.
Expand Down Expand Up @@ -487,8 +491,66 @@ where
)
.map_err(|e| Error::Application(Box::new(e)))?;

let database_path = match config.database {
sc_client_db::DatabaseSource::Auto { ref paritydb_path, ref rocksdb_path, .. } =>
if rocksdb_path.exists() {
Some(rocksdb_path.as_path())
} else {
Some(paritydb_path.as_path())
},
sc_client_db::DatabaseSource::RocksDb { ref path, .. } |
sc_client_db::DatabaseSource::ParityDb { ref path, .. } => Some(path.as_path()),
sc_client_db::DatabaseSource::Custom { .. } => None,
};

let sysinfo = crate::sysinfo::gather_sysinfo();
let hwbench = crate::sysinfo::gather_hwbench(database_path);

info!("💻 Operating system: {}", TARGET_OS);
info!("💻 CPU architecture: {}", TARGET_ARCH);
if !TARGET_ENV.is_empty() {
info!("💻 Target environment: {}", TARGET_ENV);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just looking at these log lines, I would get the impression that the properties of the running system are listed, not those of the build target. I know it is really an edge-case, but foreign ELF formats can be loaded and run emulated on a different system. Are we okay with ignoring those fringe usages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... well, that is a good point; I don't think we have to care about this in general though since those should mostly be really fringe cases, and detecting this will most likely not be easy. (That said, if anyone has any counterpoints here or any good ideas how to handle this in a reasonable way I'm all ears.)

I guess the most likely cases here would be either someone running the Linux binary on a BSD system, or someone running an amd64 binary on an M1 Mac (but we don't provide binaries for macOS, so they'd have to compile it themselves, and if they're compiling it themselves then why not compile a native aarch64 binary in the first place and run that?).

if let Some(ref cpu) = sysinfo.cpu {
info!("💻 CPU: {}", cpu);
}
if let Some(core_count) = sysinfo.core_count {
info!("💻 CPU cores: {}", core_count);
}
if let Some(memory) = sysinfo.memory {
info!("💻 Memory: {}MB", memory / (1024 * 1024));
}
if let Some(ref linux_kernel) = sysinfo.linux_kernel {
info!("💻 Kernel: {}", linux_kernel);
}
if let Some(ref linux_distro) = sysinfo.linux_distro {
info!("💻 Linux distribution: {}", linux_distro);
}
if let Some(is_virtual_machine) = sysinfo.is_virtual_machine {
info!("💻 Virtual machine: {}", if is_virtual_machine { "yes" } else { "no" });
}

info!("🏁 CPU score: {}MB/s", hwbench.cpu_score);
info!("🏁 Memory score: {}MB/s", hwbench.memory_score);

if let Some(score) = hwbench.disk_sequential_write_score {
info!("🏁 Disk score (seq. writes): {}MB/s", score);
}
if let Some(score) = hwbench.disk_random_write_score {
info!("🏁 Disk score (rand. writes): {}MB/s", score);
}

let telemetry = telemetry
.map(|telemetry| init_telemetry(&mut config, network.clone(), client.clone(), telemetry))
.map(|telemetry| {
init_telemetry(
&mut config,
network.clone(),
client.clone(),
telemetry,
Some(sysinfo),
Some(hwbench),
)
})
.transpose()?;

info!("📦 Highest known block at #{}", chain_info.best_number);
Expand Down Expand Up @@ -609,12 +671,17 @@ fn init_telemetry<TBl: BlockT, TCl: BlockBackend<TBl>>(
network: Arc<NetworkService<TBl, <TBl as BlockT>::Hash>>,
client: Arc<TCl>,
telemetry: &mut Telemetry,
sysinfo: Option<sc_telemetry::SysInfo>,
hwbench: Option<sc_telemetry::HwBench>,
) -> sc_telemetry::Result<TelemetryHandle> {
let genesis_hash = client.block_hash(Zero::zero()).ok().flatten().unwrap_or_default();
let connection_message = ConnectionMessage {
name: config.network.node_name.to_owned(),
implementation: config.impl_name.to_owned(),
version: config.impl_version.to_owned(),
target_os: TARGET_OS.into(),
target_arch: TARGET_ARCH.into(),
target_env: TARGET_ENV.into(),
config: String::new(),
chain: config.chain_spec.name().to_owned(),
genesis_hash: format!("{:?}", genesis_hash),
Expand All @@ -625,6 +692,8 @@ fn init_telemetry<TBl: BlockT, TCl: BlockBackend<TBl>>(
.unwrap_or(0)
.to_string(),
network_id: network.local_peer_id().to_base58(),
sysinfo,
hwbench,
};

telemetry.start_telemetry(connection_message)?;
Expand Down
4 changes: 4 additions & 0 deletions client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ mod client;
mod metrics;
mod task_manager;

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

use std::{collections::HashMap, io, net::SocketAddr, pin::Pin};

use codec::{Decode, Encode};
Expand Down
Loading