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

PIDs and TIDs in filters and output #547

Open
markdrayton opened this issue May 21, 2016 · 2 comments

Comments

Projects
None yet
3 participants
@markdrayton
Copy link
Contributor

commented May 21, 2016

Lots of the scripts in tools/ take a PID argument to apply filtering to a particular process. The filtering is usually on task->pid (i.e. the lower 32 bits of bpf_get_current_pid_tgid()) and consequently only matches a single thread within a process. IME most userspace apps treat PID as TGID, rather than a specific thread within the process (e.g. think pgrep, ps aux, etc).

Sometime it's handy to filter events by a single task but very often I want to do something for a whole process without filtering by threads within it. E.g., if I wanted to see which stacks in my webserver are doing block IO I'd run stacksnoop -p $(pgrep webserver) submit_bio and expect it to match all threads by default. If I was doing this in perf its -p option would match the process, not a particular thread (there is -t to limit to certain threads).

Any objections to changing tools to:

a) make -p PID filter on TGID
b) adding a -t TID option to limit to a single task (i.e. what -p does now)
c) print both TID and PID in output

I realise this is changing existing behavior but I'd argue it'd be a net improvement overall.

@4ast

This comment has been minimized.

Copy link
Member

commented May 21, 2016

makes sense to me. I think we discussed pid/tgid controversy few times.
Though it may be a bit confusing to script writers that kernel pid is compared with command line tid
and kernel tgid is compared with command line pid.

@brendangregg

This comment has been minimized.

Copy link
Member

commented May 24, 2016

Makes sense to me. I think -p should match whatever pidstat says is the PID, and -t should match what "pidstat -t" says is the TID.

I likely got this wrong many, many times (copy-n-pasted) in /tools, sorry. Would be happy to see it fixed!

As for printing both PID and TID, definitely print TID if -t is used (as the user has signaled that it is important). As for other tools and default output, I guess it would depend on the tool. I try to keep the default output to a minimum. Some tools probably have -v for verbose. Plus I also try to keep the default output to < 80 chars width.

Eg, execsnoop default output probably shouldn't have TID. Nor should killsnoop. ... Actually, I probably wouldn't add TID to most of the scripts' default output. It could show up with -t, or -v.

This will require updates to the /examples files and man pages...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.