From d155a9d97ddce0a3056ccbe2cdd240fab7e21872 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Sat, 4 Apr 2020 19:52:19 +0200 Subject: [PATCH] Fix non-linux build of sc-client (#5524) * procfs is linux only * also for the import * fixup non-linux build --- substrate/client/service/Cargo.toml | 8 ++++---- substrate/client/service/src/metrics.rs | 22 +++++++++------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/substrate/client/service/Cargo.toml b/substrate/client/service/Cargo.toml index 7dc987b303..530142c745 100644 --- a/substrate/client/service/Cargo.toml +++ b/substrate/client/service/Cargo.toml @@ -62,12 +62,12 @@ sc-tracing = { version = "2.0.0-alpha.5", path = "../tracing" } tracing = "0.1.10" parity-util-mem = { version = "0.6.0", default-features = false, features = ["primitive-types"] } -[target.'cfg(unix)'.dependencies] -procfs = '0.7.8' + +[target.'cfg(any(unix, windows))'.dependencies] netstat2 = "0.8.1" -[target.'cfg(windows)'.dependencies] -netstat2 = "0.8.1" +[target.'cfg(target_os = "linux")'.dependencies] +procfs = '0.7.8' [dev-dependencies] diff --git a/substrate/client/service/src/metrics.rs b/substrate/client/service/src/metrics.rs index 931d59b5f1..740a795eda 100644 --- a/substrate/client/service/src/metrics.rs +++ b/substrate/client/service/src/metrics.rs @@ -24,15 +24,12 @@ use sp_transaction_pool::PoolStatus; use sp_utils::metrics::register_globals; #[cfg(any(windows, unix))] -use sysinfo::{ProcessExt, System, SystemExt}; +use sysinfo::{self, ProcessExt, SystemExt}; #[cfg(any(unix, windows))] use netstat2::{TcpState, ProtocolSocketInfo, iterate_sockets_info, AddressFamilyFlags, ProtocolFlags}; -#[cfg(not(unix))] -use sysinfo::get_current_pid; - -#[cfg(unix)] +#[cfg(target_os = "linux")] use procfs; struct PrometheusMetrics { @@ -183,11 +180,11 @@ struct ProcessInfo { pub struct MetricsService { metrics: Option, #[cfg(any(windows, unix))] - system: System, + system: sysinfo::System, pid: Option, } -#[cfg(unix)] +#[cfg(target_os = "linux")] impl MetricsService { fn inner_new(metrics: Option) -> Self { let process = procfs::process::Process::myself() @@ -195,7 +192,7 @@ impl MetricsService { Self { metrics, - system: System::new(), + system: sysinfo::System::new(), pid: Some(process.pid), } } @@ -224,19 +221,18 @@ impl MetricsService { } - -#[cfg(windows)] +#[cfg(all(any(unix, windows), not(target_os = "linux")))] impl MetricsService { fn inner_new(metrics: Option) -> Self { Self { metrics, - system: System(), - pid: get_current_pid().ok() + system: sysinfo::System::new(), + pid: sysinfo::get_current_pid().ok() } } fn process_info(&mut self) -> ProcessInfo { - self.pid.map(|pid| self._process_info_for(pid)).or_else(ProcessInfo::default) + self.pid.map(|pid| self._process_info_for(&pid)).unwrap_or_else(ProcessInfo::default) } }