pub struct CPUStat {
    pub user: u64,
    pub nice: u64,
    pub system: u64,
    pub idle: u64,
    pub iowait: u64,
    pub irq: u64,
    pub softirq: u64,
    pub steal: u64,
    pub guest: u64,
    pub guest_nice: u64,
}

Fields

user: u64nice: u64system: u64idle: u64iowait: u64irq: u64softirq: u64steal: u64guest: u64guest_nice: u64

Implementations

Add all idle time and non-idle time respectively.

extern crate mprober_lib;

use mprober_lib::cpu;

let average_cpu_stat = cpu::get_average_cpu_stat().unwrap();
let cpu_time = average_cpu_stat.compute_cpu_time();

println!("{:#?}", cpu_time);

Compute CPU utilization in percentage between two CPUStat instances at different time. If it returns 1.0, means 100%.

extern crate mprober_lib;

use std::thread::sleep;
use std::time::Duration;

use mprober_lib::cpu;

let pre_average_cpu_stat = cpu::get_average_cpu_stat().unwrap();

sleep(Duration::from_millis(100));

let average_cpu_stat = cpu::get_average_cpu_stat().unwrap();

let cpu_percentage =
    pre_average_cpu_stat.compute_cpu_utilization_in_percentage(&average_cpu_stat);

println!("{:.2}%", cpu_percentage * 100.0);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.