diff --git a/README.md b/README.md index 6d74e82..3f5a946 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ loadtimer -s 2 -b 0 -n 3 `pidof logd` Benchmarking PIDs [229] 3 sample(s) of 60s -| Description | CPU usage % | total mean | utime mean | utime stddev | stime mean | stime stddev | -| 229, 3 samples, 60s | 2.5 | 5.0 | 1.3 | 0.58 | 3.7 | 0.58 | +| Description | CPU usage % | total mean | utime mean | utime stddev | stime mean | stime stddev | +| logd | 2.5 | 5.0 | 1.3 | 0.58 | 3.7 | 0.58 | ``` If you want to build from source, e.g. for Android: diff --git a/src/lib.rs b/src/lib.rs index e6c3819..cea0857 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +use std::fs; + use anyhow::Result; use nix::unistd::SysconfVar; @@ -16,3 +18,9 @@ pub fn get_user_hz() -> Result { "failed to retreive USER_HZ / SC_CLK_TCK / jiffies" )) } + +/// Get the command behind a process. +pub fn get_process_command(pid: usize) -> Result { + let path = format!("/proc/{pid}/comm"); + fs::read_to_string(path).map_err(Into::into) +} diff --git a/src/main.rs b/src/main.rs index 70f1b8a..fb7b9fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use anyhow::Result; use loadtimer::{ - cli::Cli, dump::print_proc_metrics, eval::ProcMetrics, get_user_hz, sample::Sampler, + cli::Cli, dump::print_proc_metrics, eval::ProcMetrics, get_process_command, get_user_hz, + sample::Sampler, }; use std::time::Duration; @@ -27,7 +28,7 @@ fn main() -> Result<()> { let descriptions = args .pids .iter() - .map(|pid| format!("{pid}, {} samples, {}s", args.num_samples, args.sample_secs)); + .map(|pid| get_process_command(*pid).unwrap_or_else(|_| format!("PID {pid}"))); println!(); print_proc_metrics(&metrics, descriptions);