Skip to content

Commit

Permalink
Merge pull request #1325 from GuillaumeGomez/refresh-procs
Browse files Browse the repository at this point in the history
Changes on refreshing processes
  • Loading branch information
GuillaumeGomez committed Jul 29, 2024
2 parents 222ed97 + 10fc52b commit 80666a3
Show file tree
Hide file tree
Showing 14 changed files with 300 additions and 449 deletions.
8 changes: 4 additions & 4 deletions benches/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ fn bench_refresh_all(b: &mut test::Bencher) {
fn bench_refresh_processes(b: &mut test::Bencher) {
let mut s = sysinfo::System::new();

s.refresh_processes(); // to load the whole processes list a first time.
s.refresh_processes(sysinfo::ProcessesToUpdate::All); // to load the whole processes list a first time.
b.iter(move || {
s.refresh_processes();
s.refresh_processes(sysinfo::ProcessesToUpdate::All);
});
}

Expand All @@ -44,7 +44,7 @@ fn bench_refresh_processes(b: &mut test::Bencher) {
fn bench_first_refresh_processes(b: &mut test::Bencher) {
b.iter(move || {
let mut s = sysinfo::System::new();
s.refresh_processes();
s.refresh_processes(sysinfo::ProcessesToUpdate::All);
});
}

Expand All @@ -57,7 +57,7 @@ fn bench_refresh_process(b: &mut test::Bencher) {
// to be sure it'll exist for at least as long as we run
let pid = sysinfo::get_current_pid().expect("failed to get current pid");
b.iter(move || {
s.refresh_process(pid);
s.refresh_processes(sysinfo::ProcessesToUpdate::Some(&[pid]));
});
}

Expand Down
2 changes: 1 addition & 1 deletion examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ fn interpret_input(
.take(1)
.next()
{
if sys.refresh_process(pid) {
if sys.refresh_processes(sysinfo::ProcessesToUpdate::Some(&[pid])) != 0 {
writeln!(&mut io::stdout(), "Process `{pid}` updated successfully");
} else {
writeln!(&mut io::stdout(), "Process `{pid}` couldn't be updated...");
Expand Down
33 changes: 32 additions & 1 deletion migration_guide.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# Migration guide

## 0.30 to 0.31

With this update, the minimum supported Rust version goes up to 1.74.

### Major changes

`System::refresh_process`, `System::refresh_process_specifics` and `System::refresh_pids`
methods were removed. The `System::refresh_processes` and `System::refresh_processes_specifics`
methods take a new argument of type `ProcessesToUpdate`.

The equivalent of `System::refresh_process`, `System::refresh_process_specifics` and
`System::refresh_pids` looks like this:

```rust
use sysinfo::{ProcessesToUpdate, System};

let pid = 1337;
let mut s = System::new();
s.refresh_processes(ProcessesToUpdate::Some(&[pid.into()]));
```

The equivalent of `System::refresh_processes` and `System::refresh_processes_specifics` looks
like this:

```rust
use sysinfo::{ProcessesToUpdate, System};

let mut s = System::new();
s.refresh_processes(ProcessesToUpdate::All);
```

## 0.29 to 0.30

With this update, the minimum supported Rust version goes up to 1.69.
Expand All @@ -16,7 +47,7 @@ So before you had:
use sysinfo::{System, SystemExt};

// `SystemExt` is needed for both `new` and `refresh_processes`.
let s = System::new();
let mut s = System::new();
s.refresh_processes();
```

Expand Down
14 changes: 9 additions & 5 deletions src/c_interface.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::{Disks, Networks, Pid, Process, System};
use crate::{Disks, Networks, Pid, Process, ProcessesToUpdate, System};
use libc::{self, c_char, c_float, c_uint, c_void, size_t};
use std::borrow::BorrowMut;
use std::ffi::CString;
Expand Down Expand Up @@ -86,29 +86,33 @@ pub extern "C" fn sysinfo_refresh_all(system: CSystem) {
}
}

/// Equivalent of [`System::refresh_processes()`][crate::System#method.refresh_processes].
/// Equivalent of [`System::refresh_processes(ProcessesToUpdate::All)`].
///
/// [`System::refresh_processes(ProcessesToUpdate::All)`]: crate::System#method.refresh_processes
#[no_mangle]
pub extern "C" fn sysinfo_refresh_processes(system: CSystem) {
assert!(!system.is_null());
unsafe {
let mut system: Box<System> = Box::from_raw(system as *mut System);
{
let system: &mut System = system.borrow_mut();
system.refresh_processes();
system.refresh_processes(ProcessesToUpdate::All);
}
Box::into_raw(system);
}
}

/// Equivalent of [`System::refresh_process()`][crate::System#method.refresh_process].
/// Equivalent of [`System::refresh_processes(ProcessesToUpdate::Some(pid))`].
///
/// [`System::refresh_processes(ProcessesToUpdate::Some(pid))`]: crate::System#method.refresh_processes
#[no_mangle]
pub extern "C" fn sysinfo_refresh_process(system: CSystem, pid: PID) {
assert!(!system.is_null());
unsafe {
let mut system: Box<System> = Box::from_raw(system as *mut System);
{
let system: &mut System = system.borrow_mut();
system.refresh_process(Pid(pid as _));
system.refresh_processes(ProcessesToUpdate::Some(&[Pid::from_u32(pid as _)]));
}
Box::into_raw(system);
}
Expand Down
Loading

0 comments on commit 80666a3

Please sign in to comment.