clamp then divide by cores for more accurate statistics

This commit is contained in:
2025-08-28 13:11:48 -07:00
parent 61fe1cc38e
commit 7592709a43
4 changed files with 54 additions and 6 deletions
+5 -4
View File
@@ -454,14 +454,15 @@ pub async fn collect_processes_all(state: &AppState) -> ProcessesPayload {
new_name
};
// Normalize CPU by core count (like Linux implementation)
let raw = p.cpu_usage();
let normalized_cpu = (raw / cpu_count).clamp(0.0, 100.0);
// Convert to percentage of total CPU capacity
// e.g., 100% on 2 cores of 8 core system = 25% total CPU
let raw = p.cpu_usage(); // This is per-core percentage
let total_cpu = raw.clamp(0.0, 100.0) / cpu_count;
proc_cache.reusable_vec.push(ProcessInfo {
pid,
name,
cpu_usage: normalized_cpu,
cpu_usage: total_cpu,
mem_bytes: p.memory(),
});
}