interplane.Get Omega
Read in your language

aien-sovereign-core

Autonomous sovereign intelligence engine and runtime core for NVIDIA DGX Spark

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core / crates / spark-supervisor / src / proc_telemetry.rs

45 lines · 1160 bytes Raw Blame History
1use std::fs;
2use std::path::Path;
3
4#[derive(Debug, Clone, Default)]
5pub struct ProcessStats {
6 pub pid: u32,
7 pub is_alive: bool,
8 pub rss_bytes: u64,
9 pub cmdline: String,
10}
11
12pub fn get_process_stats(pid: u32) -> ProcessStats {
13 let proc_dir = format!("/proc/{}", pid);
14 let path = Path::new(&proc_dir);
15 if !path.exists() {
16 return ProcessStats {
17 pid,
18 is_alive: false,
19 rss_bytes: 0,
20 cmdline: String::new(),
21 };
22 }
23
24 let cmdline = fs::read_to_string(path.join("cmdline"))
25 .map(|s| s.replace('\0', " ").trim().to_string())
26 .unwrap_or_default();
27
28 let mut rss_bytes = 0;
29 if let Ok(statm) = fs::read_to_string(path.join("statm")) {
30 let parts: Vec<&str> = statm.split_whitespace().collect();
31 if parts.len() >= 2 {
32 if let Ok(resident_pages) = parts[1].parse::<u64>() {
33 // Typical page size is 4096 bytes on Linux arm64/x86_64
34 rss_bytes = resident_pages * 4096;
35 }
36 }
37 }
38
39 ProcessStats {
40 pid,
41 is_alive: true,
42 rss_bytes,
43 cmdline,
44 }
45}