Skip to content

Commit

Permalink
Merge pull request #1262 from GuillaumeGomez/global-cpu-name
Browse files Browse the repository at this point in the history
Always make global CPU name empty
  • Loading branch information
GuillaumeGomez committed Apr 28, 2024
2 parents 29582df + 8507baa commit 1e4c985
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
1 change: 0 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ jobs:
toolchain: ${{ matrix.toolchain }}

- name: Install cross-target
if: matrix.triple.cross
run: rustup target add ${{ matrix.triple.target }}

- name: Check
Expand Down
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
7 changes: 1 addition & 6 deletions src/windows/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,7 @@ impl CpusWrapper {
pub fn new() -> Self {
Self {
global: Cpu {
inner: CpuInner::new_with_values(
"Total CPU".to_owned(),
String::new(),
String::new(),
0,
),
inner: CpuInner::new_with_values(String::new(), String::new(), String::new(), 0),
},
cpus: Vec::new(),
got_cpu_frequency: false,
Expand Down

0 comments on commit 1e4c985

Please sign in to comment.