Fix non-linux build of sc-client (#5524)

* procfs is linux only

* also for the import

* fixup non-linux build
This commit is contained in:
Benjamin Kampmann
2020-04-04 19:52:19 +02:00
committed by GitHub
parent 247822bb33
commit d155a9d97d
2 changed files with 13 additions and 17 deletions
+4 -4
View File
@@ -62,12 +62,12 @@ sc-tracing = { version = "2.0.0-alpha.5", path = "../tracing" }
tracing = "0.1.10" tracing = "0.1.10"
parity-util-mem = { version = "0.6.0", default-features = false, features = ["primitive-types"] } 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" netstat2 = "0.8.1"
[target.'cfg(windows)'.dependencies] [target.'cfg(target_os = "linux")'.dependencies]
netstat2 = "0.8.1" procfs = '0.7.8'
[dev-dependencies] [dev-dependencies]
+9 -13
View File
@@ -24,15 +24,12 @@ use sp_transaction_pool::PoolStatus;
use sp_utils::metrics::register_globals; use sp_utils::metrics::register_globals;
#[cfg(any(windows, unix))] #[cfg(any(windows, unix))]
use sysinfo::{ProcessExt, System, SystemExt}; use sysinfo::{self, ProcessExt, SystemExt};
#[cfg(any(unix, windows))] #[cfg(any(unix, windows))]
use netstat2::{TcpState, ProtocolSocketInfo, iterate_sockets_info, AddressFamilyFlags, ProtocolFlags}; use netstat2::{TcpState, ProtocolSocketInfo, iterate_sockets_info, AddressFamilyFlags, ProtocolFlags};
#[cfg(not(unix))] #[cfg(target_os = "linux")]
use sysinfo::get_current_pid;
#[cfg(unix)]
use procfs; use procfs;
struct PrometheusMetrics { struct PrometheusMetrics {
@@ -183,11 +180,11 @@ struct ProcessInfo {
pub struct MetricsService { pub struct MetricsService {
metrics: Option<PrometheusMetrics>, metrics: Option<PrometheusMetrics>,
#[cfg(any(windows, unix))] #[cfg(any(windows, unix))]
system: System, system: sysinfo::System,
pid: Option<i32>, pid: Option<i32>,
} }
#[cfg(unix)] #[cfg(target_os = "linux")]
impl MetricsService { impl MetricsService {
fn inner_new(metrics: Option<PrometheusMetrics>) -> Self { fn inner_new(metrics: Option<PrometheusMetrics>) -> Self {
let process = procfs::process::Process::myself() let process = procfs::process::Process::myself()
@@ -195,7 +192,7 @@ impl MetricsService {
Self { Self {
metrics, metrics,
system: System::new(), system: sysinfo::System::new(),
pid: Some(process.pid), pid: Some(process.pid),
} }
} }
@@ -224,19 +221,18 @@ impl MetricsService {
} }
#[cfg(all(any(unix, windows), not(target_os = "linux")))]
#[cfg(windows)]
impl MetricsService { impl MetricsService {
fn inner_new(metrics: Option<PrometheusMetrics>) -> Self { fn inner_new(metrics: Option<PrometheusMetrics>) -> Self {
Self { Self {
metrics, metrics,
system: System(), system: sysinfo::System::new(),
pid: get_current_pid().ok() pid: sysinfo::get_current_pid().ok()
} }
} }
fn process_info(&mut self) -> ProcessInfo { 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)
} }
} }