From 4b72f052968bbf048430310d22871d1c7a77558d Mon Sep 17 00:00:00 2001 From: Sasha Goldshtein Date: Wed, 29 Jun 2016 02:18:06 -0700 Subject: [PATCH] cpudist: Attempt to resolve pid to command Use `/proc/$PID/comm`, which may fail, for example if the original process already exited. This may also produce misleading results if another process got the same pid, but there's no way around this. --- tools/cpudist.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/cpudist.py b/tools/cpudist.py index 2df8172..8cd434c 100755 --- a/tools/cpudist.py +++ b/tools/cpudist.py @@ -192,7 +192,14 @@ while (1): if args.timestamp: print("%-8s\n" % strftime("%H:%M:%S"), end="") - dist.print_log2_hist(label, section, section_print_fn=int) + def pid_to_comm(pid): + try: + comm = open("/proc/%d/comm" % pid, "r").read() + return "%d %s" % (pid, comm) + except IOError: + return str(pid) + + dist.print_log2_hist(label, section, section_print_fn=pid_to_comm) dist.clear() countdown -= 1 -- 2.7.4