xref: /freebsd/cddl/contrib/opensolaris/cmd/dtrace/dtrace.1 (revision 24e4dcf4ba5e9dedcf89efd358ea3e1fe5867020)
1.\" CDDL HEADER START
2.\"
3.\" The contents of this file are subject to the terms of the
4.\" Common Development and Distribution License (the "License").
5.\" You may not use this file except in compliance with the License.
6.\"
7.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
8.\" or http://www.opensolaris.org/os/licensing.
9.\" See the License for the specific language governing permissions
10.\" and limitations under the License.
11.\"
12.\" When distributing Covered Code, include this CDDL HEADER in each
13.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
14.\" If applicable, add the following below this CDDL HEADER, with the
15.\" fields enclosed by brackets "[]" replaced with your own identifying
16.\" information: Portions Copyright [yyyy] [name of copyright owner]
17.\"
18.\" CDDL HEADER END
19.\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved.
20.\"
21.\" $FreeBSD$
22.\"
23.Dd July 30, 2025
24.Dt DTRACE 1
25.Os
26.Sh NAME
27.Nm dtrace
28.Nd dynamic tracing compiler and tracing utility
29.Sh SYNOPSIS
30.Nm
31.Op Fl 32 | Fl 64
32.Op Fl aACdeFGhHlOqSvVwZ
33.Op Fl -libxo
34.Op Fl b Ar bufsz
35.Op Fl c Ar cmd
36.Op Fl D Ar name Op Ns = Ns value
37.Op Fl I Ar path
38.Op Fl L Ar path
39.Op Fl o Ar output
40.Op Fl s Ar script
41.Op Fl U Ar name
42.Op Fl x Ar arg Op Ns = Ns value
43.Op Fl X Cm a | c | s | t
44.Op Fl p Ar pid
45.Op Fl P Ar provider Oo Oo Ar predicate Oc Ar action Oc
46.Op Fl m Oo Ar provider : Oc Ar module Oo Oo Ar predicate Oc Ar action Oc
47.Op Fl f Oo Oo Ar provider : Oc Ar module : Oc Ar function Oo Oo Ar predicate \
48    Oc Ar action Oc
49.Op Fl n Oo Oo Oo Ar provider : Oc Ar module : Oc Ar function : Oc Ar name \
50    Oo Oo Ar predicate Oc Ar action Oc
51.Op Fl i Ar probe-id Oo Oo Ar predicate Oc Ar action Oc
52.Sh DESCRIPTION
53DTrace is a comprehensive dynamic tracing framework ported from Solaris.
54DTrace provides a powerful infrastructure that permits administrators,
55developers, and service personnel to concisely answer arbitrary questions about
56the behavior of the operating system and user programs.
57.Pp
58The
59.Nm
60command provides a generic interface to the essential services provided by the
61DTrace facility, including:
62.Bl -bullet -offset indent
63.It
64Options that list the set of probes and providers currently published by DTrace
65.It
66Options that enable probes directly using any of the probe description
67specifiers (provider, module, function, name)
68.It
69Options that run the D compiler and compile one or more D program files or
70programs written directly on the command line
71.It
72Options that generate anonymous tracing programs
73.It
74Options that generate program stability reports
75.It
76Options that modify DTrace tracing and buffering behavior and enable
77additional D compiler features
78.El
79.Pp
80You can use
81.Nm
82to create D scripts by using it in a shebang declaration to create an
83interpreter file.
84You can also use
85.Nm
86to attempt to compile D programs and determine their properties without
87actually enabling traces using the
88.Fl e
89option.
90.Sh OPTIONS
91The arguments accepted by the
92.Fl P ,
93.Fl m ,
94.Fl f ,
95.Fl n ,
96and
97.Fl i
98options can include an optional D language
99.Ar predicate
100enclosed in slashes and an optional D language
101.Ar action
102statement list enclosed in braces.
103D program code specified on the command line must be appropriately quoted to
104avoid interpretation of meta-characters by the shell.
105.Pp
106The following options are supported:
107.Bl -tag -width indent
108.It Fl 32 | Fl 64
109The D compiler produces programs using the native data model of the operating
110system kernel.
111If the
112.Fl 32
113option is specified,
114.Nm
115forces the D compiler to compile a D program using the 32-bit data model.
116If the
117.Fl 64
118option is specified,
119.Nm
120forces the D compiler to compile a D program using the 64-bit data model.
121These options are typically not required as
122.Nm
123selects the native data model as the default.
124The data model affects the sizes of integer types and other language properties.
125D programs compiled for either data model can be executed on both 32-bit and
12664-bit kernels.
127The
128.Fl 32
129and
130.Fl 64
131options also determine the
132.Xr elf 5
133file format (ELF32 or ELF64) produced by the
134.Fl G
135option.
136.It Fl a
137Claim anonymous tracing state and display the traced data.
138You can combine the
139.Fl a
140option with the
141.Fl e
142option to force
143.Nm
144to exit immediately after consuming the anonymous tracing state rather than
145continuing to wait for new data.
146.It Fl A
147Generate directives for anonymous tracing and write them to
148.Pa /boot/dtrace.dof .
149This option constructs a set of dtrace configuration file directives to enable
150the specified probes for anonymous tracing and then exits.
151By default,
152.Nm
153attempts to store the directives to the file
154.Pa /boot/dtrace.dof .
155This behavior can be modified using the
156.Fl o
157option to specify an alternate output file.
158.It Fl b Ar bufsz
159Set the principal trace buffer size to
160.Ar bufsz .
161The trace buffer size can include any of the size suffixes k, m, g, or t.
162If the buffer space cannot be allocated,
163.Nm dtrace
164attempts to reduce the buffer size or exit depending on the setting of the
165bufresize property.
166.It Fl c Ar cmd
167Run the specified command
168.Ar cmd
169and exit upon its completion.
170If more than one
171.Fl c
172option is present on the command line,
173.Nm dtrace
174exits when all commands have exited, reporting the exit status for each child
175process as it terminates.
176The process ID of the first command is made available to any D programs
177specified on the command line or using the
178.Fl s
179option through the
180.Li $target
181macro variable.
182.It Fl C
183Run the C preprocessor
184.Xr cpp 1
185over D programs before compiling them.
186You can pass options to the C preprocessor using the
187.Fl D ,
188.Fl U ,
189.Fl I ,
190and
191.Fl H
192options.
193You can select the degree of C standard conformance if you use the
194.Fl X
195option.
196For a description of the set of tokens defined by the D compiler when invoking
197the C preprocessor, see
198.Fl X .
199.It Fl d
200Dump the D script to standard output, after syntactic transformations have been
201applied.
202For example, if-statements in D are implemented using such transformations: a
203conditional clause in a probe body is replaced at compile-time by a separate
204probe predicated on the original condition.
205.It Fl D Ar name Op Ns = Ns value
206Define
207.Ar name
208when invoking
209.Xr cpp 1
210(enabled using the
211.Fl C
212option).
213If you specify an additional
214.Ar value ,
215the name is assigned the corresponding value.
216This option passes the
217.Fl D
218option to each
219.Xr cpp 1
220invocation.
221.It Fl e
222Exit after compiling any requests and consuming anonymous tracing state
223.Fl ( a
224option) but prior to enabling any probes.
225You can combine this option with the
226.Fl a
227option to print anonymous tracing data and exit.
228You can also combine this option with D compiler options.
229This combination verifies that the programs compile without actually executing
230them and enabling the corresponding instrumentation.
231.It Fl f Oo Oo Ar provider : Oc Ar module : Oc Ar function Oo Oo Ar predicate \
232    Oc Ar action Oc
233Specify function name to trace or list
234.Fl ( l
235option).
236The corresponding argument can include any of the probe description forms
237.Ar provider:module:function ,
238.Ar module:function ,
239or
240.Ar function .
241Unspecified probe description fields are left blank and match any probes
242regardless of the values in those fields.
243If no qualifiers other than
244.Ar function
245are specified in the description, all probes with the corresponding
246.Ar function
247are matched.
248The
249.Fl f
250argument can be suffixed with an optional D probe clause.
251You can specify more than one
252.Fl f
253option on the command line at a time.
254.It Fl F
255Coalesce trace output by identifying function entry and return.
256Function entry probe reports are indented and their output is prefixed with
257.Ql -> .
258Function return probe reports are unindented and their output is prefixed with
259.Ql <- .
260System call entry probe reports are indented and their output is prefixed with
261.Ql => .
262System call return probe reports are unindented and their output is prefixed
263with
264.Ql <= .
265.It Fl G
266Generate an ELF file containing an embedded DTrace program.
267The DTrace probes specified in the program are saved inside of a relocatable ELF
268object which can be linked into another program.
269If the
270.Fl o
271option is present, the ELF file is saved using the pathname specified as the
272argument for this operand.
273If the
274.Fl o
275option is not present and the DTrace program is contained with a file whose name
276is
277.Ar filename.d ,
278then the ELF file is saved using the name
279.Ar filename.o .
280Otherwise the ELF file is saved using the name d.out.
281.It Fl h
282Generate a header file containing macros that correspond to probes in the
283specified provider definitions.
284This option should be used to generate a header file that is included by other
285source files for later use with the
286.Fl G
287option.
288If the
289.Fl o
290option is present, the header file is saved using the pathname specified as the
291argument for that option.
292If the
293.Fl o
294option is not present and the DTrace program is contained within a file whose
295name is
296.Ar filename.d ,
297then the header file is saved using the name
298.Ar filename.h .
299.It Fl H
300Print the pathnames of included files when invoking
301.Xr cpp 1
302(enabled using the
303.Fl C
304option).
305This option passes the
306.Fl H
307option to each
308.Xr cpp 1
309invocation, causing it to display the list of pathnames, one for each line, to
310standard error.
311.It Fl i Ar probe-id Op Oo Ar predicate Oc Ar action
312Specify probe identifier
313.Ar ( probe-id )
314to trace or list
315.Ar ( l
316option).
317You can specify probe IDs using decimal integers as shown by `dtrace -l`.
318The
319.Fl i
320argument can be suffixed with an optional D probe clause.
321You can specify more than one
322.Fl i
323option at a time.
324.It Fl I Ar path
325Add the specified directory
326.Ar path
327to the search path for #include files when invoking
328.Xr cpp 1
329(enabled using the
330.Fl C
331option).
332This option passes the
333.Fl I
334option to each
335.Xr cpp 1
336invocation.
337The specified
338.Ar path
339is inserted into the search path ahead of the default directory list.
340.It Fl l
341List probes instead of enabling them.
342If the
343.Fl l
344option is specified,
345.Nm
346produces a report of the probes matching the descriptions given using the
347.Fl P , m , f , n , i ,
348and
349.Fl s
350options.
351If none of these options are specified, this option lists all probes.
352.It Fl L Ar path
353Add the specified directory
354.Ar path
355to the search path for DTrace libraries.
356DTrace libraries are used to contain common definitions that can be used when
357writing D programs.
358The specified
359.Ar path
360is added after the default library search path.
361.It Fl -libxo
362Generate output via
363.Xr libxo 3 .
364This option is the same as specifying
365.Sy oformat .
366.It Fl m Oo Ar provider : Oc Ar module Oo Oo Ar predicate Oc Ar action Oc
367Specify module name to trace or list
368.Fl ( l
369option).
370The corresponding argument can include any of the probe description forms
371.Ar provider:module
372or
373.Ar module .
374Unspecified probe description fields are left blank and match any probes
375regardless of the values in those fields.
376If no qualifiers other than
377.Ar module
378are specified in the description, all probes with a corresponding
379.Ar module
380are matched.
381The
382.Fl m
383argument can be suffixed with an optional D probe clause.
384More than one
385.Fl m
386option can be specified on the command line at a time.
387.It Fl n Oo Oo Oo Ar provider : Oc Ar module : Oc Ar function : Oc Ar name \
388    Oo Oo Ar predicate Oc Ar action Oc
389Specify probe name to trace or list
390.Fl ( l
391option).
392The corresponding argument can include any of the probe description forms
393.Ar provider:module:function:name , module:function:name , function:name ,
394or
395.Ar name .
396Unspecified probe description fields are left blank and match any probes
397regardless of the values in those fields.
398If no qualifiers other than
399.Ar name
400are specified in the description, all probes with a corresponding
401.Ar name
402are matched.
403The
404.Fl n
405argument can be suffixed with an optional D probe clause.
406More than one
407.Fl n
408option can be specified on the command line at a time.
409.It Fl O
410This option causes
411.Nm
412to print all the aggregations upon exiting if
413.Sy oformat
414or
415.Fl -libxo
416are specified.
417.It Fl o Ar output
418Specify the
419.Ar output
420file for the
421.Fl A , G ,
422and
423.Fl l
424options, or for the traced data itself.
425If the
426.Fl A
427option is present and
428.Fl o
429is not present, the default output file is
430.Pa /boot/dtrace.dof .
431If the
432.Fl G
433option is present and the
434.Fl s
435option's argument is of the form
436.Ar filename.d
437and
438.Fl o
439is not present, the default output file is
440.Ar filename.o .
441Otherwise the default output file is
442.Ar d.out .
443.It Fl p Ar pid
444Grab the specified process-ID
445.Ar pid ,
446cache its symbol tables, and exit upon its completion.
447If more than one
448.Fl p
449option is present on the command line,
450.Nm
451exits when all commands have exited, reporting the exit status for each process
452as it terminates.
453The first process-ID is made available to any D programs specified on the
454command line or using the
455.Fl s
456option through the
457.Li $target
458macro variable.
459.It Fl P Ar provider Oo Oo Ar predicate Oc Ar action Oc
460Specify provider name to trace or list
461.Fl ( l
462option).
463The remaining probe description fields module, function, and name are left
464blank and match any probes regardless of the values in those fields.
465The
466.Fl P
467argument can be suffixed with an optional D probe clause.
468You can specify more than one
469.Fl P
470option on the command line at a time.
471.It Fl q
472Set quiet mode.
473.Nm
474suppresses messages such as the number of probes matched by the specified
475options and D programs and does not print column headers, the CPU ID, the probe
476ID, or insert newlines into the output.
477Only data traced and formatted by D program statements such as
478.Ql dtrace()
479and
480.Ql printf()
481is displayed to standard output.
482.It Fl s Ar script
483Compile the specified D program source file.
484If the
485.Fl e
486option is present, the program is compiled but instrumentation is not enabled.
487If the
488.Fl l
489option is present, the program is compiled and the set of probes matched by it
490is listed, but instrumentation is not enabled.
491If none of
492.Fl e , l , G ,
493or
494.Fl A
495are present, the instrumentation specified by the D program is enabled and
496tracing begins.
497.It Fl S
498Show D compiler intermediate code.
499The D compiler produces a report of the intermediate code generated for each D
500program to standard error.
501.It Fl U Ar name
502Undefine the specified
503.Ar name
504when invoking
505.Xr cpp 1
506(enabled using the
507.Fl C
508option).
509This option passes the
510.Fl U
511option to each
512.Xr cpp 1
513invocation.
514.It Fl v
515Set verbose mode.
516If the
517.Fl v
518option is specified,
519.Nm
520produces a program stability report showing the minimum interface stability and
521dependency level for the specified D programs.
522.It Fl V
523Report the highest D programming interface version supported by
524.Nm .
525The version information is printed to standard output and the
526.Nm
527command exits.
528.It Fl w
529Permit destructive actions in D programs specified using the
530.Fl s , P , m , f , n ,
531or
532.Fl i
533options.
534If the
535.Fl w
536option is not specified,
537.Nm
538does not permit the compilation or enabling of a D program that contains
539destructive actions.
540.Pp
541Set the
542.Va security.bsd.allow_destructive_dtrace
543.Xr loader 8
544tunable
545to
546.Ql 0
547to disallow the possibility of enabling destructive actions system-wide at any point at all.
548Any attempts to enable destructive actions will cause
549.Nm
550to exit with a runtime error.
551.It Fl x Ar arg Op Ns = Ns value
552Enable or modify a DTrace runtime option or D compiler option.
553Boolean options are enabled by specifying their name.
554Options with values are set by separating the option name and value with an
555equals sign (=).
556.Pp
557A
558.Ar size
559argument may be suffixed with one of
560.Cm K ,
561.Cm M ,
562.Cm G
563or
564.Cm T
565(either upper or lower case) to indicate a multiple of
566Kilobytes, Megabytes, Gigabytes or Terabytes
567respectively.
568.Pp
569A
570.Ar time
571argument may be suffixed with one of
572.Cm ns ,
573.Cm nsec ,
574.Cm us ,
575.Cm usec ,
576.Cm ms ,
577.Cm msec ,
578.Cm s  ,
579.Cm sec ,
580.Cm m ,
581.Cm min ,
582.Cm h ,
583.Cm hour ,
584.Cm d  ,
585.Cm day ,
586.Cm hz .
587If no suffix is specified
588.Cm hz
589will be used as the unit.
590.Bl -tag -width indent
591.It Sy aggrate Ns = Ns Ar time
592Rate of aggregation reading.
593.It Sy aggsize Ns = Ns Ar size
594Size of the aggregation buffer.
595.It Sy bufpolicy Ns = Ns Cm fill Ns | Ns Cm switch Ns | Ns Cm ring
596Specifies the buffer policy for the principal buffer.
597.It Sy bufresize Ns = Ns Cm auto Ns | Ns Cm manual
598Buffer resizing policy.
599.It Sy bufsize Ns = Ns Ar size
600Size of the per-CPU principal buffer.
601Same as the
602.Fl b
603flag.
604.It Sy cleanrate Ns = Ns Ar time
605Cleaning rate.
606Must be specified in number-per-second with the
607.Dq Li hz
608suffix.
609.It Sy cpu Ns = Ns Ar scalar
610Specifies the CPU on which to enable tracing.
611.It Sy cpp
612Run a C preprocessor over input files.
613Same as the
614.Fl C
615flag.
616.It Sy cpppath Ns = Ns Ar path
617Use the specified path for the C preprocessor rather than
618searching for
619.Dq cpp
620in
621.Ev PATH .
622.It Sy defaultargs
623Allow references to unspecified macro arguments.
624.It Sy destructive
625Allow destructive actions.
626Same as the
627.Fl w
628flag.
629.It Sy dynvarsize Ns = Ns Ar size
630Size of the dynamic variable space.
631.Sm off
632.It Sy evaltime = Cm exec | preinit | postinit | main
633.Sm on
634Process create mode.
635When using
636.Fl c Ar cmd
637to start a command,
638.Nm
639will first stop the newly started
640.Ar cmd ,
641evaluate the
642.Xr d 7
643program,
644and then resume the
645.Ar cmd .
646The
647.Cm evaltime
648option controls the exact moment when this happens.
649.Pp
650The following table describes supported modes.
651.Bl -column -offset indent "postinit" "D Program Evaluation Time"
652.It Sy Mode Ta Sy D Program Evaluation Time
653.It Cm exec Ta
654Right at the first instruction of the command
655.Ar cmd
656execution.
657.It Cm preinit Ta
658Before
659.Xr elf 5 Ap s
660.Dq .init
661sections.
662.It Cm postinit Ta
663After
664.Xr elf 5 Ap s
665.Dq .init
666sections.
667Default on
668.Fx .
669.It Cm main Ta
670Before the first instruction of the
671.Fn main
672function.
673.El
674.Pp
675Usually, there is no reason to change the default mode,
676but it might be handy in situations such as shared library tracing.
677.It Sy flowindent
678Turn on flow indentation.
679Same as the
680.Fl F
681flag.
682.It Sy grabanon
683Claim anonymous state.
684Same as the
685.Fl a
686flag.
687.It Sy jstackframes Ns = Ns Ar scalar
688Number of default stack frames for
689.Fn jstack .
690.It Sy jstackstrsize Ns = Ns Ar scalar
691Default string space size for
692.Fn jstack .
693.It Sy ldpath Ns = Ns Ar path
694When
695.Fl G
696is specified, use the specified path for a static linker
697rather than searching for
698.Dq "ld"
699in
700.Ev PATH .
701.It Sy libdir Ns = Ns Ar path
702Add a directory to the system library path.
703.It Sy nspec Ns = Ns Ar scalar
704Number of speculations.
705.It Sy nolibs
706Do not load D system libraries.
707.It Sy quiet
708Set quiet mode.
709Same as the
710.Fl q
711flag.
712.It Sy specsize Ns = Ns Ar size
713Size of the speculation buffer.
714.It Sy strsize Ns = Ns Ar size
715Maximum size of strings.
716.It Sy stackframes Ns = Ns Ar scalar
717Maximum number of kernelspace stack frames to unwind when executing the
718.Fn stack
719action.
720.It Sy stackindent Ns = Ns Ar scalar
721Number of whitespace characters to use when indenting
722.Fn stack
723and
724.Fn ustack
725output.
726.It Sy oformat Ns = Ns Ar format
727Specify the format to use for output.
728Setting
729.Sy oformat
730to
731.Ql text
732makes
733.Nm
734use regular human-readable output which is its default behavior.
735The options passed to
736.Sy oformat
737are directly forwarded to
738.Xr libxo 3 .
739Some of the supported formatters include
740.Ql json ,
741.Ql xml
742and
743.Ql html .
744Note that this option will cause
745.Nm
746to not produce any output unless printing functions are explicitly called,
747or the
748.Fl O
749flag is specified.
750For more information see
751.Sx STRUCTURED OUTPUT .
752.It Sy statusrate Ns = Ns Ar time
753Rate of status checking.
754.It Sy switchrate Ns = Ns Ar time
755Rate of buffer switching.
756.It Sy syslibdir Ns = Ns Ar path
757Path to system libraries.
758Defaults to
759.Pa /usr/lib/dtrace .
760.It Sy ustackframes Ns = Ns Ar scalar
761Maximum number of userspace stack frames to unwind when executing the
762.Fn ustack
763action.
764.El
765.It Fl X Cm a | c | s | t
766Specify the degree of conformance to the ISO C standard that should be selected
767when invoking
768.Xr cpp 1
769(enabled using the
770.Fl C
771option).
772The
773.Fl X
774option argument affects the value and presence of the __STDC__ macro depending
775upon the value of the argument letter.
776.sp
777The
778.Fl X
779option supports the following arguments:
780.Bl -tag -width indent
781.It a
782Default.
783ISO C plus K&R compatibility extensions, with semantic changes required by ISO
784C.
785This is the default mode if
786.Fl X
787is not specified.
788The predefined macro __STDC__ has a value of 0 when
789.Xr cpp 1
790is invoked in conjunction with the
791.Fl Xa
792option.
793.It c
794Conformance.
795Strictly conformant ISO C, without K&R C compatibility extensions.
796The predefined macro __STDC__ has a value of 1 when
797.Xr cpp 1
798is invoked in conjunction with the
799.Fl \&Xc
800option.
801.It s
802K&R C only.
803The macro __STDC__ is not defined when
804.Xr cpp 1
805is invoked in conjunction with the
806.Fl Xs
807option.
808.It t
809Transition.
810ISO C plus K&R C compatibility extensions, without semantic changes required by
811ISO C.
812The predefined macro __STDC__ has a value of 0 when
813.Xr cpp 1
814is invoked in conjunction with the
815.Fl Xt
816option.
817.El
818.Pp
819As the
820.Fl X
821option only affects how the D compiler invokes the C preprocessor, the
822.Fl Xa
823and
824.Fl Xt
825options are equivalent from the perspective of D and both are provided only to
826ease re-use of settings from a C build environment.
827.Pp
828Regardless of the
829.Fl X
830mode, the following additional C preprocessor definitions are always specified
831and valid in all modes:
832.Bl -bullet -offset indent
833.It
834__sun
835.It
836__unix
837.It
838__SVR4
839.It
840__sparc (on SPARC systems only)
841.It
842__sparcv9 (on SPARC systems only when 64-bit programs are compiled)
843.It
844__i386 (on x86 systems only when 32-bit programs are compiled)
845.It
846__amd64 (on x86 systems only when 64-bit programs are compiled)
847.It
848__`uname -s`_`uname -r` (for example,
849.Ql FreeBSD_9.2-RELEASE .
850.It
851__SUNW_D=1
852.It
853.No __SUNW_D_VERSION=0x Ns Ar MMmmmuuu
854.Pp
855Where
856.Ar MM
857is the major release value in hexadecimal,
858.Ar mmm
859is the minor release value in hexadecimal, and
860.Ar uuu
861is the micro release value in hexadecimal.
862.El
863.It Fl Z
864Permit probe descriptions that match zero probes.
865If the
866.Fl Z
867option is not specified,
868.Nm
869reports an error and exits if any probe descriptions specified in D program
870files
871.Fl ( s
872option) or on the command line
873.Fl ( P , m , f , n ,
874or
875.Fl i
876options) contain descriptions that do not match any known probes.
877.El
878.Sh STRUCTURED OUTPUT
879.Nm
880supports structured output using
881.Xr libxo 3 .
882The output will always have a top-level object called
883.Dq dtrace ,
884followed by a list of objects
885.Dq probes .
886Each of the probe objects will to have a timestamp which is generated at
887output time rather than probe firing time, an identifier for the CPU on
888which the probe was executed, and the probe's full specification:
889.Bd -literal
890{
891  "dtrace": {
892    "probes": [
893      {
894        "timestamp": ...,
895        "cpu": ...,
896        "id": ...,
897        "provider": ...,
898        "module": ...,
899        "function": ...,
900        "name": ...,
901        "output": [
902           ... (script-specific output)
903        ]
904      }
905    ]
906  }
907}
908
909<?xml version="1.0"?>
910<dtrace>
911  <probes>
912    <timestamp>...</timestamp>
913    <cpu>...</cpu>
914    <id>...</id>
915    <provider>...</provider>
916    <module>...</module>
917    <function>...</function>
918    <name>...</name>
919    <output>
920      ... (script-specific output)
921    </output>
922  </probes>
923</dtrace>
924.Ed
925.Pp
926It is also possible for XML output to take the following form if some
927of the fields are empty (in this example, module and function values
928are absent):
929.Bd -literal
930<?xml version="1.0"?>
931<dtrace>
932  <probes>
933    ...
934    <module/>
935    <function/>
936    ...
937    <output>
938      ... (script-specific output)
939    </output>
940  </probes>
941</dtrace>
942.Ed
943.Pp
944Similarly,
945.Sy oformat
946can be used to generate HTML:
947.Bd -literal
948<div class="line">
949<div class="data" data-tag="timestamp">...</div>
950<div class="text"></div>
951<div class="data" data-tag="cpu">...</div>
952<div class="text"></div>
953<div class="data" data-tag="id">...</div>
954<div class="text"></div>
955<div class="data" data-tag="provider">...</div>
956<div class="text"></div>
957<div class="data" data-tag="module">...</div>
958<div class="text"></div>
959<div class="data" data-tag="function">...</div>
960<div class="text"></div>
961<div class="data" data-tag="name">...</div>
962<div class="data" data-tag="... (script-specific output)">...</div>
963</div>
964.Ed
965.Pp
966Unlike JSON and XML, the
967.Dq output
968array is not present.
969Instead, data is simply formatted into a div of class
970.Dq data
971and a data-tag is associated with each of the keys.
972.Pp
973The
974.Dq output
975array's contents depend on the probes' actions and is explained below.
976The examples here are presented in JSON form as opposed to XML or HTML,
977however the conversion explained above applies for all output formats.
978.Pp
979Any scalar output, such as output produced by the
980.Fn trace
981action is of form:
982.Bd -literal
983{
984  "value": ...
985}
986.Ed
987.Pp
988The
989.Fn printf
990action begins with an object containing the formatted output of the
991.Fn printf
992action.
993Subsequent objects contains the value of each of the arguments to
994.Fn printf
995in its raw form as if the
996.Fn trace
997action was used instead.
998A
999.Fn printf
1000statement which contains no arguments other than the message will only have
1001one object following the message object and its value will always be 0.
1002This is an artefact of the implementation and can safely be ignored.
1003.Bd -literal
1004# dtrace --libxo json,pretty -n 'BEGIN { printf("... %Y, ..", walltimestamp); }'
1005
1006{
1007  "message": "... 2023 Sep  7 16:49:02, .."
1008},
1009{
1010  "value": 1694105342633402400
1011},
1012{
1013  ...
1014}
1015.Ed
1016.Pp
1017Scalar aggregations are aggregations which produce a single value for a given
1018key.
1019These aggregations include
1020.Fn count ,
1021.Fn min ,
1022.Fn max ,
1023.Fn stddev
1024and
1025.Fn sum .
1026Each one of them is represented by the key containing their name.
1027For example, the output of a
1028.Fn stddev
1029aggregation will contain a key
1030.Dq stddev
1031inside an
1032.Dq aggregation-data
1033object:
1034.Bd -literal
1035{
1036  "aggregation-data": [
1037    {
1038      "keys": [
1039        ...
1040      ],
1041      "stddev": ...
1042    }
1043  ],
1044  "aggregation-name": ...
1045}
1046.Ed
1047.Pp
1048The
1049.Dq keys
1050field remains consistent across all aggregations, however
1051.Fn quantize ,
1052.Fn lquantize
1053and
1054.Fn llquantize
1055need to be treated differently.
1056.Sy oformat
1057will create a new array of objects called
1058.Dq buckets .
1059Each of the objects contains a
1060.Dq value
1061and a
1062.Dq count
1063field which are
1064the left-hand side and the right-hand side of human-readable
1065.Nm
1066output respectively.
1067The full object has the following format:
1068.Bd -literal
1069{
1070  "aggregation-data": [
1071    ...
1072    {
1073      "keys": [
1074        ...
1075      ],
1076      "buckets": [
1077        {
1078          "value": 32,
1079          "count": 0
1080        },
1081        {
1082          "value": 64,
1083          "count": 17
1084        },
1085        ...
1086      ],
1087    },
1088    ...
1089  ]
1090  "aggregation-name": ...
1091}
1092.Ed
1093.Pp
1094Similar to scalar aggregations, named scalar actions such as
1095.Fn mod ,
1096.Fn umod ,
1097.Fn usym ,
1098.Fn tracemem
1099and
1100.Fn printm
1101will output an object with the key being equal to the
1102name of the action.
1103For example,
1104.Fn printm
1105output would produce the following object:
1106.Bd -literal
1107{
1108  "printm": "0x4054171100"
1109}
1110.Ed
1111.Pp
1112.Fn sym
1113is slightly different.
1114While it will create a
1115.Dq sym
1116field which contains its value, in some cases it will also create additional
1117fields
1118.Dq object ,
1119.Dq name
1120and
1121.Dq offset :
1122.Bd -literal
1123# dtrace -x oformat=json,pretty -On 'BEGIN { sym((uintptr_t)&`prison0); }'
1124
1125{
1126  "sym": "kernel`prison0",
1127  "object": "kernel",
1128  "name": "prison0"
1129}
1130
1131# dtrace --libxo json,pretty -On 'BEGIN { sym((uintptr_t)curthread); }'
1132
1133{
1134  "sym": "0xfffffe00c18d2000",
1135  "offset": "0xfffffe00c18d2000"
1136}
1137.Ed
1138.Pp
1139.Fn stack
1140and
1141.Fn ustack
1142actions unroll each of the stack frames into its own object in an array.
1143The only real difference between them is that the
1144.Fn stack
1145action will produce a list called
1146.Dq stack-frames
1147while
1148.Fn ustack
1149will produce one called
1150.Dq ustack-frames .
1151The following is an example of their
1152.Sy oformat
1153output:
1154.Bd -literal
1155{
1156  "stack-frames": [
1157    {
1158      "symbol": "dtrace.ko`dtrace_dof_create+0x35",
1159      "module": "dtrace.ko",
1160      "name": "dtrace_dof_create",
1161      "offset": "0x35"
1162    },
1163    {
1164      "symbol": "dtrace.ko`dtrace_ioctl+0x81c",
1165      "module": "dtrace.ko",
1166      "name": "dtrace_ioctl",
1167      "offset": "0x81c"
1168    },
1169    ...
1170  ]
1171}
1172
1173{
1174  "ustack-frames": [
1175    {
1176      "symbol": "libc.so.7`ioctl+0xa",
1177      "module": "libc.so.7",
1178      "name": "ioctl",
1179      "offset": "0xa"
1180    },
1181    {
1182      "symbol": "libdtrace.so.2`dtrace_go+0xf3",
1183      "module": "libdtrace.so.2",
1184      "name": "dtrace_go",
1185      "offset": "0xf3"
1186    },
1187    ...
1188  ]
1189}
1190.Ed
1191.Pp
1192The
1193.Fn print
1194action produces a
1195.Dq type
1196list in the following form:
1197.Bd -literal
1198{
1199  "type": [
1200    {
1201      "object-name": "kernel",
1202      "name": "struct thread",
1203      "ctfid": 2372
1204    },
1205    {
1206      "member-name": "td_lock",
1207      "name": "struct mtx *volatile",
1208      "ctfid": 2035,
1209      "value": "0xffffffff82158440"
1210    },
1211    ...
1212}
1213.Ed
1214.Pp
1215If the type is invalid, a
1216.Dq warning
1217object will be produced containing the diagnostic message as well as two
1218possible optional fields:
1219.Dq type-identifier
1220which contains the CTF identifier of the type and
1221.Dq size containing the size of an integer, enum or float.
1222The fields generated will depend on the kind of error that was encountered
1223while processing the trace data.
1224.Pp
1225Finally,
1226.Sy oformat
1227provides a special pseudo-probe to represent drops.
1228As
1229.Nm
1230polls for various kinds of drops
1231.Sy oformat
1232will produce output similar to the following in order to represent drops:
1233.Bd -literal
1234{
1235  "cpu": -1,
1236  "id": -1,
1237  "provider": "dtrace",
1238  "module": "INTERNAL",
1239  "function": "INTERNAL",
1240  "name": "DROP",
1241  "timestamp": ...,
1242  "count": ...,
1243  "total": ...,
1244  "kind": 2,
1245  "msg": "... dynamic variable drops\n"
1246}
1247.Ed
1248.Sh OPERANDS
1249You can specify zero or more additional arguments on the
1250.Nm
1251command line to define a set of macro variables and so forth).
1252The additional arguments can be used in D programs specified using the
1253.Fl s
1254option or on the command line.
1255.Sh FILES
1256.Bl -tag -width /boot/dtrace.dof -compact
1257.It Pa /boot/dtrace.dof
1258File for anonymous tracing directives.
1259.El
1260.Sh EXIT STATUS
1261The following exit statuses are returned:
1262.Bl -tag -width indent
1263.It 0
1264Successful completion.
1265.Pp
1266For D program requests, an exit status of 0 indicates that programs were
1267successfully compiled, probes were successfully enabled, or anonymous state
1268was successfully retrieved.
1269.Nm
1270returns 0 even if the specified tracing requests encountered errors or drops.
1271.It 1
1272An error occurred.
1273.Pp
1274For D program requests, an exit status of 1 indicates that program compilation
1275failed or that the specified request could not be satisfied.
1276.It 2
1277Invalid command line options or arguments were specified.
1278.El
1279.Sh DIAGNOSTICS
1280.Bl -diag
1281.It dtrace: could not enable tracing: Permission denied
1282This can happen when
1283.Nm
1284fails to enable destructive actions because
1285.Va security.bsd.allow_destructive_dtrace
1286is set to
1287.Ql 0
1288in
1289.Xr loader.conf 5 .
1290.El
1291.Sh SEE ALSO
1292.Xr cpp 1 ,
1293.Xr dwatch 1 ,
1294.Xr dtrace_audit 4 ,
1295.Xr dtrace_dtrace 4 ,
1296.Xr dtrace_fbt 4 ,
1297.Xr dtrace_io 4 ,
1298.Xr dtrace_ip 4 ,
1299.Xr dtrace_kinst 4 ,
1300.Xr dtrace_lockstat 4 ,
1301.Xr dtrace_proc 4 ,
1302.Xr dtrace_profile 4 ,
1303.Xr dtrace_sched 4 ,
1304.Xr dtrace_sctp 4 ,
1305.Xr dtrace_tcp 4 ,
1306.Xr dtrace_udp 4 ,
1307.Xr dtrace_udplite 4 ,
1308.Xr elf 5 ,
1309.Xr d 7 ,
1310.Xr tracing 7 ,
1311.Xr SDT 9
1312.Rs
1313.%T Solaris Dynamic Tracing Guide
1314.Re
1315.Sh HISTORY
1316The
1317.Nm
1318utility first appeared in
1319.Fx 7.1 .
1320