Trait sysinfo::CpuExt

source ·
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§

source

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());
}
source

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());
}
source

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());
}
source

fn brand(&self) -> &str

Returns the CPU’s brand.

use sysinfo::{CpuExt, System, SystemExt};

let s = System::new();
for cpu in s.cpus() {
    println!("{}", cpu.brand());
}
source

fn frequency(&self) -> u64

Returns the CPU’s frequency.

use sysinfo::{CpuExt, System, SystemExt};

let s = System::new();
for cpu in s.cpus() {
    println!("{}", cpu.frequency());
}

Implementors§