Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools/execsnoop: display which cpu the processes running on #4904

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions tools/execsnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def parse_uid(user):
u32 pid; // PID as in the userspace term (i.e. task->tgid in kernel)
u32 ppid; // Parent PID as in the userspace term (i.e task->real_parent->tgid in kernel)
u32 uid;
u32 cpu;
char comm[TASK_COMM_LEN];
enum event_type type;
char argv[ARGSIZE];
Expand Down Expand Up @@ -207,6 +208,7 @@ def parse_uid(user):
// as the real_parent->tgid.
// We use the get_ppid function as a fallback in those cases. (#1883)
data.ppid = task->real_parent->tgid;
data.cpu = task->cpu;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which kernel version you are testing? I checked latest upstream and 5.19, the field name for 'task' is 'on_cpu' and not 'cpu'. Please ensure your change works for all supported kernels (from e.g. 4.11 to recent kernels).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, 'cpu' filed was changed on recent kernels. It was move back to 'thread_info' since linux 5.16
Link: torvalds/linux@bcf9033e5449
Now, BTF filed check or buildtime filed check is added to handle this change.


PPID_FILTER

Expand Down Expand Up @@ -251,7 +253,7 @@ def parse_uid(user):
print("%-8s" % ("TIME(s)"), end="")
if args.print_uid:
print("%-6s" % ("UID"), 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"))

class EventType(object):
EVENT_ARG = 0
Expand Down Expand Up @@ -305,8 +307,8 @@ def print_event(cpu, data, size):
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))
printb(b"%-16s %-7d %-7s %-4d %3d %s" % (event.comm, event.pid,
ppid, event.cpu, event.retval, argv_text))
try:
del(argv[event.pid])
except Exception:
Expand Down
Loading