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

Conversation

markyangcc
Copy link
Contributor

@markyangcc markyangcc commented Feb 6, 2024

In SMP systems, knowing which specific CPU a process is running on can be useful for troubleshooting.

Test it,

[root@anylinux ~]# taskset -c 0 sleep 100 &
[1] 2199347
[root@anylinux ~]# taskset -c 1 sleep 100 &
[2] 2199348

Now, execsnoop with '-C' option displays that one sleep process is running on CPU 0, the other is running on CPU 1, as expected.

[root@anylinux ~]# /usr/share/bcc/tools/execsnoop -C
PCOMM            PID     PPID    CPU  RET ARGS
taskset          2199347 2199222 0      0 /usr/bin/taskset -c 0 sleep 100
sleep            2199347 2199222 0      0 /usr/bin/sleep 100
taskset          2199348 2199222 4      0 /usr/bin/taskset -c 1 sleep 100
sleep            2199348 2199222 1      0 /usr/bin/sleep 100

@@ -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.

@yonghong-song
Copy link
Collaborator

can we add this 'cpu' display under an option (e.g., '-c')? The reason is in most cases, the value will be 0 and we should not display them. People can use -c if they have pinned-to-cpu task and they want to monitor them.

print("%-16s %-7s %-7s %-4s %3s %s" % ("PCOMM", "PID", "PPID", "CPU", "RET", "ARGS"))
if args.print_cpu:
print("%-6s" % ("CPU"), end="")
print("%-16s %-7s %-7s %3s %s" % ("PCOMM", "PID", "PPID", "RET", "ARGS"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would like CPU column after 'PPID' and before 'RET' and this confirms to most other bcc tools where PCOMM/PID/PPID is displayed earlier in columns.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks reviewing, I rearranged the CPU column display position. Now it's after 'PPID' and before 'RET'.

@yonghong-song yonghong-song merged commit 699cd5f into iovisor:master Feb 23, 2024
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants