DTRACE(1)

πŸ“¦
version 5.6 Β· 4 versions
, in arch rolling, centos-stream 10, centos-stream 9, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, ubuntu resolute, ubuntu stonking

πŸ’… DTRACE(1) β€” General Commands Manual ✨

okay bestie, sit down, hydrate, and let me tell you about dtrace β€” the Dtrace compatible user application static probe generation tool. yes that's a mouthful. it's fine. she's iconic and she knows it. 🫢


🌸 NAME 🌸

dtrace β€” the Dtrace compatible user application static probe generation tool. that's it, that's her whole job, and she does it flawlessly. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

dtrace -s file [OPTIONS]

literally that's the shape of it. -s gives her the file, and then [OPTIONS] is where you get to be a little extra. 🌈


✨ DESCRIPTION ✨

so here's the tea: the dtrace command takes probe descriptions that you defined over in file.d and converts them into… something useful. specifically:

  • a probe header file, if you pass the -h option πŸ’–
  • a probe description file, if you pass the -G option πŸŽ€

that's the whole vibe. you write the probes, she does the translating. main character energy fr fr.


πŸ‘‘ OPTIONS πŸ‘‘

  • -h β€” generate a systemtap header file. slay.
  • -G β€” generate a systemtap probe definition object file. she invokes the C compiler with a sensible set of compiler flags, because she's thoughtful like that. need to add more? flags chillin' in the CFLAGS environment variable get transcribed over to the compiler. and if that's still not enough control for you (valid, love that for you), use the -k option to capture the generated C file and compile it however you need. πŸ’œ
  • -o file β€” this is the name of the output file. and here's the cute part: if you gave -G, the output file will be called file.o; if you gave -h, the output file will be called file.h. ✨
  • -C β€” run the cpp preprocessor on the input file when the -h option is given.
  • -I file β€” give this include path to cpp when the -C option is given.
  • -k β€” keep temporary files, for example the C language source for the -G option. no takebacks, no cleanup, we keep the receipts. πŸŽ€

πŸ”₯ EXAMPLES πŸ”₯

Systemtap is source compatible with dtrace user application static probe support. ngl that's the whole point.

so say you've got a file test.d containing this:

provider sdt_probes
{
  probe test_0 (int type);
  probe test_1 (struct astruct node);
};
struct astruct {int a; int b;};

then boom:

  • the command dtrace -s test.d -G will create the probe definition file test.o πŸ”₯
  • the command dtrace -stest.d -h will create the probe header file test.h ✨

subsequently (love that word, very fancy) the application can use the generated macros this way:

#include "test.h"
 ...
struct astruct s;
 ...
SDT_PROBES_TEST_0(value);
 ...
if (SDT_PROBES_TEST_1_ENABLED())
    SDT_PROBES_TEST_1(expensive_function(s));

look at those macros go. we love a generated-macro moment. πŸ’–


🧚 SEMAPHORES 🧚

okay so semaphores. they're flag variables that probes use as a way of bypassing potentially costly processing β€” specifically, the work of preparing arguments for probes that may not even be active. why do all that cooking if nobody's eating, right? 😭

they are automatically set/cleared by systemtap when a relevant script is running, so the argument setup cost is only paid when it's actually necessary. those semaphore variables are defined within the test.o object file β€” which means that object file must therefore be linked into an application. no test.o, no semaphores. periodt. πŸ’…

but sometimes? semaphore variables are not necessary nor helpful. and skipping them can simplify the build process, by omitting the extra test.o file. to skip dependence upon semaphore variables, include <sys/sdt.h> within the application before test.h:

#include <sys/sdt.h>
#include "test.h"
 ...
struct astruct s;
 ...
SDT_PROBES_TEST_0(value);
 ...
if (SDT_PROBES_TEST_1_ENABLED())
   SDT_PROBES_TEST_1(cheap_function(s));
heads up bestie: in this mode, the ENABLED() test is fixed at 1. so yeah. it's giving "always on." 🫢

🌈 SEE ALSO 🌈

go read them, i'll wait. πŸ’œ


πŸ’€ BUGS πŸ’€

found a bug? use the Bugzilla link of the project web page or our mailing list:

please actually report it and don't just suffer in silence, that's not the vibe. πŸ™ˆ


and that's the whole page, bestie! this one came out of the General Commands Manual under the name DTRACE(1) β€” so yeah, dtrace(1), section 1, general commands, that's our girl. no date or version stamp on this footer, just her name in lights. k bye, go write some probes πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ«Ά

πŸ“¦ where this page comes from