NAME

nbdkit-tracing - adding user statically defined tracing (USDT) probes

SYNOPSIS

 perf buildid-cache --add server/nbdkit
 perf list sdt_nbdkit:*
 perf probe sdt_nbdkit:*
 perf record -e sdt_nbdkit:* -a -R \
             ./nbdkit memory 1G --run 'nbdinfo "$uri"'

DESCRIPTION

You can add user statically defined tracing (USDT) a.k.a DTrace probes to nbdkit and use them to trace significant events in the server. Note this almost certainly requires you to recompile nbdkit from source, since only a very minimal set of probes is included in nbdkit itself and you will want to add your own.

ADDING PROBES

To enable probing at all you will need the <sys/sdt.h> header file installed (eg. from the package systemtap-sdt-devel on Fedora, but available from different places in other Linux distros and BSD). When configuring nbdkit you should see:

 Optional server features:
 ...
    USDT probes ............................ yes

Add probes by inserting DTRACE_PROBE or DTRACE_PROBE<nn> macros into the server source code:

 DTRACE_PROBE (nbdkit, my_probe);

or with up to 12 parameters:

 DTRACE_PROBE2 (nbdkit, my_probe, arg1, arg2);

After compiling nbdkit, you should see a .note.stapsdt ELF section in the binary. This section contains the probes:

 $ readelf -x .note.stapsdt server/nbdkit
 Hex dump of section '.note.stapsdt':
   0x00000000 08000000 39000000 03000000 73746170 ....9.......stap
   0x00000010 73647400 42c70000 00000000 40400200 sdt.B.......@@..
   0x00000020 00000000 00000000 00000000 6e62646b ............nbdk
   0x00000030 69740068 616e646c 655f7369 6e676c65 it.handle_single
   0x00000040 5f636f6e 6e656374 696f6e00 00000000 _connection.....
 ...

USING PERF TO TRACE NBDKIT

perf(1) requires that you scan the binary to detect the probes:

 # perf buildid-cache --add server/nbdkit
 # perf list sdt_nbdkit:*
 List of pre-defined events (to be used in -e or -M):
  sdt_nbdkit:handle_single_connection                [SDT event]
  sdt_nbdkit:preconnect                              [SDT event]

To enable all probes (costly) use:

 # perf probe sdt_nbdkit:*

You can also enable just the probes you are interested in.

To disable probes, use perf probe --del pattern.

Then run perf to record information in the usual way, for example:

 # perf record -e sdt_nbdkit:* -a -R \
               ./nbdkit memory 1G --run 'nbdinfo "$uri"'

 # perf script
          nbdkit 1620084 [007] 2415654.254236:
                 sdt_nbdkit:handle_single_connection: (55e582694742)
          nbdkit 1620084 [007] 2415654.254247:
                 sdt_nbdkit:preconnect: (55e582698724) arg1=94444748021888

SEE ALSO

nbdkit(1), perf(1), https://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps, https://blog.vmsplice.net/2017/07/tracing-userspace-static-probes-with.html, https://jvns.ca/blog/2017/07/05/linux-tracing-systems/, https://docs.openvswitch.org/en/latest/topics/usdt-probes/.

AUTHORS

Eric Blake

Richard W.M. Jones

COPYRIGHT

Copyright Red Hat

LICENSE

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.