Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always make global CPU name empty #1262

Merged
merged 2 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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