From e225589b05ae2ae2b2e8ebd90cf7f918975c751e Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Thu, 30 Dec 2021 17:17:28 -0700 Subject: [PATCH] mux: improve process name cache and fg proc name on windows Reduce the cache lifetime a bit, and resolve a potential racy/non-deterministic result due to the timestamp granularity. --- mux/src/localpane.rs | 15 +++++++++++++-- mux/src/sysinfo.rs | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/mux/src/localpane.rs b/mux/src/localpane.rs index 420118e62..7a3e68257 100644 --- a/mux/src/localpane.rs +++ b/mux/src/localpane.rs @@ -361,8 +361,19 @@ impl Pane for LocalPane { proc: &'a LocalProcessInfo, youngest: &mut &'a LocalProcessInfo, ) { - if proc.start_time > youngest.start_time { - *youngest = proc; + if proc.start_time >= youngest.start_time { + // start_time has only 1 second granularity, and spawning + // a child process will typically spawn a console host at + // the same time. + // We might traverse one snapshot of the tree differently + // from another due to random seeds in the hash table, + // so we do a little bit of targeted workaround here + // to suppress the console hosts from candidate child + // processes. + let ignore = proc.name == "OpenConsole.exe" || proc.name == "conhost.exe"; + if !ignore { + *youngest = proc; + } } for child in proc.children.values() { diff --git a/mux/src/sysinfo.rs b/mux/src/sysinfo.rs index c7fa94cbb..de2d22ce9 100644 --- a/mux/src/sysinfo.rs +++ b/mux/src/sysinfo.rs @@ -37,7 +37,7 @@ impl CachedSystemInfo { } pub fn check_refresh(&mut self) { - if self.last_update.elapsed() < Duration::from_millis(1000) { + if self.last_update.elapsed() < Duration::from_millis(300) { return; } self.refresh_now();