Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthik Uthaman committed Jan 30, 2025
1 parent 432db81 commit 01aa1e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
17 changes: 8 additions & 9 deletions src/common/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl System {
self.inner.refresh_cpu_specifics(refresh_kind)
}

/// Gets all processes and updates their information, along with all the threads/tasks each process has.
/// Gets all processes and updates their information, along with all the tasks each process has.
///
/// It does the same as:
///
Expand All @@ -278,7 +278,6 @@ impl System {
/// .with_cpu()
/// .with_disk_usage()
/// .with_exe(UpdateKind::OnlyIfNotSet)
/// .with_tasks(),
/// );
/// ```
///
Expand All @@ -289,9 +288,9 @@ impl System {
/// ⚠️ 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].
///
/// ⚠️ On Linux, if you dont need the threads/tasks of each process, you can use
/// ⚠️ On Linux, if you dont need the tasks of each process, you can use
/// `refresh_processes_specifics` with `ProcessRefreshKind::everything().without_tasks()`.
/// Refreshesing all processes and their threads can be quite expensive. For more information
/// Refreshesing all processes and their tasks can be quite expensive. For more information
/// see [`ProcessRefreshKind`].
///
/// Example:
Expand Down Expand Up @@ -1878,13 +1877,12 @@ pub enum ProcessesToUpdate<'a> {
/// ⚠️ ** Linux Specific ** ⚠️
/// When using `ProcessRefreshKind::everything()`, in linux we will fetch all relevant
/// information from `/proc/<pid>/` as well as all the information from `/proc/<pid>/task/<tid>/`
/// dirs. This makes the refresh mechanism a lot slower depending on the number of threads
/// dirs. This makes the refresh mechanism a lot slower depending on the number of tasks
/// each process has.
///
/// If you dont care about threads information, use `ProcessRefreshKind::everything().without_thread()`
/// If you don't care about tasks information, use `ProcessRefreshKind::everything().without_thread()`
/// as much as possible.
///
/// In windows, this will not have any effect.
/// ```
/// use sysinfo::{ProcessesToUpdate, ProcessRefreshKind, System};
///
Expand Down Expand Up @@ -1940,8 +1938,9 @@ impl Default for ProcessRefreshKind {
}

impl ProcessRefreshKind {
/// Creates a new `ProcessRefreshKind` with every refresh set to `false`.
///
/// Creates a new `ProcessRefreshKind` with every refresh set to `false`, except for `tasks`
/// This is because by default, [`Process`] was fetching all tasks and we want to keep this
/// behavior.
/// ```
/// use sysinfo::{ProcessRefreshKind, UpdateKind};
///
Expand Down
10 changes: 2 additions & 8 deletions src/unix/linux/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,18 +683,12 @@ fn get_all_pid_entries(
let name = name?;
let pid = Pid::from(usize::from_str(name.to_str()?).ok()?);

let tasks = if enable_thread_stats {
let tasks = if enable_task_stats {
let tasks_dir = Path::join(&entry, "task");
if let Ok(entries) = fs::read_dir(tasks_dir) {
let mut tasks = HashSet::new();
for task in entries.into_iter().filter_map(|entry| {
get_all_pid_entries(
Some(name),
Some(pid),
entry.ok()?,
data,
enable_thread_stats,
)
get_all_pid_entries(Some(name), Some(pid), entry.ok()?, data, enable_task_stats)
}) {
tasks.insert(task);
}
Expand Down

0 comments on commit 01aa1e7

Please sign in to comment.