2 releases

Uses old Rust 2015

0.1.1 Sep 2, 2018
0.1.0 Aug 29, 2018

#567 in Command-line interface

Download history 42/week @ 2024-03-11 70/week @ 2024-03-18 34/week @ 2024-03-25 256/week @ 2024-04-01 23/week @ 2024-04-08 40/week @ 2024-04-15 28/week @ 2024-04-22 16/week @ 2024-04-29 13/week @ 2024-05-06 55/week @ 2024-05-13 35/week @ 2024-05-20 27/week @ 2024-05-27 35/week @ 2024-06-03 24/week @ 2024-06-10 56/week @ 2024-06-17 100/week @ 2024-06-24

217 downloads per month

MIT/Apache

19KB
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

~0–1.1MB