From f4b54db399604f73095025de6e7eca8892634c7a Mon Sep 17 00:00:00 2001 From: jasonwitty Date: Mon, 6 Oct 2025 09:50:38 -0700 Subject: [PATCH] fix for windows build error. --- socktop_agent/src/metrics.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/socktop_agent/src/metrics.rs b/socktop_agent/src/metrics.rs index 27e5b99..a4bd9e8 100644 --- a/socktop_agent/src/metrics.rs +++ b/socktop_agent/src/metrics.rs @@ -1,5 +1,7 @@ //! Metrics collection using sysinfo for socktop_agent. +use std::fs; + use crate::gpu::collect_all_gpus; use crate::state::AppState; use crate::types::{ @@ -10,8 +12,6 @@ use once_cell::sync::OnceCell; #[cfg(target_os = "linux")] use std::collections::HashMap; #[cfg(target_os = "linux")] -use std::fs; -#[cfg(target_os = "linux")] use std::io; use std::process::Command; use std::sync::Mutex; @@ -979,8 +979,9 @@ pub async fn collect_process_metrics( let start_time = process.start_time(); // Read UID and GID directly from /proc/{pid}/status for accuracy + #[cfg(target_os = "linux")] let (user_id, group_id) = - if let Ok(status_content) = fs::read_to_string(format!("/proc/{pid}/status")) { + if let Ok(status_content) = std::fs::read_to_string(format!("/proc/{pid}/status")) { let mut uid = 0u32; let mut gid = 0u32; @@ -1002,15 +1003,19 @@ pub async fn collect_process_metrics( (uid, gid) } else { - // Fallback if /proc read fails (non-Linux or permission issue) + // Fallback if /proc read fails (permission issue) (0, 0) }; + + #[cfg(not(target_os = "linux"))] + let (user_id, group_id) = (0, 0); // Read I/O stats directly from /proc/{pid}/io // Use rchar/wchar to capture ALL I/O including cached reads (like htop/btop do) // sysinfo's total_read_bytes/total_written_bytes only count actual disk I/O + #[cfg(target_os = "linux")] let (read_bytes, write_bytes) = - if let Ok(io_content) = fs::read_to_string(format!("/proc/{pid}/io")) { + if let Ok(io_content) = std::fs::read_to_string(format!("/proc/{pid}/io")) { let mut rchar = 0u64; let mut wchar = 0u64;