pub trait CpuExt: Debug {
// Required methods
fn cpu_usage(&self) -> f32;
fn name(&self) -> &str;
fn vendor_id(&self) -> &str;
fn brand(&self) -> &str;
fn frequency(&self) -> u64;
}
Expand description
Contains all the methods of the Cpu
struct.
Required Methods§
sourcefn cpu_usage(&self) -> f32
fn cpu_usage(&self) -> f32
Returns this CPU’s usage.
Note: You’ll need to refresh it at least twice (diff between the first and the second is how CPU usage is computed) at first if you want to have a non-zero value.
use sysinfo::{CpuExt, System, SystemExt};
let s = System::new();
for cpu in s.cpus() {
println!("{}%", cpu.cpu_usage());
}
sourcefn name(&self) -> &str
fn name(&self) -> &str
Returns this CPU’s name.
use sysinfo::{CpuExt, System, SystemExt};
let s = System::new();
for cpu in s.cpus() {
println!("{}", cpu.name());
}
sourcefn vendor_id(&self) -> &str
fn vendor_id(&self) -> &str
Returns the CPU’s vendor id.
use sysinfo::{CpuExt, System, SystemExt};
let s = System::new();
for cpu in s.cpus() {
println!("{}", cpu.vendor_id());
}