Skip to content

Commit

Permalink
Merge pull request #1161 from GuillaumeGomez/process-exe
Browse files Browse the repository at this point in the history
Get `Process::exe` information by default
  • Loading branch information
GuillaumeGomez authored Nov 29, 2023
2 parents 9fb48e6 + 96ffca3 commit 8737fa0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 36 deletions.
16 changes: 10 additions & 6 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,14 @@ impl System {
/// It does the same as:
///
/// ```no_run
/// # use sysinfo::{ProcessRefreshKind, System};
/// # use sysinfo::{ProcessRefreshKind, System, UpdateKind};
/// # let mut system = System::new();
/// system.refresh_processes_specifics(
/// ProcessRefreshKind::new()
/// .with_memory()
/// .with_cpu()
/// .with_disk_usage(),
/// .with_disk_usage()
/// .with_exe(UpdateKind::OnlyIfNotSet),
/// );
/// ```
///
Expand All @@ -247,7 +248,8 @@ impl System {
ProcessRefreshKind::new()
.with_memory()
.with_cpu()
.with_disk_usage(),
.with_disk_usage()
.with_exe(UpdateKind::OnlyIfNotSet),
);
}

Expand All @@ -273,15 +275,16 @@ impl System {
/// It is the same as calling:
///
/// ```no_run
/// # use sysinfo::{Pid, ProcessRefreshKind, System};
/// # use sysinfo::{Pid, ProcessRefreshKind, System, UpdateKind};
/// # let mut system = System::new();
/// # let pid = Pid::from(0);
/// system.refresh_process_specifics(
/// pid,
/// ProcessRefreshKind::new()
/// .with_memory()
/// .with_cpu()
/// .with_disk_usage(),
/// .with_disk_usage()
/// .with_exe(UpdateKind::OnlyIfNotSet),
/// );
/// ```
///
Expand All @@ -302,7 +305,8 @@ impl System {
ProcessRefreshKind::new()
.with_memory()
.with_cpu()
.with_disk_usage(),
.with_disk_usage()
.with_exe(UpdateKind::OnlyIfNotSet),
)
}

Expand Down
34 changes: 4 additions & 30 deletions tests/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,6 @@

use sysinfo::{Pid, ProcessRefreshKind, System, UpdateKind};

#[test]
fn test_process() {
let mut s = System::new();
assert_eq!(s.processes().len(), 0);
s.refresh_processes();
if !sysinfo::IS_SUPPORTED || cfg!(feature = "apple-sandbox") {
return;
}
assert!(!s.processes().is_empty());
assert!(s
.processes()
.values()
.all(|p| p.exe().as_os_str().is_empty()));

let mut s = System::new();
s.refresh_processes_specifics(ProcessRefreshKind::new().with_exe(UpdateKind::Always));
assert!(s
.processes()
.values()
.any(|p| !p.exe().as_os_str().is_empty()));
}

#[test]
fn test_cwd() {
if !sysinfo::IS_SUPPORTED || cfg!(feature = "apple-sandbox") {
Expand Down Expand Up @@ -188,17 +166,13 @@ fn test_process_refresh() {
.process(sysinfo::get_current_pid().expect("failed to get current pid"))
.is_some());

assert!(s.processes().iter().all(|(_, p)| p.environ().is_empty()
&& p.cwd().as_os_str().is_empty()
&& p.cmd().is_empty()));
assert!(s
.processes()
.iter()
.all(|(_, p)| p.exe().as_os_str().is_empty()
&& p.environ().is_empty()
&& p.cwd().as_os_str().is_empty()
&& p.cmd().is_empty()));
assert!(s
.processes()
.iter()
.any(|(_, p)| !p.name().is_empty() && p.memory() != 0));
.any(|(_, p)| !p.exe().as_os_str().is_empty() && !p.name().is_empty() && p.memory() != 0));
}

#[test]
Expand Down

0 comments on commit 8737fa0

Please sign in to comment.