diff --git a/README.md b/README.md index eb7621486..945e44e2b 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ use sysinfo::System; let mut sys = System::new(); loop { - sys.refresh_cpu(); // Refreshing CPU information. + sys.refresh_cpu_usage(); // Refreshing CPU usage. for cpu in sys.cpus() { print!("{}% ", cpu.cpu_usage()); } diff --git a/benches/basic.rs b/benches/basic.rs index 34124003d..04d121737 100644 --- a/benches/basic.rs +++ b/benches/basic.rs @@ -114,11 +114,12 @@ fn bench_refresh_memory(b: &mut test::Bencher) { } #[bench] -fn bench_refresh_cpu(b: &mut test::Bencher) { +fn bench_refresh_cpu_usage(b: &mut test::Bencher) { let mut s = sysinfo::System::new(); + s.refresh_cpu_usage(); b.iter(move || { - s.refresh_cpu(); + s.refresh_cpu_usage(); }); } diff --git a/examples/simple.rs b/examples/simple.rs index 15ce7be45..afd351cc0 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -179,7 +179,7 @@ fn interpret_input( } "refresh_cpu" => { writeln!(&mut io::stdout(), "Refreshing CPUs..."); - sys.refresh_cpu(); + sys.refresh_cpu_all(); writeln!(&mut io::stdout(), "Done."); } "signals" => { diff --git a/src/common.rs b/src/common.rs index 62b4d33c4..ba987610b 100644 --- a/src/common.rs +++ b/src/common.rs @@ -201,7 +201,9 @@ impl System { /// Refreshes all information related to CPUs information. /// - /// ⚠️ Please note that the result will very likely be inaccurate at the first call. + /// If you only want the CPU usage, use [`System::refresh_cpu_usage`] instead. + /// + /// ⚠️ Please note that the result will 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 [`MINIMUM_CPU_UPDATE_INTERVAL`] for more information) /// to get accurate value as it uses previous results to compute the next value. @@ -213,11 +215,11 @@ impl System { /// use sysinfo::System; /// /// let mut s = System::new_all(); - /// s.refresh_cpu(); + /// s.refresh_cpu_all(); /// ``` /// /// [`MINIMUM_CPU_UPDATE_INTERVAL`]: crate::MINIMUM_CPU_UPDATE_INTERVAL - pub fn refresh_cpu(&mut self) { + pub fn refresh_cpu_all(&mut self) { self.refresh_cpu_specifics(CpuRefreshKind::everything()) } @@ -493,7 +495,7 @@ impl System { /// Returns "global" CPUs information (aka the addition of all the CPUs). /// - /// To have up-to-date information, you need to call [`System::refresh_cpu`] or + /// To have up-to-date information, you need to call [`System::refresh_cpu_specifics`] or /// [`System::refresh_specifics`] with `cpu` enabled. /// /// **⚠️ Important ⚠️** @@ -519,7 +521,7 @@ impl System { /// Returns the list of the CPUs. /// - /// By default, the list of CPUs is empty until you call [`System::refresh_cpu`] or + /// By default, the list of CPUs is empty until you call [`System::refresh_cpu_specifics`] or /// [`System::refresh_specifics`] with `cpu` enabled. /// /// ```no_run @@ -3970,7 +3972,7 @@ impl Component { /// // Wait a bit because CPU usage is based on diff. /// std::thread::sleep(sysinfo::MINIMUM_CPU_UPDATE_INTERVAL); /// // Refresh CPUs again. -/// s.refresh_cpu(); +/// s.refresh_cpu_all(); /// /// for cpu in s.cpus() { /// println!("{}%", cpu.cpu_usage()); @@ -3996,7 +3998,7 @@ impl Cpu { /// // Wait a bit because CPU usage is based on diff. /// std::thread::sleep(sysinfo::MINIMUM_CPU_UPDATE_INTERVAL); /// // Refresh CPUs again. - /// s.refresh_cpu(); + /// s.refresh_cpu_all(); /// /// for cpu in s.cpus() { /// println!("{}%", cpu.cpu_usage()); diff --git a/tests/cpu.rs b/tests/cpu.rs index 14a88065b..72fa93b9e 100644 --- a/tests/cpu.rs +++ b/tests/cpu.rs @@ -11,7 +11,7 @@ fn test_cpu() { return; } - s.refresh_cpu(); + s.refresh_cpu_all(); assert!(!s.cpus().is_empty()); let s = sysinfo::System::new_all(); @@ -42,7 +42,7 @@ fn test_global_cpu_info_not_set() { assert_eq!(s.global_cpu_info().vendor_id(), ""); assert_eq!(s.global_cpu_info().brand(), ""); assert_eq!(s.global_cpu_info().frequency(), 0); - s.refresh_cpu(); + s.refresh_cpu_all(); assert_eq!(s.global_cpu_info().vendor_id(), ""); assert_eq!(s.global_cpu_info().brand(), ""); assert_eq!(s.global_cpu_info().frequency(), 0); @@ -57,8 +57,8 @@ fn test_too_rapid_cpu_refresh() { return; } - s.refresh_cpu(); - s.refresh_cpu(); + s.refresh_cpu_all(); + s.refresh_cpu_all(); assert!(s.cpus().iter().any(|c| !c.cpu_usage().is_nan())); }