Struct sysinfo::Cpu

source ·
pub struct Cpu { /* private fields */ }
Expand description

Contains all the methods of the Cpu struct.

use sysinfo::{System, RefreshKind, CpuRefreshKind};

let mut s = System::new_with_specifics(
    RefreshKind::new().with_cpu(CpuRefreshKind::everything()),
);

// Wait a bit because CPU usage is based on diff.
std::thread::sleep(sysinfo::MINIMUM_CPU_UPDATE_INTERVAL);
// Refresh CPUs again.
s.refresh_cpu();

for cpu in s.cpus() {
    println!("{}%", cpu.cpu_usage());
}

Implementations§

source§

impl Cpu

source

pub 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::{System, RefreshKind, CpuRefreshKind};

let mut s = System::new_with_specifics(
    RefreshKind::new().with_cpu(CpuRefreshKind::everything()),
);

// Wait a bit because CPU usage is based on diff.
std::thread::sleep(sysinfo::MINIMUM_CPU_UPDATE_INTERVAL);
// Refresh CPUs again.
s.refresh_cpu();

for cpu in s.cpus() {
    println!("{}%", cpu.cpu_usage());
}
source

pub fn name(&self) -> &str

Returns this CPU’s name.

use sysinfo::{System, RefreshKind, CpuRefreshKind};

let s = System::new_with_specifics(
    RefreshKind::new().with_cpu(CpuRefreshKind::everything()),
);
for cpu in s.cpus() {
    println!("{}", cpu.name());
}
source

pub fn vendor_id(&self) -> &str

Returns the CPU’s vendor id.

use sysinfo::{System, RefreshKind, CpuRefreshKind};

let s = System::new_with_specifics(
    RefreshKind::new().with_cpu(CpuRefreshKind::everything()),
);
for cpu in s.cpus() {
    println!("{}", cpu.vendor_id());
}
source

pub fn brand(&self) -> &str

Returns the CPU’s brand.

use sysinfo::{System, RefreshKind, CpuRefreshKind};

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

pub fn frequency(&self) -> u64

Returns the CPU’s frequency.

use sysinfo::{System, RefreshKind, CpuRefreshKind};

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

Trait Implementations§

source§

impl Debug for Cpu

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Cpu

§

impl RefUnwindSafe for Cpu

§

impl Send for Cpu

§

impl Sync for Cpu

§

impl Unpin for Cpu

§

impl UnwindSafe for Cpu

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.