summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorThomas Otto <th1000s@posteo.net>2021-12-09 00:10:37 +0100
committerThomas Otto <th1000s@posteo.net>2021-12-09 00:25:47 +0100
commite710c72169cd4e5cfadc3d7a29fc6d46a005aeab (patch)
treea17bdeae851332d62eb824fbdb4b39a650a9dd88 /src/utils
parent2d6c6d4b295b6c58b450aa1f04814b7e2ae31bc7 (diff)
Query fewer processes when searching for the parentprocs
This query now happens for more invocation types, so speed it up. Call `refresh_process()` only on pids numerically close to the one of delta itself.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/process.rs38
1 files changed, 24 insertions, 14 deletions
diff --git a/src/utils/process.rs b/src/utils/process.rs
index 827e44de..5602dd3f 100644
--- a/src/utils/process.rs
+++ b/src/utils/process.rs
@@ -275,16 +275,11 @@ trait ProcessInterface {
self.refresh_process(sibling_pid).then(|| ())?;
self.process(sibling_pid)
}
- #[cfg(test)]
- fn find_sibling_process<F, T>(&mut self, pid: Pid, extract_args: F) -> Option<T>
+ fn find_sibling_in_refreshed_processes<F, T>(&mut self, pid: Pid, extract_args: &F) -> Option<T>
where
F: Fn(&[String]) -> ProcessArgs<T>,
Self: Sized,
{
- self.refresh_processes();
-
- let this_start_time = self.process(pid)?.start_time();
-
/*
$ start_blame_of.sh src/main.rs | delta
@@ -303,6 +298,8 @@ trait ProcessInterface {
*/
+ let this_start_time = self.process(pid)?.start_time();
+
let mut pid_distances = HashMap::<Pid, usize>::new();
let mut collect_parent_pids = |pid, distance| {
pid_distances.insert(pid, distance);
@@ -407,7 +404,8 @@ where
started, so no command line can be parsed. Same if the data was piped from an input file.
There might also be intermediary scripts in between or piped input with a gap in pids or (rarely)
- randomized pids, so check all processes for the closest match in the process tree.
+ randomized pids, so check processes for the closest match in the process tree.
+ The size of this process tree can be reduced by only refreshing selected processes.
100 /usr/bin/some-terminal-emulator
124 \_ -shell
@@ -426,19 +424,31 @@ where
567 | \_ less --RAW-CONTROL-CHARS --quit-if-one-screen
*/
- #[cfg(test)]
- {
- info.find_sibling_process(my_pid, extract_args)
+
+ let pid_range = my_pid.saturating_sub(10)..my_pid.saturating_add(20);
+ for p in pid_range.clone() {
+ // Processes which were not refreshed do not exist for sysinfo, so by selectively
+ // letting it know about processes the `find_sibling..` function will only
+ // consider these.
+ info.refresh_process(p);
}
- #[cfg(not(test))]
- {
- None
+
+ match info.find_sibling_in_refreshed_processes(my_pid, &extract_args) {
+ None => {
+ #[cfg(test)]
+ {
+ info.refresh_processes();
+ info.find_sibling_in_refreshed_processes(my_pid, &extract_args)
+ }
+ #[cfg(not(test))]
+ None
+ }
+ some => some,
}
}
// Walk up the process tree, calling `f` with the pid and the distance to `starting_pid`.
// Prerequisite: `info.refresh_processes()` has been called.
-#[cfg(test)]
fn iter_parents<P, F>(info: &P, starting_pid: Pid, f: F)
where
P: ProcessInterface,