diff --git a/src/c_interface.rs b/src/c_interface.rs index f39e5bedd..26bb84e1c 100644 --- a/src/c_interface.rs +++ b/src/c_interface.rs @@ -58,7 +58,7 @@ pub extern "C" fn sysinfo_refresh_memory(system: CSystem) { } } -/// Equivalent of [`System::refresh_cpu()`][crate::System#method.refresh_cpu]. +/// Equivalent of [`System::refresh_cpu_usage()`][crate::System#method.refresh_cpu_usage]. #[no_mangle] pub extern "C" fn sysinfo_refresh_cpu(system: CSystem) { assert!(!system.is_null()); @@ -66,7 +66,7 @@ pub extern "C" fn sysinfo_refresh_cpu(system: CSystem) { let mut system: Box = Box::from_raw(system as *mut System); { let system: &mut System = system.borrow_mut(); - system.refresh_cpu(); + system.refresh_cpu_usage(); } Box::into_raw(system); } diff --git a/src/freebsd/system.rs b/src/freebsd/system.rs index bccb6ad1b..51b4dc0fc 100644 --- a/src/freebsd/system.rs +++ b/src/freebsd/system.rs @@ -118,7 +118,7 @@ impl SystemExt for System { fn refresh_components_list(&mut self) { if self.cpus.cpus.is_empty() { - self.refresh_cpu(); + self.refresh_cpu_usage(); } self.components = unsafe { super::component::get_components(self.cpus.cpus.len()) }; } diff --git a/src/lib.rs b/src/lib.rs index 54b9f0bf9..0e984883d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -290,7 +290,7 @@ mod test { } let mut s = System::new(); for _ in 0..10 { - s.refresh_cpu(); + s.refresh_cpu_usage(); // Wait a bit to update CPU usage values std::thread::sleep(System::MINIMUM_CPU_UPDATE_INTERVAL); if s.cpus().iter().any(|c| c.cpu_usage() > 0.0) { @@ -444,7 +444,7 @@ mod test { .physical_core_count() .expect("failed to get number of physical cores"); - s.refresh_cpu(); + s.refresh_cpu_usage(); // The cpus shouldn't be empty anymore. assert!(!s.cpus().is_empty()); @@ -487,7 +487,7 @@ mod test { for proc_ in s.cpus() { assert_eq!(proc_.frequency(), 0); } - s.refresh_cpu(); + s.refresh_cpu_usage(); for proc_ in s.cpus() { assert_eq!(proc_.frequency(), 0); } diff --git a/src/traits.rs b/src/traits.rs index c41280df3..6cc010904 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -746,7 +746,7 @@ pub trait SystemExt: Sized + Debug + Default + Send + Sync { /// ``` fn refresh_system(&mut self) { self.refresh_memory(); - self.refresh_cpu(); + self.refresh_cpu_usage(); self.refresh_components(); } @@ -760,7 +760,7 @@ pub trait SystemExt: Sized + Debug + Default + Send + Sync { /// ``` fn refresh_memory(&mut self); - /// Refreshes CPUs information. + /// Refreshes CPUs usage. /// /// ⚠️ Please note that the result will very likely be inaccurate at the first call. /// You need to call this method at least twice (with a bit of time between each call, like @@ -774,10 +774,45 @@ pub trait SystemExt: Sized + Debug + Default + Send + Sync { /// use sysinfo::{System, SystemExt}; /// /// let mut s = System::new_all(); + /// s.refresh_cpu_usage(); + /// ``` + fn refresh_cpu_usage(&mut self) { + self.refresh_cpu_specifics(CpuRefreshKind::new().with_cpu_usage()) + } + + /// Refreshes CPUs frequency information. + /// + /// Calling this method is the same as calling + /// `refresh_cpu_specifics(CpuRefreshKind::new().with_frequency())`. + /// + /// ```no_run + /// use sysinfo::{System, SystemExt}; + /// + /// let mut s = System::new_all(); + /// s.refresh_cpu_frequency(); + /// ``` + fn refresh_cpu_frequency(&mut self) { + self.refresh_cpu_specifics(CpuRefreshKind::new().with_frequency()) + } + + /// Refreshes all information related to CPUs information. + /// + /// ⚠️ Please note that the result will very likely be inaccurate at the first call. + /// You need to call this method at least twice (with a bit of time between each call, like + /// 200 ms, take a look at [`SystemExt::MINIMUM_CPU_UPDATE_INTERVAL`] for more information) + /// to get accurate value as it uses previous results to compute the next value. + /// + /// Calling this method is the same as calling + /// `refresh_cpu_specifics(CpuRefreshKind::everything())`. + /// + /// ```no_run + /// use sysinfo::{System, SystemExt}; + /// + /// let mut s = System::new_all(); /// s.refresh_cpu(); /// ``` fn refresh_cpu(&mut self) { - self.refresh_cpu_specifics(CpuRefreshKind::new().with_cpu_usage()) + self.refresh_cpu_specifics(CpuRefreshKind::everything()) } /// Refreshes CPUs specific information.