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>
This commit is contained in:
parent
a553188601
commit
c325eb3af9
1 changed files with 13 additions and 9 deletions
|
|
@ -756,12 +756,14 @@ impl ServerOsApi for ServerOsInputOutput {
|
||||||
|
|
||||||
fn get_cwds(&self, pids: Vec<Pid>) -> HashMap<Pid, PathBuf> {
|
fn get_cwds(&self, pids: Vec<Pid>) -> HashMap<Pid, PathBuf> {
|
||||||
let mut system_info = System::new();
|
let mut system_info = System::new();
|
||||||
|
let mut cwds = HashMap::new();
|
||||||
|
|
||||||
|
for pid in pids {
|
||||||
// Update by minimizing information.
|
// Update by minimizing information.
|
||||||
// See https://docs.rs/sysinfo/0.22.5/sysinfo/struct.ProcessRefreshKind.html#
|
// See https://docs.rs/sysinfo/0.22.5/sysinfo/struct.ProcessRefreshKind.html#
|
||||||
system_info.refresh_processes_specifics(ProcessRefreshKind::default());
|
let is_found =
|
||||||
|
system_info.refresh_process_specifics(pid.into(), ProcessRefreshKind::default());
|
||||||
let mut cwds = HashMap::new();
|
if is_found {
|
||||||
for pid in pids {
|
|
||||||
if let Some(process) = system_info.process(pid.into()) {
|
if let Some(process) = system_info.process(pid.into()) {
|
||||||
let cwd = process.cwd();
|
let cwd = process.cwd();
|
||||||
let cwd_is_empty = cwd.iter().next().is_none();
|
let cwd_is_empty = cwd.iter().next().is_none();
|
||||||
|
|
@ -770,6 +772,8 @@ impl ServerOsApi for ServerOsInputOutput {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cwds
|
cwds
|
||||||
}
|
}
|
||||||
fn get_all_cmds_by_ppid(&self) -> HashMap<String, Vec<String>> {
|
fn get_all_cmds_by_ppid(&self) -> HashMap<String, Vec<String>> {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue