nbdkit-tracing(3)

πŸ’– nbdkit-tracing(3) πŸ’–

okay bestie, sit down, hydrate, because we're about to talk about user statically defined tracing, a.k.a. USDT, a.k.a. DTrace probes πŸ¦‹

this is page nbdkit-tracing(3) from the nbdkit manual (section 3, library/syscall girlies know) β€” and no cap, this one is a vibe: it's all about adding USDT probes so you can watch the server doing its little thing in real time ✨


✨ 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 πŸ’…

so like, you can add user statically defined tracing (USDT), also known as DTrace probes, to nbdkit, and then use them to trace significant events in the server. it's giving observability, it's giving main character energy πŸ”₯

⚠️ but heads up bestie: this almost certainly requires you to recompile nbdkit from source, because only a very minimal set of probes is included in nbdkit itself β€” and you're gonna want to add your own. periodt.

🧚 ADDING PROBES 🧚

to enable probing at all, you need the <sys/sdt.h> header file installed. like, for example from the package systemtap-sdt-devel on Fedora, but it's available from different places in other Linux distros and BSD 🌈

when you're configuring nbdkit you should see this:

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

add probes by inserting the DTRACE_PROBE or DTRACE_PROBE<nn> macros into the server source code, like:

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 πŸŽ€ and that 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, so do that first:

# 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 the probes (which is costly, ngl πŸ’€) use:

# perf probe sdt_nbdkit:*

you can also enable just the probes you're interested in β€” pick your faves, it's your world πŸ’œ

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

look at those timestamps go, we love to see it πŸ˜­πŸ’–


πŸ‘€ SEE ALSO πŸ‘€


🫢 AUTHORS 🫢

  • Eric Blake
  • Richard W.M. Jones

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:

  • 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 notice, this list of conditions and the following disclaimer in the documentation 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 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.


and that's the whole page bestie, you ate that πŸ’…βœ¨

this was nbdkit-1.48.1, dated 2026-08-29 β€” go forth and probe responsibly, ily πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from