1 .\" Copyright (c) 2010, Apple Inc. All rights reserved.
8 .Nd configure, record, and display kernel trace events
10 .Bl -hang -compact -width "trace -"
13 .Op Fl a Ar pid | Fl x Ar pid
16 .Op Fl c Ar class Oo Fl p Ar end-class Oc Oo Fl s Ar subclass Oc
17 .Op Fl a Ar pid | Fl x Ar pid
20 .Op Fl T Ar filter-file
23 .Op Fl c Ar class Oo Fl p Ar end-class Oc Oo Fl s Ar subclass Oc
24 .Op Fl a Ar pid | Fl x Ar pid
27 .Op Fl T Ar tracefilter
34 .Op Fl b Ar num-events
38 .It Nm Fl l Ar rawfile
40 .It Nm Fl L Ar rawfile
47 .It Nm Fl R Ar rawfile
61 initializes and configures the kernel trace subsystem. Trace events can
62 be recorded to an in-memory buffer or logged directly to a file, and
63 optionally converted to a human-readable, plain-text format.
66 operates according to the command flag specified.
70 is obsolete. The command you probably want is
75 Print a succinct help message to
79 .It Fl i Op Fl b Ar num-events
81 Initialize the kernel trace buffer. This command is required before
84 .It Fl b Ar num-events
85 Set the number of events that can be stored in the kernel trace buffer.
87 is a decimal number of events. The default (and minimum) value is 8192
88 event records per logical CPU. No more than half of available
89 memory may be used by trace buffers, though running with a buffer this
90 large is not recommended.
95 Print the current kernel trace buffer settings to
99 .It Fl d Op Fl a Ar pid | Fl x Ar pid
101 By default, disable collection of events. This command does not remove
102 the kernel trace buffer.
105 Disable event collection for the process identified by
111 This reenables event collection of events for.
117 Remove the kernel trace buffer.
121 Disable ring buffer mode. When set, the trace buffer will fill to capacity
122 and then stop collecting events. Ring buffer mode is sometimes called
123 "head," "stop," or "no-wrap" mode. By default, the trace buffer will
124 wrap around, overwriting previous events. The default behavior is
125 sometimes called windowed or wrap-around mode.
130 .Op Fl c Ar class Oo Fl p Ar end-class Oc Oo Fl s Ar subclass Oc
131 .Op Fl a Ar pid | Fl x Ar pid
134 .Op Fl T Ar filter-file
138 Enable collection of events. By default, all events are collected.
140 Options can be used to restrict collection to specific classes, class
141 ranges, subclasses, and codes. Classes and subclasses can be specified
142 any number of times, but only 4 codes can be filtered at once. Values
143 can be specified in hex (0x...), decimal, or octal (0...).
146 Restrict collection to the events with the specified
148 This option can be specified any number of times to collect events from
151 .It Fl p Ar end-class
152 Provide an ending class to restrict collection to events in an inclusive
153 range of classes between
158 Restrict collection to the events with the specified
162 Restrict collection to to those events emitted by the process identified
166 Exclude events emitted by the process identified by
169 Restrict collection to events with the specified
171 This option can be specified up to 4 times, and applies to all classes
173 .It Fl T Ar filter-file
174 Restrict collection to events specified in the provided
177 .Sx TRACEFILTER FORMAT
180 Restrict collection to PPT events. This special collection of trace
181 events provides insight into system performance.
188 .Op Fl c Ar class Oo Fl p Ar end-class Oc Oo Fl s Ar subclass Oc
189 .Op Fl a Ar pid | Fl x Ar pid
192 .Op Fl T Ar filter-file
193 .Ar command Op args ...
199 with trace collection enabled for events emitted by the process. See
201 for more information.
204 .It Fl t Oo Fl o Ar outfile Oc Oo Fl N Oc Oo Ar codesfile ... Oc
206 Extract events from the kernel trace buffer and print them in a formatted,
207 plain-text representation. Additional code files can be specified to
210 find the names of unknown events. For more information on the formatting
212 .Sx TRACE CODES FORMAT .
215 Output the plain-text events to
218 Ignore the system-wide trace codes file when getting names of events.
219 Additional trace codes files specified will still be used.
225 Empty the current kernel trace buffer into
227 in a binary format. If
231 the file will be written to
235 .It Fl L Ar rawfile Fl S Ar seconds
237 Copy the current trace buffer to
239 and send all future trace events to
245 have elapsed, stop recording and exit. If
249 the file will be written to
254 .It Fl R Ar rawfile Oo Fl o Ar outfile Oc Oo Fl N Oc Oo Fl F Ar frequency Oc Oo Fl X Oc Op Ar codesfile ...
258 and print them in a human-readable format.
260 .It Fl F Ar frequency
263 does not contain clock frequency information, it can be specified with
266 Force the binary format to be interpreted as 32-bit, as opposed to
267 matching the width of the system running
273 for additional options.
275 .Sh TRACE CODES FORMAT
276 Event classes, subclasses, and codes are matched to names using a trace
277 codes file. Any events that cannot be matched will be referred to by
278 their debugid in hex.
280 The system-wide trace codes file is located at
281 .Pa /usr/share/misc/trace.codes .
282 Additional files are typically stored in
283 .Pa /usr/local/share/misc .
285 A code file consists of a list of tracepoints, one per line, with the
286 tracepoint's debugid (component, subclass, and code) in hex, followed by
287 a tab, followed by the tracepoint's name.
289 For instance, the MSC_mach_msg_trap tracepoint is defined by
291 .Dl 0x010c007c MSC_mach_msg_trap
293 This describes the tracepoint with the following info:
295 .Bl -column -offset indent "Subclass" "MSC_mach_msg_trap"
296 .\" is this right? We should refer to the shifting and kdebug.h
297 .It Sy Name Ta MSC_mach_msg_trap
298 .It Sy Class Ta 0x01 Ta (Mach events)
299 .It Sy Subclass Ta 0x0c Ta (Mach system calls)
300 .It Sy Code Ta 0x007c Ta (msg_trap)
304 .\" this absolute path no longer exists thanks to SDKs. :P
305 .Pa /usr/include/sys/kdebug.h
306 for class and subclass values.
307 .Sh TRACEFILTER FORMAT
308 A tracefilter description file consists of a list of class and subclass
309 filters in hex, one per line, which are applied as if they were passed
316 to see what classes and subclasses are being set.
318 Comment lines start with
320 class filter lines start with
322 and subclass filter lines start with
324 and include the class they apply to.
326 For example, to trace Mach events (class 1):
330 And to trace Mach system calls (class 1, subclass 13):
336 usually requires multiple invocations in order to set up the trace
337 buffers, enable the correct events, and collect the events. A typical
338 session with trace is:
341 .Dl trace -e -c 1 -s 31
346 This initializes the trace buffers to their default values, enables the
347 mach_msg_trap subclass of the MACH_SysCall class, waits for one second,
348 then disables tracing and prints it to
350 This is useful for investigating isolated issues or gaining some
351 understanding about a kernel subsystem. If a specific execuable should
352 be traced, with the events saved for later analysis, the sequence of
356 .Dl trace -E -c 0x4 ./my_prog
358 .Dl trace -l tracefile
359 .Dl trace -R tracefile
361 This initializes the trace buffers, enables all events in the BSC_SysCall class and runs
363 disables tracing, collects events into
365 and finally prints those events out in a human-readable form.
369 command flags require superuser (root) privileges.
371 After failures, the trace buffers usually need to be re-initialized.