diff --git a/socktop_agent/src/metrics.rs b/socktop_agent/src/metrics.rs index 07a93f1..a1fc744 100644 --- a/socktop_agent/src/metrics.rs +++ b/socktop_agent/src/metrics.rs @@ -4,6 +4,7 @@ use crate::gpu::collect_all_gpus; use crate::state::AppState; use crate::types::{DiskInfo, Metrics, NetworkInfo, ProcessInfo, ProcessesPayload}; use once_cell::sync::OnceCell; +#[cfg(target_os = "linux")] use std::collections::HashMap; #[cfg(target_os = "linux")] use std::fs; @@ -260,12 +261,20 @@ pub async fn collect_processes_top_k(state: &AppState, k: usize) -> ProcessesPay // Compute deltas vs last sample let (last_total, mut last_map) = { - let mut t = state.proc_cpu.lock().await; - let lt = t.last_total; - let lm = std::mem::take(&mut t.last_per_pid); - t.last_total = total_now; - t.last_per_pid = current.clone(); - (lt, lm) + #[cfg(target_os = "linux")] + { + let mut t = state.proc_cpu.lock().await; + let lt = t.last_total; + let lm = std::mem::take(&mut t.last_per_pid); + t.last_total = total_now; + t.last_per_pid = current.clone(); + (lt, lm) + } + #[cfg(not(target_os = "linux"))] + { + let _: u64 = total_now; // silence unused warning + (0u64, HashMap::new()) + } }; // On first run or if total delta is tiny, report zeros diff --git a/socktop_agent/src/state.rs b/socktop_agent/src/state.rs index 6af8960..53edd32 100644 --- a/socktop_agent/src/state.rs +++ b/socktop_agent/src/state.rs @@ -1,5 +1,6 @@ //! Shared agent state: sysinfo handles and hot JSON cache. +#[cfg(target_os = "linux")] use std::collections::HashMap; use std::sync::atomic::AtomicUsize; use std::sync::Arc; @@ -11,6 +12,7 @@ pub type SharedComponents = Arc>; pub type SharedDisks = Arc>; pub type SharedNetworks = Arc>; +#[cfg(target_os = "linux")] #[derive(Default)] pub struct ProcCpuTracker { pub last_total: u64, @@ -25,6 +27,7 @@ pub struct AppState { pub networks: SharedNetworks, // For correct per-process CPU% using /proc deltas (Linux only path uses this tracker) + #[cfg(target_os = "linux")] pub proc_cpu: Arc>, // Connection tracking (to allow future idle sleeps if desired) @@ -45,6 +48,7 @@ impl AppState { components: Arc::new(Mutex::new(components)), disks: Arc::new(Mutex::new(disks)), networks: Arc::new(Mutex::new(networks)), + #[cfg(target_os = "linux")] proc_cpu: Arc::new(Mutex::new(ProcCpuTracker::default())), client_count: Arc::new(AtomicUsize::new(0)), auth_token: std::env::var("SOCKTOP_TOKEN")