Skip to content

Commit

Permalink
tools/execsnoop: add '-C' option to display CPU column
Browse files Browse the repository at this point in the history
  • Loading branch information
markyangcc committed Feb 23, 2024
1 parent 397449a commit 2d74ce2
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tools/execsnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,9 @@ def check_cpu_filed():
if args.print_uid:
print("%-6s" % ("UID"), end="")
if args.print_cpu:
print("%-6s" % ("CPU"), end="")
print("%-16s %-7s %-7s %3s %s" % ("PCOMM", "PID", "PPID", "RET", "ARGS"))
print("%-16s %-7s %-7s %-4s %3s %s" % ("PCOMM", "PID", "PPID", "CPU", "RET", "ARGS"))
else:
print("%-16s %-7s %-7s %3s %s" % ("PCOMM", "PID", "PPID", "RET", "ARGS"))

class EventType(object):
EVENT_ARG = 0
Expand Down Expand Up @@ -328,13 +329,15 @@ def print_event(cpu, data, size):
printb(b"%-8.3f" % (time.time() - start_ts), nl="")
if args.print_uid:
printb(b"%-6d" % event.uid, nl="")
if args.print_cpu:
printb(b"%-6d" % event.cpu, nl="")
ppid = event.ppid if event.ppid > 0 else get_ppid(event.pid)
ppid = b"%d" % ppid if ppid > 0 else b"?"
argv_text = b' '.join(argv[event.pid]).replace(b'\n', b'\\n')
printb(b"%-16s %-7d %-7s %3d %s" % (event.comm, event.pid,
ppid, event.retval, argv_text))
if args.print_cpu:
printb(b"%-16s %-7d %-7s %-4d %3d %s" % (event.comm, event.pid,
ppid, event.cpu, event.retval, argv_text))
else:
printb(b"%-16s %-7d %-7s %3d %s" % (event.comm, event.pid,
ppid, event.retval, argv_text))
try:
del(argv[event.pid])
except Exception:
Expand Down

0 comments on commit 2d74ce2

Please sign in to comment.