TRACE(1) | General Commands Manual | TRACE(1) |
trace
— record and
modify trace files
trace
record
file-name [options]trace
amend
file-path --add
provider [options]trace
trim
file-name [options]trace
plans
[options]trace
providers
[options]trace
records and modifies files of
software events used for performance analysis. A trace file captures what
the system was doing over a period of time, like which threads are
scheduled, what memory is used for the first time, and thousands of other
kinds of events from software running in the kernel, user space, or on
coprocessors.
Trace files (with the .atrc extension) capture how a Darwin system behaves for a period of time. By default, they include a selection of kdebug trace events, Unified Logging information, and metadata to support analysis, like symbols and machine configuration.
The record
subcommand creates these files
from the current system, according to a plan and options passed in on the
command line. The file-name positional argument is
used as a prefix and can include path components. The path to the file is
derived by adding an incrementing number at the end, followed by the file
extension. To write to a particular file path, end the argument with
‘.atrc
’. The default plan produces
files readable by Instruments System Trace and
spindump(1).
Plans support safe configuration by the user with
‘layers
’ and
‘providers
’. Layers are listed by the
help output for trace
record
and alter basic configuration of the plan, like which events are collected.
Listing providers is not yet implemented, but they add more complex
features, like custom data sources beyond kdebug trace. Unified Logging
support is implemented as a provider, for instance.
This subcommand is opinionated about unsafe operations, and
requires any options that may impact the reliability of the tool to also
include the --unsafe
flag to acknowledge that the
files produced may be unusable. Experimental features are treated similarly,
requiring a --experimental
flag while they are still
being vetted.
--help
| -h
record
subcommand.--plan
trace
plans
.--add
layer-or-providertrace
plans.
The list of
providers can be obtained using trace
providers
.-
-
provider-name:option-name=option-valuetrace
providers
.--omit
layer-or-provider--overwrite
--compress
--notify-after-start
notification-namenotifyutil -1
ktrace-start
’ will wait for the notification named
ktrace-start to be published and then exit. This
option can be specified multiple times to send additional
notifications.--notify-after-end
notification-name--end-after-duration
durations--end-on-notification
notification-name--end-on-kdebug-event
event-id--end-after-kdebug-events-size
size-bytes--trailing-duration
duration--start-on-notification
notification-namenotifyutil -p ktrace-end
’ published
a notification named ktrace-end.--profiling-interval
durationThe following options are unsafe and have a may produce an unusable trace file.
--unsafe
--experimental
--kdebug-buffer-size
size-with-suffix--kdebug-filter-include
filter-descriptionAdditional events may require changes to the buffer size.
--kdebug-filter-exclude
filter-description--prioritize-collection
--collection-priority
. Potentially interferes with
other processes.--collection-priority
trace
amend
adds
more information to previously-recorded trace files from providers.
--add
provider-name--provider-name
:option-name=option-valuetrace
providers
.trace
trim
removes
events from a trace file except for those within a specified time range.
trace
plans
lists
the plans available to trace
record
and the layers that can be added to them.
--verbose
--experimental
trace
providers
lists the providers available to trace
record
and the options that can be passed to
them.
--experimental
The ‘ktrace
’ feature is
supported by two kernel subsystems: kdebug provides the event format and
buffering system and kperf emits sampling information as events based on
triggers.
The event format used by kdebug is simple and constraining, but effective. Events are classified using a 32-bit debug ID:
class subclass code function ╭──────┬───────┬─────────────┬─╮ │ 8 │ 8 │ 14 │2│ ╰──────┴───────┴─────────────┴─╯ ╰──────────────╯ │ class-subclass 00│ ╰──────────────────────────────╯ │ event ID │ ╰──────────────────────────────╯ debug ID
Classes are assigned in
<sys/kdebug.h>
for broad
parts of the system. Each class can assign its own subclasses. The
class-subclass is the finest granularity that can be filtered on. Codes are
for specific events in each subclass, and functions denote whether the event
is a start (DBG_FUNC_START
), end
(DBG_FUNC_END
), or impulse (left unset). An event ID
is a debug ID with the function bits set to 0.
Events also contain a timestamp, 4 pointer-sized arguments, the ID of the thread that emitted the event, and the CPU ID on which it was emitted. The CPU ID may be greater than the number of CPUs on the system — denoting a coprocessor event.
Trace files can be analyzed with dedicated tools, including fs_usage(1), spindump(1), or Instruments, depending on how they were recorded and the filters in effect.
The trace
utility exits 0 on
success, and >0 if an error occurs.
fs_usage(1), notify(3), ktrace(5), and ktrace(1)
December 1, 2023 | Darwin |