[][src]Function heim_cpu::usage

pub async fn usage() -> Result<CpuUsage>

Returns CPU usage measurement.

Returned CpuUsage struct represents instantaneous CPU usage and does not represent any reasonable value by itself. It is suggested to wait for a while with help of any async timer (for accuracy recommended delay should be at least 100 ms), call this method once again and subtract former CpuUsage from the new one.

Same to any *nix system, calculated CPU usage might exceed 100 % if the process is running multiple threads on different CPU cores.

Example

let measurement_1 = usage().await?;
// Or any other async timer at your choice
futures_timer::Delay::new(Duration::from_millis(100)).await;
let measurement_2 = usage().await?;

println!("CPU usage: {} %", (measurement_2 - measurement_1).get::<ratio::percent>());