diff options
author | pierce <xuanyuan300@gmail.com> | 2023-11-09 16:41:01 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-09 09:41:01 +0100 |
commit | c325eb3af90e3046ec4c9d9f85250e0e9c4d7792 (patch) | |
tree | 109d4283a01a03d4023bcd2bf166cb409f9f9068 | |
parent | a553188601204a2f79f0cce7c9756248f1aec90e (diff) |
fix(performance): only refresh relevant prorcess in sysinfo when serializing sessions (#2920)
* optimize: update refresh prorcess for sysinfo to reduce cpu usage
* fix: fix format
Signed-off-by: xuanyuan300 <xuanyuan300@gmail.com>
---------
Signed-off-by: xuanyuan300 <xuanyuan300@gmail.com>
-rw-r--r-- | zellij-server/src/os_input_output.rs | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/zellij-server/src/os_input_output.rs b/zellij-server/src/os_input_output.rs index c74001ea7..8a2a4cdc7 100644 --- a/zellij-server/src/os_input_output.rs +++ b/zellij-server/src/os_input_output.rs @@ -756,20 +756,24 @@ impl ServerOsApi for ServerOsInputOutput { fn get_cwds(&self, pids: Vec<Pid>) -> HashMap<Pid, PathBuf> { let mut system_info = System::new(); - // Update by minimizing information. - // See https://docs.rs/sysinfo/0.22.5/sysinfo/struct.ProcessRefreshKind.html# - system_info.refresh_processes_specifics(ProcessRefreshKind::default()); - let mut cwds = HashMap::new(); + for pid in pids { - if let Some(process) = system_info.process(pid.into()) { - let cwd = process.cwd(); - let cwd_is_empty = cwd.iter().next().is_none(); - if !cwd_is_empty { - cwds.insert(pid, process.cwd().to_path_buf()); + // Update by minimizing information. + // See https://docs.rs/sysinfo/0.22.5/sysinfo/struct.ProcessRefreshKind.html# + let is_found = + system_info.refresh_process_specifics(pid.into(), ProcessRefreshKind::default()); + if is_found { + if let Some(process) = system_info.process(pid.into()) { + let cwd = process.cwd(); + let cwd_is_empty = cwd.iter().next().is_none(); + if !cwd_is_empty { + cwds.insert(pid, process.cwd().to_path_buf()); + } } } } + cwds } fn get_all_cmds_by_ppid(&self) -> HashMap<String, Vec<String>> { |