• Daniel Xu's avatar
    Add -c CMD option · a3086a88
    Daniel Xu authored
    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 #253
    a3086a88
bpftrace.8 7.62 KB