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

Introduce ProcessRefreshKind::Thread #1436

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/common/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,7 @@ pub struct ProcessRefreshKind {
environ: UpdateKind,
cmd: UpdateKind,
exe: UpdateKind,
thread: bool,
}

impl ProcessRefreshKind {
Expand Down Expand Up @@ -1887,6 +1888,7 @@ impl ProcessRefreshKind {
environ: UpdateKind::OnlyIfNotSet,
cmd: UpdateKind::OnlyIfNotSet,
exe: UpdateKind::OnlyIfNotSet,
thread: false,
}
}

Expand Down Expand Up @@ -1929,6 +1931,7 @@ It will retrieve the following information:
);
impl_get_set!(ProcessRefreshKind, cmd, with_cmd, without_cmd, UpdateKind);
impl_get_set!(ProcessRefreshKind, exe, with_exe, without_exe, UpdateKind);
impl_get_set!(ProcessRefreshKind, thread, with_thread, without_thread);
}

/// Used to determine what you want to refresh specifically on the [`Cpu`] type.
Expand Down
25 changes: 14 additions & 11 deletions src/unix/linux/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ fn get_all_pid_entries(
parent_pid: Option<Pid>,
entry: DirEntry,
data: &mut Vec<ProcAndTasks>,
refresh_kind: ProcessRefreshKind,
) -> Option<Pid> {
let Ok(file_type) = entry.file_type() else {
return None;
Expand All @@ -678,17 +679,19 @@ fn get_all_pid_entries(
let name = name?;
let pid = Pid::from(usize::from_str(name.to_str()?).ok()?);

let tasks_dir = Path::join(&entry, "task");

let tasks = 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))
{
tasks.insert(task);
let tasks = if refresh_kind.thread() {
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, refresh_kind)
}) {
tasks.insert(task);
}
Some(tasks)
} else {
None
}
Some(tasks)
} else {
None
};
Expand Down Expand Up @@ -773,7 +776,7 @@ pub(crate) fn refresh_procs(
.map(|entry| {
let Ok(entry) = entry else { return Vec::new() };
let mut entries = Vec::new();
get_all_pid_entries(None, None, entry, &mut entries);
get_all_pid_entries(None, None, entry, &mut entries, refresh_kind);
entries
})
.flatten()
Expand Down
Loading