Struct mprober_lib::cpu::CPUStat[][src]

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

impl CPUStat[src]

pub fn compute_cpu_time(&self) -> CPUTime[src]

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);

pub fn compute_cpu_utilization_in_percentage(
    &self,
    cpu_stat_after_this: &CPUStat
) -> f64
[src]

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

impl Clone for CPUStat[src]

impl Debug for CPUStat[src]

impl Default for CPUStat[src]

Auto Trait Implementations

impl RefUnwindSafe for CPUStat

impl Send for CPUStat

impl Sync for CPUStat

impl Unpin for CPUStat

impl UnwindSafe for CPUStat

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.