KTRACE(1) | General Commands Manual | KTRACE(1) |
ktrace
— record
kernel trace files
ktrace
info
ktrace
trace
-ACNnrSstu
] [-R
path | -E
]
[-C
codes-path
[...]] [-T
timeout] [-f
filter-desc] [-b
buffer-size-mb] [-x
pid-or-process-name [...] |
-p
pid-or-process-name
[...]] [--json
|
--csv
| --ndjson
|
--json-64
] [-c
command [...]]
[--only-named-events
]
[--no-default-codes-files
]
[--continuous
]
[--disable-coprocessors
]ktrace
dump
-E
] [-f
filter-desc] [-l
compression-level] [-T
timeout] [-b
buffer-size-mb] [-p
pid-or-process-name]
[--stackshot-flags
extra-flags]
[--include-log-content
]
[--disable-coprocessors
]
[--notify-tracing-started
key] [path]ktrace
init
-b
buffer-size-mb |
-n
n-eventsktrace
setopt
-f
filter-desc]
[-w
] [-x
pid-or-process-name [...] |
-p
pid-or-process-name
[...]]ktrace
enable
ktrace
disable
ktrace
remove
ktrace
reset
ktrace
decode
debugid [debugid
[...]]ktrace
emit
ktrace
symbolicate
ktrace
machine
ktrace
config
ktrace
compress
-l
-fast|balanced|small
]
pathktrace
artrace
-nr
] [-t
timeout] [-i
interval] [-o
filename] [-b
buffer-size-mb] [-f
filter-desc] [-F
filter-desc] [-p
pid-or-process-name]
[--kperf
=sampler-name[,sampler-name@]timer-period|timer-frequency|kdebug-filter-desc]
[--remote
[=remote-device]]
[--type
=full|profile|lite|morelite|none]
[--stackshot-flags
extra-flags]
[--notify-tracing-started
key] [-c
command [...]]ktrace
can configure the system to trace
events, or record them to a file, and print a human-readable representation
of the events.
ktrace
uses a subcommand syntax to
separate different functionality into logical groups. Each subcommand takes
its own set of options, though a few options may be used in multiple
subcommands.
info
trace
[-ACNnrSstu
] [-R
path | -E
]
[-C
codes-path
[...]] [-T
timeout] [-f
filter-desc] [-b
buffer-size-mb] [-x
pid-or-process-name [...] |
-p
pid-or-process-name
[...]] [--json
|
--csv
| --ndjson
|
--json-64
] [-c
command [...]]
[--only-named-events
]
[--no-default-codes-files
]
[--continuous
]
[--disable-coprocessors
]Print events to stdout(4)
in a human-readable format, automatically providing wall clock time,
process names, and event names for each event. Without the
-R
or -E
options,
ktrace
initializes the trace buffers to a
reasonable size and enables tracing until it terminates.
-R
path-E
trace
subcommand with other
ktrace
subcommands, like
init
and setopt
.-N
-C
-n
-r
ktrace
trace
-E
can later be
used to read the in-memory events.-S
-s
-t
-A
-u
-C
codes-path-b
buffer-size-mb-f
filter-desc-T
timeoutns
or ms
are
supported, but seconds are the default if just a number is
supplied.-x
pid-or-process-name [...] |
-p
pid-or-process-name
[...]-x
) or only trace events
(-p
) from the provided processes by name or
pid. These options are mutually exlusive. Processes that cannot be
attached to are always excluded on release kernels. Similarly, events
in the Mach scheduling subclass are included, regardless of the this
option, to allow tools to maintain thread scheduling state
machines.--json
--csv
--ndjson
--json-64
-c
command [...]dump
Write trace to a file at path for later
inspection with ktrace
trace
-R
. If no
path is specified, the tool writes to a new,
numbered file in the working directory, starting with
trace001.ktrace
. The command continues to write
events until ktrace
is terminated, the optional
timeout triggers, or the trace buffers fill up when using an existing
configuration with wrapping disabled. If a compression level is
specified, the file is compressed as it is written. Using non-default
values for this option may increase the overhead of collecting
events.
-E
-f
filter-desc-p
pid-or-process-name-T
timeoutns
or ms
are
supported, but seconds are the default if just a number is
supplied.--stackshot-flags
extra-flags--notify-tracing-started
keyinit
-b
buffer-size-mb |
-n
n-eventsInitialize trace to allocate
buffer-size-mb megabytes of space or
n-events events for its trace buffers. This
subcommand must be provided before using the
setopt
, enable
, or
disable
subcommands initially or after using the
remove
subcommand.
setopt
[-f
filter-desc]
[-w
] [-x
pid-or-process-name [...] |
-p
pid-or-process-name
[...]]Set options on the existing trace configuration. The trace configuration must already be initialized.
-f
filter-desc-w
-x
pid-or-process-name [...] |
-p
pid-or-process-name
[...]-x
) or only trace events
(-p
) from the provided processes by name or
pid. These options are mutually exlusive. Processes that cannot be
attached to are always excluded on release kernels. Similarly, events
in the Mach scheduling subclass are included, regardless of the this
option, to allow tools to maintain thread scheduling state
machines.enable
disable
remove
reset
decode
debugid [debugid [...]]emit
debugid [arg1 [arg2 [arg3 [arg4]]]]Emit an event into the trace stream with the provided debugid and arguments.
symbolicate
pathconfig
machine
compress
[-l
fast|balanced|small]
path-l
option.artrace
[-nr
] [-t
timeout] [-i
interval] [-o
filename] [-b
buffer-size-mb] [-f
filter-desc] [-F
filter-desc] [-p
pid-or-process-name]
[--remote
[=device-name]]
[--type
=full|profile|lite|morelite|none]
[--kperf
=sampler-name,sampler-name@timer-period|timer-frequency|kdebug-filter-desc]
[-d
group]
[-e
group]
[--stackshot-flags
extra-flags]
[--disable-coprocessors
] [-c
command [...]]-o
path-f
filter-desc-F
filter-desc-t
timeoutus
,
ms
, or s
appended to
indicate the time units.-i
interval-t
).-n
-b
buffer-size-mb-r
-p
pid-or-process-name-d
group-e
group--remote
[=device-name]--type
=full|profile|lite|morelite|noneThe ‘lite
’ modes
work by lazily sampling threads as they are unblocked, and only
those threads that block for more than a set threshold. Further, the
typical profiling timer is disabled, in lieu of sampling the CPUs
opportunistically, on other interrupts. The
morelite mode has a more restrictive
typefilter than lite.
none mode acts like ktrace
dump
.
--stackshot-flags
extra-flags-c
command [...]--kperf
=sampler-name[,sampler-name]@timer-period|timer-frequency|kdebug-filter-descA filter description is a comma-separated list of class and
subclass specifiers that indicate which events should be traced. A class
specifier starts with ‘C
’ and contains
a single byte, specified in either decimal or hex. A subclass specifier
starts with ‘S
’ and takes two bytes.
The high byte is the class and the low byte is the subclass of that
class.
For example, this filter description would enable classes 1 and 37
and the subclasses 33 and 35 of class 5:
‘C1,C0x25,S0x0521,S0x0523
’. The
‘ALL
’ filter description enables
events from all classes.
A sampling description is similar to a filter description, but it
configures sampling. It's composed of two parts: a samplers section and a
trigger section, separated by @
. The overall form is
sampler-name[,sampler-name]@ Ns
timer-period|timer-frequency|kdebug-filter-desc.
The valid names of samplers are
‘ustack
’,
‘kstack
’,
‘thinfo
’,
‘thsnapshot
’,
‘meminfo
’,
‘thsched
’,
‘thdispatch
’,
‘tksnapshot
’,
‘sysmem
’, and
‘thinstrscycles
’.
For example, to sample user stacks every 10 milliseconds, use
‘ustack@10ms
’. To sample thread
scheduling information and system memory every time the
‘0xfeedfac0
’ event is emitted, use
‘thsched,sysmem@D0xfeedfac0
’.
The ktrace
utility exits 0 on
success, and >0 if an error occurs.
Once trace has been initialized with the
init
subcommand (or the
trace
and artrace
subcommands with the -r
flag), it remains in use
until the space is reclaimed with the remove
subcommand. This prevents background diagnostic tools from making use of
trace.
fs_usage(1), notify(3), ktrace(5), and trace(1)
June 1, 2022 | Darwin |