Skip site navigation (1)Skip section navigation (2)

  
 
  

home | help
nbdkit-tracing(3)		     NBDKIT		       nbdkit-tracing(3)

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 in-
     stalled (eg. from the package "systemtap-sdt-devel" on Fedora, but avail-
     able from different places in other Linux distros and BSD).  When configur-
     ing 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/AddingUser-
     SpaceProbingToApps, https://blog.vmsplice.net/2017/07/tracing-user-
     space-static-probes-with.html, https://jvns.ca/blog/2017/07/05/linux-trac-
     ing-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 modifi-
     cation, are permitted provided that the following conditions are met:

     *	 Redistributions of source code must retain the above copyright notice,
	 this list of conditions and the following disclaimer.

     *	 Redistributions in binary form must reproduce the above copyright no-
	 tice, this list of conditions and the following disclaimer in the docu-
	 mentation and/or other materials provided with the distribution.

     *	 Neither the name of Red Hat nor the names of its contributors may be
	 used to endorse or promote products derived from this software without
	 specific prior written permission.

     THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND ANY EX-
     PRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DIS-
     CLAIMED. IN NO EVENT SHALL RED HAT OR CONTRIBUTORS BE LIABLE FOR ANY DI-
     RECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SER-
     VICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABIL-
     ITY, 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 DAM-
     AGE.

nbdkit-1.46.2			   2026-08-30		       nbdkit-tracing(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=nbdkit-tracing&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>

home | help