Struct mprober_lib::cpu::CPUStat
source · [−]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: u64Implementations
sourceimpl CPUStat
impl CPUStat
sourcepub fn compute_cpu_time(&self) -> CPUTime
pub fn compute_cpu_time(&self) -> CPUTime
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);sourcepub fn compute_cpu_utilization_in_percentage(
&self,
cpu_stat_after_this: &CPUStat
) -> f64
pub fn compute_cpu_utilization_in_percentage(
&self,
cpu_stat_after_this: &CPUStat
) -> f64
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
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more