D(7)

๐Ÿ“ฆ
version 15.1 ยท 2 versions
, in freebsd 15.1

๐ŸŒˆ D(7) โ€” DTrace Scripting Language Overview ๐ŸŒˆ

Okay bestie, so you're reading D(7), the manual for the DTrace scripting language โ€” the D language, not the vitamin, not the grade, the tracing one ๐Ÿ’… This page is your lil cheat-sheet, no cap.


โœจ SYNOPSIS โœจ

provider:module:function:name [[/predicate/] {action}]

That's the whole vibe of a probe clause, right there. Iconic.


๐Ÿ’– DESCRIPTION ๐Ÿ’–

So D is the dtrace(1) scripting language. This manual gives you a brief reference of the D language and scripting โ€” it's giving "quick-start card".

This page is literally just a short reference of the language, fr fr. If you want the full novel, go read the books listed in SEE ALSO โ€” they're the main characters of complete references.


๐Ÿฆ‹ PROBE'S DESCRIPTION ๐Ÿฆ‹

A probe's description is made of four elements, and yes you have to say all four:

provider:module:function:name

The exact meaning of module, function, and name depends on the provider โ€” so like, context matters, iykyk.


๐ŸŽ€ USER-DEFINED VARIABLE TYPES ๐ŸŽ€

Here's the whole fam, with their syntax:

  • global โ€” variable_name
  • aggregate โ€” @variable_name
  • thread-local โ€” self->variable_name
  • clause-local โ€” this->variable_name

Tips, bestie, listen up:

  • Always use the variable type with the smallest scope to minimize processing overhead.
  • Use aggregate variables instead of global variables when possible. Aggregate variables are multi-CPU safe in contrast to global variables โ€” big slay.

๐Ÿ‘‘ BUILT-IN VARIABLES ๐Ÿ‘‘

๐Ÿ”ฅ Probe Arguments

  • args[] โ€” The array of typed probe arguments.
  • arg0, ..., arg9 โ€” The untyped probe arguments represented as 64-bit unsigned integers. Only the first ten arguments are available this way.

๐Ÿ”ฅ Probe Information

  • epid โ€” The enabled probe ID which uniquely identifies an enabled probe. An enabled probe is defined by its probe ID, its predicates, and its actions.
  • id โ€” The probe ID which uniquely identifies a probe available to DTrace.
  • probeprov โ€” The provider in the probe's description (provider:module:function:name).
  • probemod โ€” The module in the probe's description (provider:module:function:name).
  • probefunc โ€” The function in the probe's description (provider:module:function:name).
  • probename โ€” The name in the probe's description (provider:module:function:name).

๐Ÿ”ฅ Process Information

  • execargs โ€” The process arguments. Effectively, curthread->td_proc->p_args.
  • execname โ€” The name of the current process. Effectively, curthread->td_proc->p_comm.
  • gid โ€” The group ID of the current process.
  • pid โ€” The process ID of the current process.
  • ppid โ€” The parent process ID of the current process.
  • uid โ€” The user ID of the current process.

๐Ÿ”ฅ Thread Information

  • uregs[] โ€” The saved user-mode register values.
  • cpu โ€” The ID of the current CPU.
  • stackdepth โ€” The kernel stack frame depth.
  • ustackdepth โ€” The userspace counterpart of stackdepth.
  • tid โ€” The thread ID. Depending on the context, this can be either the ID of a kernel thread or a thread in a user process.
  • errno โ€” The errno(2) value of the last system call performed by the current thread.
  • curlwpsinfo โ€” A pointer to the lwpsinfo_t representation of the current thread. Refer to dtrace_proc(4) for more details.
  • curpsinfo โ€” A pointer to the psinfo_t representation of the current process. Refer to dtrace_proc(4) for more details.
  • curthread โ€” A pointer to the thread struct that is currently on-CPU. E.g., curthread->td_name returns the thread name. The <sys/proc.h> header documents all members of struct thread.
  • caller โ€” The address of the kernel thread instruction at the time of execution of the current probe.
  • ucaller โ€” The userspace counterpart of caller.

๐Ÿ”ฅ Timestamps

  • timestamp โ€” The number of nanoseconds since boot. Suitable for calculating relative time differences of elapsed time and latency.
  • vtimestamp โ€” The number of nanoseconds that the current thread spent on CPU. The counter is not increased during handling of a fired DTrace probe. Suitable for calculating relative time differences of on-CPU time.
  • walltimestamp โ€” The number of nanoseconds since the Epoch (1970-01-01T00+00:00). Suitable for timestamping logs.

๐Ÿงš BUILT-IN FUNCTIONS ๐Ÿงš

String-ology ๐Ÿ’ฌ

string strchr(string s, char c) Return a substring of s starting at the first occurance of c in s. Return NULL if c does not occur in s.

For example,

strchr("abc", 'b');

returns bc and

strchr("abc", 'd');

returns NULL.


string strjoin(string s1, string s2) Return a string resulting from concatenating s1 and s2.

For example,

strjoin("abc", "def")

returns abcdef.


string strrchr(string s, char c) Return a substring of s starting at the last occurance of c in s. Similar to strchr().


string strstr(string haystack, string needle) Return a substring of haystack starting at the first occurrence of needle. Return NULL if needle is not a substring of haystack.

For example,

strstr("abc1bc2", "bc")

returns bc1bc2 and

strstr("abc", "xy")

returns NULL.


string strtok(string s, string separators) Tokenize s with separators.

For example,

strtok("abcdefg", "xyzd")

returns abc.


size_t strlen(string s) Return the length of string s.


string substr(string s, int position, [int length]) Return a substring of string s starting at position. The substring will be at most length-long. If length is not specified, use the rest of the string. If position is greater than the size of s, return an empty string.

For example,

substr("abcd", 2)

returns cd,

substr("abcd", 2, 1)

returns c, and

substr("abcd", 99)

returns an empty string.


Aggregation Functions ๐Ÿงฎ

  • avg(value) โ€” Average
  • count() โ€” Count
  • llquantize(value, factor, low, high, nsteps) โ€” Log-linear quantization
  • lquantize(value, low, high, nsteps) โ€” Linear quantization
  • max(value) โ€” Maximum
  • min(value) โ€” Minimum
  • quantize(value) โ€” Power-of-two frequency distribution
  • stddev(value) โ€” Standard deviation
  • sum(value) โ€” Sum

Kernel Destructive Functions ๐Ÿ’€ (handle with care, bestie)

By default, dtrace(1) does not permit the use of destructive actions. Read that again.
  • breakpoint() โ€” Set a kernel breakpoint and transfer control to the ddb(4) kernel debugger.
  • chill(nanoseconds) โ€” Spin on the CPU for the specified number of nanoseconds.
  • panic() โ€” Panic the kernel. ๐Ÿ˜ญ

๐ŸŒธ FILES ๐ŸŒธ

  • /usr/share/dtrace โ€” DTrace scripts shipped with FreeBSD base.

โญ SEE ALSO โญ

awk(1), dtrace(1), tracing(7)

The illumos Dynamic Tracing Guide, https://illumos.org/books/dtrace/, 2008.

Brendan Gregg and Jim Mauro, DTrace: Dynamic Tracing in Oracle Solaris, Mac OS X and FreeBSD, Prentice Hall, https://www.brendangregg.com/dtracebook/, 2011.

George Neville-Neil, Jonathan Anderson, Graeme Jenkinson, Brian Kidney, Domagoj Stolfa, Arun Thomas, and Robert N. M. Watson, Univeristy of Cambridge Computer Laboratory, OpenDTrace Specification version 1.0, https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-924.pdf, Cambridge, United Kingdom, August 2018.


๐Ÿ•ฐ๏ธ HISTORY ๐Ÿ•ฐ๏ธ

This manual page first appeared in FreeBSD 15.0 โ€” a fresh arrival, periodt.


๐Ÿซถ AUTHORS ๐Ÿซถ

This manual page was written by Mateusz Piotrowski <0mp@FreeBSD.org> โ€” give them their flowers ๐Ÿ’


๐Ÿ™ˆ BUGS ๐Ÿ™ˆ

The cwd variable which typically provides the current working directory is not supported on FreeBSD at the moment. So like... don't come for it, it's not there yet, ngl.


Okay that's the whole page, bestie โ€” you ate that read ๐Ÿ’… This little number is Debian-flavored, dated October 28, 2025, and it's literally the FreeBSD D(7) tea served fresh ๐ŸŒˆโœจ

๐Ÿ“ฆ where this page comes from
  • freebsd 15.1: base 15.1
  • ๐Ÿ“œ the page's license: BSD-2-Clause
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms