pub struct ProcessTimeStat {
    pub utime: u32,
    pub stime: u32,
}

Fields

utime: u32stime: u32

Implementations

Compute CPU utilization in percentage between two ProcessTimeStat 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;
use mprober_lib::process;

let pre_average_cpu_stat = cpu::get_average_cpu_stat().unwrap();
let pre_process_time_stat = process::get_process_time_stat(1).unwrap();

sleep(Duration::from_millis(100));

let average_cpu_stat = cpu::get_average_cpu_stat().unwrap();
let process_time_stat = process::get_process_time_stat(1).unwrap();

let total_cpu_time_f64 = {
    let pre_average_cpu_time = pre_average_cpu_stat.compute_cpu_time();
    let average_cpu_time = average_cpu_stat.compute_cpu_time();

    (average_cpu_time.get_total_time() - pre_average_cpu_time.get_total_time()) as f64
};

let cpu_percentage = pre_process_time_stat
    .compute_cpu_utilization_in_percentage(&process_time_stat, total_cpu_time_f64);

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
Converts to this type from the input type.

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
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.