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
impl Cpu
sourcepub fn cpu_usage(&self) -> f32
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());
}
sourcepub fn name(&self) -> &str
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());
}
sourcepub fn vendor_id(&self) -> &str
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());
}
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Cpu
impl Send for Cpu
impl Sync for Cpu
impl Unpin for Cpu
impl UnwindSafe for Cpu
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more