Skip to content

Commit

Permalink
Always make global CPU name empty
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Apr 28, 2024
1 parent 313223e commit 9d74cf9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,15 @@ mod test {
}
}

// Ensure that the global CPU name is always empty.
#[test]
fn check_global_cpu_name() {
let mut s = System::new();
assert_eq!(s.global_cpu_info().name(), "");
s.refresh_cpu_all();
assert_eq!(s.global_cpu_info().name(), "");
}

// In case `Process::updated` is misused, `System::refresh_processes` might remove them
// so this test ensures that it doesn't happen.
#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/unix/apple/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl CpusWrapper {
Self {
global_cpu: Cpu {
inner: CpuInner::new(
"0".to_owned(),
String::new(),
Arc::new(CpuData::new(std::ptr::null_mut(), 0)),
0,
String::new(),
Expand Down
8 changes: 1 addition & 7 deletions src/unix/linux/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,7 @@ impl CpusWrapper {
if &line[..4] != b"cpu " {
return;
}
let mut parts = line.split(|x| *x == b' ').filter(|s| !s.is_empty());
if first {
to_str!(parts.next().unwrap_or(&[]))
.clone_into(&mut self.global_cpu.inner.name);
} else {
parts.next();
}
let mut parts = line.split(|x| *x == b' ').filter(|s| !s.is_empty()).skip(1);
self.global_cpu.inner.set(
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
Expand Down

0 comments on commit 9d74cf9

Please sign in to comment.