GuillaumeGomez / sysinfo

Cross-platform library to fetch system information
MIT License
2.19k stars 320 forks source link

Global CPU usage is incorrect on Mac M3 Pro #1312

Closed comfortablynick closed 4 months ago

comfortablynick commented 4 months ago

Describe the bug If I print the System struct, the CPU usage basically stays the same no matter what, and doesn't correspond to Activity Monitor or any of the other tools I have looked at. Here is a typical debug print:

System {
    global CPU usage: 8.58352,
    load average: LoadAvg {
        one: 7.2587890625,
        five: 3.60107421875,
        fifteen: 2.802734375,
    },
    total memory: 38654705664,
    free memory: 1125629952,
    total swap: 0,
    free swap: 0,
    nb CPUs: 12,
    nb processes: 781,
}

This number doesn't really change even when building large projects that peg the CPU in Activity Monitor. Am I using this incorrectly?

To Reproduce

let mut sys = sysinfo::System::new_all();
sys.refresh_all();
dbg!(sys);
GuillaumeGomez commented 4 months ago

https://docs.rs/sysinfo/latest/sysinfo/struct.Cpu.html#method.cpu_usage

If you follow what is described in the docs, please re-open this issue.

comfortablynick commented 4 months ago

Thank you, I hadn't caught that. It seems to be a lot closer to another utility when I do this:

let mut sys = System::new_all();
sys.refresh_all();
std::thread::sleep(sysinfo::MINIMUM_CPU_UPDATE_INTERVAL);
sys.refresh_cpu();
dbg!(&sys);