-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Allow running bpftrace with an optional command #253
Comments
There's another use case that someone wants at FB that would be similar to this. We want to exit bpftrace when |
#294 lays down some supporting changes for this feature |
Merged
danobi
added a commit
to danobi/bpftrace
that referenced
this issue
Dec 28, 2018
This patch adds a command running option to bpftrace. The user can now run something like: ./bpftrace -e '...' -c 'sleep 5' which is a convenience wrapper around something like: sleep 5 & ./bpfrace -e '...' -p `pidof sleep` `-c` is better because it: * ensures a tighter tracing range around CMD (ie we trace less of the system while it is not running CMD) * makes bpftrace exit (which is convenient) when CMD terminates * previously, it was not possible to get a full trace of CMDs execution and have bpftrace exit upon CMD termination Test Plan: Trivial successful example: ``` $ sudo ./build/src/bpftrace -e 'tracepoint:syscalls:sys_enter_nanosleep { printf("%s nanoslept\n", comm); }' -c '/bin/sleep 1' [sudo] password for dlxu: chdir(/lib/modules/4.19.8-200.fc28.x86_64/build): No such file or directory Attaching 1 probe... sleep nanoslept splunkd nanoslept webrtc_audio_mo nanoslept gnome-terminal- nanoslept webrtc_audio_mo nanoslept gnome-terminal- nanoslept gnome-terminal- nanoslept gnome-terminal- nanoslept gnome-terminal- nanoslept gnome-terminal- nanoslept gnome-terminal- nanoslept gnome-terminal- nanoslept gnome-terminal- nanoslept gnome-terminal- nanoslept gnome-terminal- nanoslept $ ``` Ambigous executable: ``` $ sudo ./build/src/bpftrace -e 'tracepoint:syscalls:sys_enter_nanosleep { printf("%s nanoslept\n", comm); }' -c 'sleep 1' chdir(/lib/modules/4.19.8-200.fc28.x86_64/build): No such file or directory Attaching 1 probe... execve: No such file or directory Failed to spawn child=sleep 1 splunkd nanoslept $ ``` This closes bpftrace#253
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running bpftrace with an optional command is useful when tracing an application in development environments and you want to trace only a specific process since it started. We could either receive the pid of the process as an argument (also related to #18), or it could filter the probe as if
-p PID
was given.For example:
sudo ./bpftrace -e 'kprobe:do_nanosleep { printf("[%d] tick\n", pid); }' -c "sleep 10s"
.The text was updated successfully, but these errors were encountered: