1PERF-SCRIPT(1)                    perf Manual                   PERF-SCRIPT(1)
2
3
4

NAME

6       perf-script - Read perf.data (created by perf record) and display trace
7       output
8

SYNOPSIS

10       perf script [<options>]
11       perf script [<options>] record <script> [<record-options>] <command>
12       perf script [<options>] report <script> [script-args]
13       perf script [<options>] <script> <required-script-args> [<record-options>] <command>
14       perf script [<options>] <top-script> [script-args]
15

DESCRIPTION

17       This command reads the input file and displays the trace recorded.
18
19       There are several variants of perf script:
20
21           'perf script' to see a detailed trace of the workload that was
22           recorded.
23
24           You can also run a set of pre-canned scripts that aggregate and
25           summarize the raw trace data in various ways (the list of scripts is
26           available via 'perf script -l').  The following variants allow you to
27           record and run those scripts:
28
29           'perf script record <script> <command>' to record the events required
30           for 'perf script report'.  <script> is the name displayed in the
31           output of 'perf script --list' i.e. the actual script name minus any
32           language extension.  If <command> is not specified, the events are
33           recorded using the -a (system-wide) 'perf record' option.
34
35           'perf script report <script> [args]' to run and display the results
36           of <script>.  <script> is the name displayed in the output of 'perf
37           script --list' i.e. the actual script name minus any language
38           extension.  The perf.data output from a previous run of 'perf script
39           record <script>' is used and should be present for this command to
40           succeed.  [args] refers to the (mainly optional) args expected by
41           the script.
42
43           'perf script <script> <required-script-args> <command>' to both
44           record the events required for <script> and to run the <script>
45           using 'live-mode' i.e. without writing anything to disk.  <script>
46           is the name displayed in the output of 'perf script --list' i.e. the
47           actual script name minus any language extension.  If <command> is
48           not specified, the events are recorded using the -a (system-wide)
49           'perf record' option.  If <script> has any required args, they
50           should be specified before <command>.  This mode doesn't allow for
51           optional script args to be specified; if optional script args are
52           desired, they can be specified using separate 'perf script record'
53           and 'perf script report' commands, with the stdout of the record step
54           piped to the stdin of the report script, using the '-o -' and '-i -'
55           options of the corresponding commands.
56
57           'perf script <top-script>' to both record the events required for
58           <top-script> and to run the <top-script> using 'live-mode'
59           i.e. without writing anything to disk.  <top-script> is the name
60           displayed in the output of 'perf script --list' i.e. the actual
61           script name minus any language extension; a <top-script> is defined
62           as any script name ending with the string 'top'.
63
64           [<record-options>] can be passed to the record steps of 'perf script
65           record' and 'live-mode' variants; this isn't possible however for
66           <top-script> 'live-mode' or 'perf script report' variants.
67
68           See the 'SEE ALSO' section for links to language-specific
69           information on how to write and run your own trace scripts.
70

OPTIONS

72       <command>...
73           Any command you can specify in a shell.
74
75       -D, --dump-raw-trace=
76           Display verbose dump of the trace data.
77
78       --dump-unsorted-raw-trace=
79           Same as --dump-raw-trace but not sorted in time order.
80
81       -L, --Latency=
82           Show latency attributes (irqs/preemption disabled, etc).
83
84       -l, --list=
85           Display a list of available trace scripts.
86
87       -s [lang], --script=
88           Process trace data with the given script ([lang]:script[.ext]). If
89           the string lang is specified in place of a script name, a list of
90           supported languages will be displayed instead.
91
92       -g, --gen-script=
93           Generate perf-script.[ext] starter script for given language, using
94           current perf.data.
95
96       --dlfilter=<file>
97           Filter sample events using the given shared object file. Refer
98           perf-dlfilter(1)
99
100       --dlarg=<arg>
101           Pass arg as an argument to the dlfilter. --dlarg may be repeated to
102           add more arguments.
103
104       --list-dlfilters
105           Display a list of available dlfilters. Use with option -v (must
106           come before option --list-dlfilters) to show long descriptions.
107
108       -a
109           Force system-wide collection. Scripts run without a <command>
110           normally use -a by default, while scripts run with a <command>
111           normally don’t - this option allows the latter to be run in
112           system-wide mode.
113
114       -i, --input=
115           Input file name. (default: perf.data unless stdin is a fifo)
116
117       -d, --debug-mode
118           Do various checks like samples ordering and lost events.
119
120       -F, --fields
121           Comma separated list of fields to print. Options are: comm, tid,
122           pid, time, cpu, event, trace, ip, sym, dso, dsoff, addr, symoff,
123           srcline, period, iregs, uregs, brstack, brstacksym, flags,
124           bpf-output, brstackinsn, brstackinsnlen, brstackoff, callindent,
125           insn, insnlen, synth, phys_addr, metric, misc, srccode, ipc,
126           data_page_size, code_page_size, ins_lat, machine_pid, vcpu, cgroup,
127           retire_lat. Field list can be prepended with the type, trace, sw or
128           hw, to indicate to which event type the field list applies. e.g.,
129           -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace
130
131               perf script -F <fields>
132
133               is equivalent to:
134
135               perf script -F trace:<fields> -F sw:<fields> -F hw:<fields>
136
137               i.e., the specified fields apply to all event types if the type string
138               is not given.
139
140               In addition to overriding fields, it is also possible to add or remove
141               fields from the defaults. For example
142
143               -F -cpu,+insn
144
145               removes the cpu field and adds the insn field. Adding/removing fields
146               cannot be mixed with normal overriding.
147
148               The arguments are processed in the order received. A later usage can
149               reset a prior request. e.g.:
150
151               -F trace: -F comm,tid,time,ip,sym
152
153               The first -F suppresses trace events (field list is ""), but then the
154               second invocation sets the fields to comm,tid,time,ip,sym. In this case a
155               warning is given to the user:
156
157               "Overriding previous field request for all events."
158
159               Alternatively, consider the order:
160
161               -F comm,tid,time,ip,sym -F trace:
162
163               The first -F sets the fields for all events and the second -F
164               suppresses trace events. The user is given a warning message about
165               the override, and the result of the above is that only S/W and H/W
166               events are displayed with the given fields.
167
168               It's possible tp add/remove fields only for specific event type:
169
170               -Fsw:-cpu,-period
171
172               removes cpu and period from software events.
173
174               For the 'wildcard' option if a user selected field is invalid for an
175               event type, a message is displayed to the user that the option is
176               ignored for that type. For example:
177
178               $ perf script -F comm,tid,trace
179               'trace' not valid for hardware events. Ignoring.
180               'trace' not valid for software events. Ignoring.
181
182               Alternatively, if the type is given an invalid field is specified it
183               is an error. For example:
184
185               perf script -v -F sw:comm,tid,trace
186               'trace' not valid for software events.
187
188               At this point usage is displayed, and perf-script exits.
189
190               The flags field is synthesized and may have a value when Instruction
191               Trace decoding. The flags are "bcrosyiABExghDt" which stand for branch,
192               call, return, conditional, system, asynchronous, interrupt,
193               transaction abort, trace begin, trace end, in transaction, VM-Entry,
194               VM-Exit, interrupt disabled and interrupt disable toggle respectively.
195               Known combinations of flags are printed more nicely e.g.
196               "call" for "bc", "return" for "br", "jcc" for "bo", "jmp" for "b",
197               "int" for "bci", "iret" for "bri", "syscall" for "bcs", "sysret" for "brs",
198               "async" for "by", "hw int" for "bcyi", "tx abrt" for "bA", "tr strt" for "bB",
199               "tr end" for "bE", "vmentry" for "bcg", "vmexit" for "bch".
200               However the "x", "D" and "t" flags will be displayed separately in those
201               cases e.g. "jcc     (xD)" for a condition branch within a transaction
202               with interrupts disabled. Note, interrupts becoming disabled is "t",
203               whereas interrupts becoming enabled is "Dt".
204
205               The callindent field is synthesized and may have a value when
206               Instruction Trace decoding. For calls and returns, it will display the
207               name of the symbol indented with spaces to reflect the stack depth.
208
209               When doing instruction trace decoding insn and insnlen give the
210               instruction bytes and the instruction length of the current
211               instruction.
212
213               The synth field is used by synthesized events which may be created when
214               Instruction Trace decoding.
215
216               The ipc (instructions per cycle) field is synthesized and may have a value when
217               Instruction Trace decoding.
218
219               The machine_pid and vcpu fields are derived from data resulting from using
220               perf inject to insert a perf.data file recorded inside a virtual machine into
221               a perf.data file recorded on the host at the same time.
222
223               The cgroup fields requires sample having the cgroup id which is saved
224               when "--all-cgroups" option is passed to 'perf record'.
225
226               Finally, a user may not set fields to none for all event types.
227               i.e., -F "" is not allowed.
228
229               The brstack output includes branch related information with raw addresses using the
230               /v/v/v/v/cycles syntax in the following order:
231               FROM: branch source instruction
232               TO  : branch target instruction
233               M/P/-: M=branch target mispredicted or branch direction was mispredicted, P=target predicted or direction predicted, -=not supported
234               X/- : X=branch inside a transactional region, -=not in transaction region or not supported
235               A/- : A=TSX abort entry, -=not aborted region or not supported
236               cycles
237
238               The brstacksym is identical to brstack, except that the FROM and TO addresses are printed in a symbolic form if possible.
239
240               When brstackinsn is specified the full assembler sequences of branch sequences for each sample
241               is printed. This is the full execution path leading to the sample. This is only supported when the
242               sample was recorded with perf record -b or -j any.
243
244               Use brstackinsnlen to print the brstackinsn lenght. For example, you
245               can’t know the next sequential instruction after an unconditional branch unless
246               you calculate that based on its length.
247
248               The brstackoff field will print an offset into a specific dso/binary.
249
250               With the metric option perf script can compute metrics for
251               sampling periods, similar to perf stat. This requires
252               specifying a group with multiple events defining metrics with the :S option
253               for perf record. perf will sample on the first event, and
254               print computed metrics for all the events in the group. Please note
255               that the metric computed is averaged over the whole sampling
256               period (since the last sample), not just for the sample point.
257
258               For sample events it's possible to display misc field with -F +misc option,
259               following letters are displayed for each bit:
260
261               PERF_RECORD_MISC_KERNEL               K
262               PERF_RECORD_MISC_USER                 U
263               PERF_RECORD_MISC_HYPERVISOR           H
264               PERF_RECORD_MISC_GUEST_KERNEL         G
265               PERF_RECORD_MISC_GUEST_USER           g
266               PERF_RECORD_MISC_MMAP_DATA*           M
267               PERF_RECORD_MISC_COMM_EXEC            E
268               PERF_RECORD_MISC_SWITCH_OUT           S
269               PERF_RECORD_MISC_SWITCH_OUT_PREEMPT   Sp
270
271               $ perf script -F +misc ...
272                sched-messaging  1414 K     28690.636582:       4590 cycles ...
273                sched-messaging  1407 U     28690.636600:     325620 cycles ...
274                sched-messaging  1414 K     28690.636608:      19473 cycles ...
275               misc field ___________/
276
277       -k, --vmlinux=<file>
278           vmlinux pathname
279
280       --kallsyms=<file>
281           kallsyms pathname
282
283       --symfs=<directory>
284           Look for files with symbols relative to this directory.
285
286       -G, --hide-call-graph
287           When printing symbols do not display call chain.
288
289       --stop-bt
290           Stop display of callgraph at these symbols
291
292       -C, --cpu
293           Only report samples for the list of CPUs provided. Multiple CPUs
294           can be provided as a comma-separated list with no space: 0,1.
295           Ranges of CPUs are specified with -: 0-2. Default is to report
296           samples on all CPUs.
297
298       -c, --comms=
299           Only display events for these comms. CSV that understands
300           file://filename entries.
301
302       --pid=
303           Only show events for given process ID (comma separated list).
304
305       --tid=
306           Only show events for given thread ID (comma separated list).
307
308       -I, --show-info
309           Display extended information about the perf.data file. This adds
310           information which may be very large and thus may clutter the
311           display. It currently includes: cpu and numa topology of the host
312           system. It can only be used with the perf script report mode.
313
314       --show-kernel-path
315           Try to resolve the path of [kernel.kallsyms]
316
317       --show-task-events Display task related events (e.g. FORK, COMM, EXIT).
318
319       --show-mmap-events Display mmap related events (e.g. MMAP, MMAP2).
320
321       --show-namespace-events Display namespace events i.e. events of type
322       PERF_RECORD_NAMESPACES.
323
324       --show-switch-events Display context switch events i.e. events of type
325       PERF_RECORD_SWITCH or PERF_RECORD_SWITCH_CPU_WIDE.
326
327       --show-lost-events Display lost events i.e. events of type
328       PERF_RECORD_LOST.
329
330       --show-round-events Display finished round events i.e. events of type
331       PERF_RECORD_FINISHED_ROUND.
332
333       --show-bpf-events Display bpf events i.e. events of type
334       PERF_RECORD_KSYMBOL and PERF_RECORD_BPF_EVENT.
335
336       --show-cgroup-events Display cgroup events i.e. events of type
337       PERF_RECORD_CGROUP.
338
339       --show-text-poke-events Display text poke events i.e. events of type
340       PERF_RECORD_TEXT_POKE and PERF_RECORD_KSYMBOL.
341
342       --demangle
343           Demangle symbol names to human readable form. It’s enabled by
344           default, disable with --no-demangle.
345
346       --demangle-kernel
347           Demangle kernel symbol names to human readable form (for C++
348           kernels).
349
350       --header Show perf.data header.
351
352       --header-only Show only perf.data header.
353
354       --itrace
355           Options for decoding instruction tracing data. The options are:
356
357               i       synthesize instructions events
358               y       synthesize cycles events
359               b       synthesize branches events (branch misses for Arm SPE)
360               c       synthesize branches events (calls only)
361               r       synthesize branches events (returns only)
362               x       synthesize transactions events
363               w       synthesize ptwrite events
364               p       synthesize power events (incl. PSB events for Intel PT)
365               o       synthesize other events recorded due to the use
366                       of aux-output (refer to perf record)
367               I       synthesize interrupt or similar (asynchronous) events
368                       (e.g. Intel PT Event Trace)
369               e       synthesize error events
370               d       create a debug log
371               f       synthesize first level cache events
372               m       synthesize last level cache events
373               M       synthesize memory events
374               t       synthesize TLB events
375               a       synthesize remote access events
376               g       synthesize a call chain (use with i or x)
377               G       synthesize a call chain on existing event records
378               l       synthesize last branch entries (use with i or x)
379               L       synthesize last branch entries on existing event records
380               s       skip initial number of events
381               q       quicker (less detailed) decoding
382               A       approximate IPC
383               Z       prefer to ignore timestamps (so-called "timeless" decoding)
384
385               The default is all events i.e. the same as --itrace=iybxwpe,
386               except for perf script where it is --itrace=ce
387
388               In addition, the period (default 100000, except for perf script where it is 1)
389               for instructions events can be specified in units of:
390
391               i       instructions
392               t       ticks
393               ms      milliseconds
394               us      microseconds
395               ns      nanoseconds (default)
396
397               Also the call chain size (default 16, max. 1024) for instructions or
398               transactions events can be specified.
399
400               Also the number of last branch entries (default 64, max. 1024) for
401               instructions or transactions events can be specified.
402
403               Similar to options g and l, size may also be specified for options G and L.
404               On x86, note that G and L work poorly when data has been recorded with
405               large PEBS. Refer linkperf:perf-intel-pt[1] man page for details.
406
407               It is also possible to skip events generated (instructions, branches, transactions,
408               ptwrite, power) at the beginning. This is useful to ignore initialization code.
409
410               --itrace=i0nss1000000
411
412               skips the first million instructions.
413
414               The 'e' option may be followed by flags which affect what errors will or
415               will not be reported. Each flag must be preceded by either '+' or '-'.
416               The flags are:
417                       o       overflow
418                       l       trace data lost
419
420               If supported, the 'd' option may be followed by flags which affect what
421               debug messages will or will not be logged. Each flag must be preceded
422               by either '+' or '-'. The flags are:
423                       a       all perf events
424                       e       output only on errors (size configurable - see linkperf:perf-config[1])
425                       o       output to stdout
426
427               If supported, the 'q' option may be repeated to increase the effect.
428
429               To disable decoding entirely, use --no-itrace.
430
431       --full-source-path
432           Show the full path for source files for srcline output.
433
434       --max-stack
435           Set the stack depth limit when parsing the callchain, anything
436           beyond the specified depth will be ignored. This is a trade-off
437           between information loss and faster processing especially for
438           workloads that can have a very long callchain stack. Note that when
439           using the --itrace option the synthesized callchain size will
440           override this value if the synthesized callchain size is bigger.
441
442               Default: 127
443
444       --ns
445           Use 9 decimal places when displaying time (i.e. show the
446           nanoseconds)
447
448       -f, --force
449           Don’t do ownership validation.
450
451       --time
452           Only analyze samples within given time window: <start>,<stop>.
453           Times have the format seconds.nanoseconds. If start is not given
454           (i.e. time string is ,x.y) then analysis starts at the beginning of
455           the file. If stop time is not given (i.e. time string is x.y,) then
456           analysis goes to end of file. Multiple ranges can be separated by
457           spaces, which requires the argument to be quoted e.g. --time
458           "1234.567,1234.789 1235,"
459
460               Also support time percent with multiple time ranges. Time string is
461               'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'.
462
463               For example:
464               Select the second 10% time slice:
465               perf script --time 10%/2
466
467               Select from 0% to 10% time slice:
468               perf script --time 0%-10%
469
470               Select the first and second 10% time slices:
471               perf script --time 10%/1,10%/2
472
473               Select from 0% to 10% and 30% to 40% slices:
474               perf script --time 0%-10%,30%-40%
475
476       --max-blocks
477           Set the maximum number of program blocks to print with brstackinsn
478           for each sample.
479
480       --reltime
481           Print time stamps relative to trace start.
482
483       --deltatime
484           Print time stamps relative to previous event.
485
486       --per-event-dump
487           Create per event files with a "perf.data.EVENT.dump" name instead
488           of printing to stdout, useful, for instance, for generating
489           flamegraphs.
490
491       --inline
492           If a callgraph address belongs to an inlined function, the inline
493           stack will be printed. Each entry has function name and file/line.
494           Enabled by default, disable with --no-inline.
495
496       --insn-trace
497           Show instruction stream for intel_pt traces. Combine with --xed to
498           show disassembly.
499
500       --xed
501           Run xed disassembler on output. Requires installing the xed
502           disassembler.
503
504       -S, --symbols=symbol[,symbol...]
505           Only consider the listed symbols. Symbols are typically a name but
506           they may also be hexadecimal address.
507
508               The hexadecimal address may be the start address of a symbol or
509               any other address to filter the trace records
510
511               For example, to select the symbol noploop or the address 0x4007a0:
512               perf script --symbols=noploop,0x4007a0
513
514               Support filtering trace records by symbol name, start address of
515               symbol, any hexadecimal address and address range.
516
517               The comparison order is:
518
519            1. symbol name comparison
520
521            2. symbol start address comparison.
522
523            3. any hexadecimal address comparison.
524
525            4. address range comparison (see --addr-range).
526
527       --addr-range
528           Use with -S or --symbols to list traced records within address
529           range.
530
531               For example, to list the traced records within the address range
532               [0x4007a0, 0x0x4007a9]:
533               perf script -S 0x4007a0 --addr-range 10
534
535       --dsos=
536           Only consider symbols in these DSOs.
537
538       --call-trace
539           Show call stream for intel_pt traces. The CPUs are interleaved, but
540           can be filtered with -C.
541
542       --call-ret-trace
543           Show call and return stream for intel_pt traces.
544
545       --graph-function
546           For itrace only show specified functions and their callees for
547           itrace. Multiple functions can be separated by comma.
548
549       --switch-on EVENT_NAME
550           Only consider events after this event is found.
551
552       --switch-off EVENT_NAME
553           Stop considering events after this event is found.
554
555       --show-on-off-events
556           Show the --switch-on/off events too.
557
558       --stitch-lbr
559           Show callgraph with stitched LBRs, which may have more complete
560           callgraph. The perf.data file must have been obtained using perf
561           record --call-graph lbr. Disabled by default. In common cases with
562           call stack overflows, it can recreate better call stacks than the
563           default lbr call stack output. But this approach is not foolproof.
564           There can be cases where it creates incorrect call stacks from
565           incorrect matches. The known limitations include exception handing
566           such as setjmp/longjmp will have calls/returns not match.
567
568       --guestmount=<path>
569           Guest OS root file system mount directory. Users mount guest OS
570           root directories under <path> by a specific filesystem access
571           method, typically, sshfs. For example, start 2 guest OS, one’s pid
572           is 8888 and the other’s is 9999:
573
574               $ mkdir ~/guestmount
575               $ cd ~/guestmount
576               $ sshfs -o allow_other,direct_io -p 5551 localhost:/ 8888/
577               $ sshfs -o allow_other,direct_io -p 5552 localhost:/ 9999/
578               $ perf script --guestmount=~/guestmount
579
580       --guestkallsyms=<path>
581           Guest OS /proc/kallsyms file copy. perf reads it to get guest
582           kernel symbols. Users copy it out from guest OS.
583
584       --guestmodules=<path>
585           Guest OS /proc/modules file copy. perf reads it to get guest kernel
586           module information. Users copy it out from guest OS.
587
588       --guestvmlinux=<path>
589           Guest OS kernel vmlinux.
590
591       --guest-code
592           Indicate that guest code can be found in the hypervisor process,
593           which is a common case for KVM test programs.
594

SEE ALSO

596       perf-record(1), perf-script-perl(1), perf-script-python(1), perf-intel-
597       pt(1), perf-dlfilter(1)
598
599
600
601perf                              11/28/2023                    PERF-SCRIPT(1)
Impressum