Module perf_monitor::cpu[][src]

Get cpu usage for current procss and specified thread.

A method named cpu on ThreadStat and ProcessStat can retrive cpu usage of thread and process respectively.

The returning value is unnormalized, that is for mutil-processor machine, the cpu usage will beyond 100%, for example returning 2.8 means 280% cpu usage. If normalized value is what you expected, divide the returning by processor_numbers.

Example

let mut stat = ThreadStat::cur().unwrap();
let _ = (0..1_000_000).into_iter().sum::<u64>();
let usage = stat.cpu().unwrap();
println!("current thread cpu usage is {:.2}%", usage * 100f64);

Bottom Layer Interface

platformthreadprocess
windowsGetThreadTimesGetProcessTimes
linux & android/proc/{pid}/task/{tid}/statclockgettime
macos & iosthread_infogetrusage

Structs

ProcessStat

A struct to monitor process cpu usage

ThreadStat

A struct to monitor thread cpu usage

Functions

cpu_time
cur_thread_id
processor_numbers

logical processor number

Type Definitions

Result

A specialized Result type for I/O operations.