#cpu #monitor #usage #system #info

cpu-monitor

A library to get cpu usage over a given duration

2 releases

0.1.1 Sep 2, 2018
0.1.0 Aug 29, 2018

#94 in Operating systems

Download history 83/week @ 2019-12-17 5/week @ 2019-12-24 27/week @ 2019-12-31 20/week @ 2020-01-07 39/week @ 2020-01-14 180/week @ 2020-01-21 84/week @ 2020-01-28 37/week @ 2020-02-04 26/week @ 2020-02-11 29/week @ 2020-02-18 21/week @ 2020-02-25 90/week @ 2020-03-03 24/week @ 2020-03-10 30/week @ 2020-03-17 36/week @ 2020-03-24 173/week @ 2020-03-31

181 downloads per month

MIT/Apache

18KB
396 lines

This library provides methods for getting the percentage of cpu time spent idle, a.k.a. cpu usage.

It follows the structure of std::time, since you can only work with a difference between 2 fixed points in time. Cpu usage and a specific instant is either 0 or 1 (per core), the value of interest is the proportion of cpu cycles spent not idle over a given period.

Examples

extern crate cpu_monitor;

use std::io;
use std::time::Duration;

use cpu_monitor::CpuInstant;

fn main() -> Result<(), io::Error> {
    let start = CpuInstant::now()?;
    std::thread::sleep(Duration::from_millis(100));
    let end = CpuInstant::now()?;
    let duration = end - start;
    println!("cpu: {:.0}%", duration.non_idle() * 100.);
    Ok(())
}

Dependencies

~71KB