D(7)
๐ 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 ofstackdepth.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โ Theerrno(2)value of the last system call performed by the current thread.curlwpsinfoโ A pointer to thelwpsinfo_trepresentation of the current thread. Refer todtrace_proc(4)for more details.curpsinfoโ A pointer to thepsinfo_trepresentation of the current process. Refer todtrace_proc(4)for more details.curthreadโ A pointer to the threadstructthat is currently on-CPU. E.g.,curthread->td_namereturns the thread name. The<sys/proc.h>header documents all members ofstruct thread.callerโ The address of the kernel thread instruction at the time of execution of the current probe.ucallerโ The userspace counterpart ofcaller.
๐ฅ 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)โ Averagecount()โ Countllquantize(value, factor, low, high, nsteps)โ Log-linear quantizationlquantize(value, low, high, nsteps)โ Linear quantizationmax(value)โ Maximummin(value)โ Minimumquantize(value)โ Power-of-two frequency distributionstddev(value)โ Standard deviationsum(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 theddb(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 โญ
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
- Copyright (c) 2025 Mateusz Piotrowski <0mp@FreeBSD.org>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms