Skip to content

Commit

Permalink
Rename System::refresh_cpu into System::refresh_cpu_all
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Apr 9, 2024
1 parent c65673a commit 26a4cee
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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());
}
Expand Down
5 changes: 3 additions & 2 deletions benches/basic.rs
Expand Up @@ -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();
});
}

Expand Down
2 changes: 1 addition & 1 deletion examples/simple.rs
Expand Up @@ -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" => {
Expand Down
16 changes: 9 additions & 7 deletions src/common.rs
Expand Up @@ -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.
Expand All @@ -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())
}

Expand Down Expand Up @@ -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 ⚠️**
Expand All @@ -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
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down
8 changes: 4 additions & 4 deletions tests/cpu.rs
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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()));
}

0 comments on commit 26a4cee

Please sign in to comment.