Skip to content

Commit

Permalink
cpudist: Attempt to resolve pid to command
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
goldshtn committed Jun 30, 2016
1 parent 9972f27 commit 4b72f05
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tools/cpudist.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,14 @@
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
Expand Down

0 comments on commit 4b72f05

Please sign in to comment.