Cpu

Struct 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::nothing().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 to get actual value.
s.refresh_cpu_all();

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::nothing().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 to get actual value.
s.refresh_cpu_all();

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::nothing().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::nothing().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::nothing().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::nothing().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>,

Source§

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

Source§

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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 264 bytes