fix for windows build error.

This commit is contained in:
jasonwitty 2025-10-06 09:50:38 -07:00
parent e857cfc665
commit f4b54db399

View File

@ -1,5 +1,7 @@
//! Metrics collection using sysinfo for socktop_agent. //! Metrics collection using sysinfo for socktop_agent.
use std::fs;
use crate::gpu::collect_all_gpus; use crate::gpu::collect_all_gpus;
use crate::state::AppState; use crate::state::AppState;
use crate::types::{ use crate::types::{
@ -10,8 +12,6 @@ use once_cell::sync::OnceCell;
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
use std::collections::HashMap; use std::collections::HashMap;
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
use std::fs;
#[cfg(target_os = "linux")]
use std::io; use std::io;
use std::process::Command; use std::process::Command;
use std::sync::Mutex; use std::sync::Mutex;
@ -979,8 +979,9 @@ pub async fn collect_process_metrics(
let start_time = process.start_time(); let start_time = process.start_time();
// Read UID and GID directly from /proc/{pid}/status for accuracy // Read UID and GID directly from /proc/{pid}/status for accuracy
#[cfg(target_os = "linux")]
let (user_id, group_id) = 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 uid = 0u32;
let mut gid = 0u32; let mut gid = 0u32;
@ -1002,15 +1003,19 @@ pub async fn collect_process_metrics(
(uid, gid) (uid, gid)
} else { } else {
// Fallback if /proc read fails (non-Linux or permission issue) // Fallback if /proc read fails (permission issue)
(0, 0) (0, 0)
}; };
#[cfg(not(target_os = "linux"))]
let (user_id, group_id) = (0, 0);
// Read I/O stats directly from /proc/{pid}/io // Read I/O stats directly from /proc/{pid}/io
// Use rchar/wchar to capture ALL I/O including cached reads (like htop/btop do) // 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 // sysinfo's total_read_bytes/total_written_bytes only count actual disk I/O
#[cfg(target_os = "linux")]
let (read_bytes, write_bytes) = 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 rchar = 0u64;
let mut wchar = 0u64; let mut wchar = 0u64;