2 releases

Uses old Rust 2015

0.1.1 Sep 2, 2018
0.1.0 Aug 29, 2018

#601 in Command-line interface

Download history 52/week @ 2024-07-22 43/week @ 2024-07-29 51/week @ 2024-08-05 20/week @ 2024-08-12 31/week @ 2024-08-19 49/week @ 2024-08-26 43/week @ 2024-09-02 111/week @ 2024-09-09 89/week @ 2024-09-16 184/week @ 2024-09-23 92/week @ 2024-09-30 175/week @ 2024-10-07 140/week @ 2024-10-14 55/week @ 2024-10-21 66/week @ 2024-10-28 74/week @ 2024-11-04

341 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–1MB