Skip to content

Commit

Permalink
Update Process::refresh_process and Process::refresh_processes de…
Browse files Browse the repository at this point in the history
…fault `ProcessRefreshKind` used
  • Loading branch information
GuillaumeGomez committed Nov 14, 2023
1 parent 3fc0b9e commit 7ccbb7c
Showing 1 changed file with 48 additions and 5 deletions.
53 changes: 48 additions & 5 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,37 @@ impl System {

/// Gets all processes and updates their information.
///
/// It does the same as `system.refresh_processes_specifics(ProcessRefreshKind::everything())`.
/// It does the same as:
///
/// ```no_run
/// # use sysinfo::{ProcessRefreshKind, System};
/// # let mut system = System::new();
/// system.refresh_processes_specifics(
/// ProcessRefreshKind::new()
/// .with_memory()
/// .with_cpu()
/// .with_disk_usage(),
/// );
/// ```
///
/// ⚠️ On Linux, `sysinfo` keeps the `stat` files open by default. You can change this behaviour
/// by using [`set_open_files_limit`][crate::set_open_files_limit].
///
/// Example:
///
/// ```no_run
/// use sysinfo::System;
///
/// let mut s = System::new_all();
/// s.refresh_processes();
/// ```
pub fn refresh_processes(&mut self) {
self.refresh_processes_specifics(ProcessRefreshKind::everything());
self.refresh_processes_specifics(
ProcessRefreshKind::new()
.with_memory()
.with_cpu()
.with_disk_usage(),
);
}

/// Gets all processes and updates the specified information.
Expand All @@ -268,8 +286,24 @@ impl System {
/// exist (it will **NOT** be removed from the processes if it doesn't exist anymore). If it
/// isn't listed yet, it'll be added.
///
/// It is the same as calling
/// `sys.refresh_process_specifics(pid, ProcessRefreshKind::everything())`.
/// It is the same as calling:
///
/// ```no_run
/// # use sysinfo::{ProcessRefreshKind, System};
/// # let mut system = System::new();
/// system.refresh_process_specifics(
/// pid,
/// ProcessRefreshKind::new()
/// .with_memory()
/// .with_cpu()
/// .with_disk_usage(),
/// );
/// ```
///
/// ⚠️ On Linux, `sysinfo` keeps the `stat` files open by default. You can change this behaviour
/// by using [`set_open_files_limit`][crate::set_open_files_limit].
///
/// Example:
///
/// ```no_run
/// use sysinfo::{Pid, System};
Expand All @@ -278,13 +312,22 @@ impl System {
/// s.refresh_process(Pid::from(1337));
/// ```
pub fn refresh_process(&mut self, pid: Pid) -> bool {
self.refresh_process_specifics(pid, ProcessRefreshKind::everything())
self.refresh_process_specifics(
pid,
ProcessRefreshKind::new()
.with_memory()
.with_cpu()
.with_disk_usage(),
)
}

/// Refreshes *only* the process corresponding to `pid`. Returns `false` if the process doesn't
/// exist (it will **NOT** be removed from the processes if it doesn't exist anymore). If it
/// isn't listed yet, it'll be added.
///
/// ⚠️ On Linux, `sysinfo` keeps the `stat` files open by default. You can change this behaviour
/// by using [`set_open_files_limit`][crate::set_open_files_limit].
///
/// ```no_run
/// use sysinfo::{Pid, ProcessRefreshKind, System};
///
Expand Down

0 comments on commit 7ccbb7c

Please sign in to comment.