perf-script.txt 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. perf-script(1)
  2. =============
  3. NAME
  4. ----
  5. perf-script - Read perf.data (created by perf record) and display trace output
  6. SYNOPSIS
  7. --------
  8. [verse]
  9. 'perf script' [<options>]
  10. 'perf script' [<options>] record <script> [<record-options>] <command>
  11. 'perf script' [<options>] report <script> [script-args]
  12. 'perf script' [<options>] <script> <required-script-args> [<record-options>] <command>
  13. 'perf script' [<options>] <top-script> [script-args]
  14. DESCRIPTION
  15. -----------
  16. This command reads the input file and displays the trace recorded.
  17. There are several variants of perf script:
  18. 'perf script' to see a detailed trace of the workload that was
  19. recorded.
  20. You can also run a set of pre-canned scripts that aggregate and
  21. summarize the raw trace data in various ways (the list of scripts is
  22. available via 'perf script -l'). The following variants allow you to
  23. record and run those scripts:
  24. 'perf script record <script> <command>' to record the events required
  25. for 'perf script report'. <script> is the name displayed in the
  26. output of 'perf script --list' i.e. the actual script name minus any
  27. language extension. If <command> is not specified, the events are
  28. recorded using the -a (system-wide) 'perf record' option.
  29. 'perf script report <script> [args]' to run and display the results
  30. of <script>. <script> is the name displayed in the output of 'perf
  31. script --list' i.e. the actual script name minus any language
  32. extension. The perf.data output from a previous run of 'perf script
  33. record <script>' is used and should be present for this command to
  34. succeed. [args] refers to the (mainly optional) args expected by
  35. the script.
  36. 'perf script <script> <required-script-args> <command>' to both
  37. record the events required for <script> and to run the <script>
  38. using 'live-mode' i.e. without writing anything to disk. <script>
  39. is the name displayed in the output of 'perf script --list' i.e. the
  40. actual script name minus any language extension. If <command> is
  41. not specified, the events are recorded using the -a (system-wide)
  42. 'perf record' option. If <script> has any required args, they
  43. should be specified before <command>. This mode doesn't allow for
  44. optional script args to be specified; if optional script args are
  45. desired, they can be specified using separate 'perf script record'
  46. and 'perf script report' commands, with the stdout of the record step
  47. piped to the stdin of the report script, using the '-o -' and '-i -'
  48. options of the corresponding commands.
  49. 'perf script <top-script>' to both record the events required for
  50. <top-script> and to run the <top-script> using 'live-mode'
  51. i.e. without writing anything to disk. <top-script> is the name
  52. displayed in the output of 'perf script --list' i.e. the actual
  53. script name minus any language extension; a <top-script> is defined
  54. as any script name ending with the string 'top'.
  55. [<record-options>] can be passed to the record steps of 'perf script
  56. record' and 'live-mode' variants; this isn't possible however for
  57. <top-script> 'live-mode' or 'perf script report' variants.
  58. See the 'SEE ALSO' section for links to language-specific
  59. information on how to write and run your own trace scripts.
  60. OPTIONS
  61. -------
  62. <command>...::
  63. Any command you can specify in a shell.
  64. -D::
  65. --dump-raw-trace=::
  66. Display verbose dump of the trace data.
  67. --dump-unsorted-raw-trace=::
  68. Same as --dump-raw-trace but not sorted in time order.
  69. -L::
  70. --Latency=::
  71. Show latency attributes (irqs/preemption disabled, etc).
  72. -l::
  73. --list=::
  74. Display a list of available trace scripts.
  75. -s ['lang']::
  76. --script=::
  77. Process trace data with the given script ([lang]:script[.ext]).
  78. If the string 'lang' is specified in place of a script name, a
  79. list of supported languages will be displayed instead.
  80. -g::
  81. --gen-script=::
  82. Generate a starter script. If a language is given then the
  83. script is named perf-script.[ext] according to the
  84. language. If a file path is given then python is used for
  85. files ending '.py' and perl used for files ending '.pl'.
  86. --dlfilter=<file>::
  87. Filter sample events using the given shared object file.
  88. Refer linkperf:perf-dlfilter[1]
  89. --dlarg=<arg>::
  90. Pass 'arg' as an argument to the dlfilter. --dlarg may be repeated
  91. to add more arguments.
  92. --list-dlfilters::
  93. Display a list of available dlfilters. Use with option -v (must come
  94. before option --list-dlfilters) to show long descriptions.
  95. -a::
  96. Force system-wide collection. Scripts run without a <command>
  97. normally use -a by default, while scripts run with a <command>
  98. normally don't - this option allows the latter to be run in
  99. system-wide mode.
  100. -i::
  101. --input=::
  102. Input file name. (default: perf.data unless stdin is a fifo)
  103. -d::
  104. --debug-mode::
  105. Do various checks like samples ordering and lost events.
  106. -F::
  107. --fields::
  108. Comma separated list of fields to print. Options are:
  109. comm, tid, pid, time, cpu, event, trace, ip, sym, dso, dsoff, addr, symoff,
  110. srcline, period, iregs, uregs, brstack, brstacksym, flags, bpf-output,
  111. brstackinsn, brstackinsnlen, brstackdisasm, brstackoff, callindent, insn, disasm,
  112. insnlen, synth, phys_addr, metric, misc, srccode, ipc, data_page_size,
  113. code_page_size, ins_lat, machine_pid, vcpu, cgroup, retire_lat, brcntr,
  114. Field list can be prepended with the type, trace, sw or hw,
  115. to indicate to which event type the field list applies.
  116. e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace
  117. perf script -F <fields>
  118. is equivalent to:
  119. perf script -F trace:<fields> -F sw:<fields> -F hw:<fields>
  120. i.e., the specified fields apply to all event types if the type string
  121. is not given.
  122. In addition to overriding fields, it is also possible to add or remove
  123. fields from the defaults. For example
  124. -F -cpu,+insn
  125. removes the cpu field and adds the insn field. Adding/removing fields
  126. cannot be mixed with normal overriding.
  127. The arguments are processed in the order received. A later usage can
  128. reset a prior request. e.g.:
  129. -F trace: -F comm,tid,time,ip,sym
  130. The first -F suppresses trace events (field list is ""), but then the
  131. second invocation sets the fields to comm,tid,time,ip,sym. In this case a
  132. warning is given to the user:
  133. "Overriding previous field request for all events."
  134. Alternatively, consider the order:
  135. -F comm,tid,time,ip,sym -F trace:
  136. The first -F sets the fields for all events and the second -F
  137. suppresses trace events. The user is given a warning message about
  138. the override, and the result of the above is that only S/W and H/W
  139. events are displayed with the given fields.
  140. It's possible tp add/remove fields only for specific event type:
  141. -Fsw:-cpu,-period
  142. removes cpu and period from software events.
  143. For the 'wildcard' option if a user selected field is invalid for an
  144. event type, a message is displayed to the user that the option is
  145. ignored for that type. For example:
  146. $ perf script -F comm,tid,trace
  147. 'trace' not valid for hardware events. Ignoring.
  148. 'trace' not valid for software events. Ignoring.
  149. Alternatively, if the type is given an invalid field is specified it
  150. is an error. For example:
  151. perf script -v -F sw:comm,tid,trace
  152. 'trace' not valid for software events.
  153. At this point usage is displayed, and perf-script exits.
  154. The flags field is synthesized and may have a value when Instruction
  155. Trace decoding. The flags are "bcrosyiABExghDt" which stand for branch,
  156. call, return, conditional, system, asynchronous, interrupt,
  157. transaction abort, trace begin, trace end, in transaction, VM-Entry,
  158. VM-Exit, interrupt disabled and interrupt disable toggle respectively.
  159. Known combinations of flags are printed more nicely e.g.
  160. "call" for "bc", "return" for "br", "jcc" for "bo", "jmp" for "b",
  161. "int" for "bci", "iret" for "bri", "syscall" for "bcs", "sysret" for "brs",
  162. "async" for "by", "hw int" for "bcyi", "tx abrt" for "bA", "tr strt" for "bB",
  163. "tr end" for "bE", "vmentry" for "bcg", "vmexit" for "bch".
  164. However the "x", "D" and "t" flags will be displayed separately in those
  165. cases e.g. "jcc (xD)" for a condition branch within a transaction
  166. with interrupts disabled. Note, interrupts becoming disabled is "t",
  167. whereas interrupts becoming enabled is "Dt".
  168. The callindent field is synthesized and may have a value when
  169. Instruction Trace decoding. For calls and returns, it will display the
  170. name of the symbol indented with spaces to reflect the stack depth.
  171. When doing instruction trace decoding, insn, disasm and insnlen give the
  172. instruction bytes, disassembled instructions (requires libcapstone support)
  173. and the instruction length of the current instruction respectively.
  174. The synth field is used by synthesized events which may be created when
  175. Instruction Trace decoding.
  176. The ipc (instructions per cycle) field is synthesized and may have a value when
  177. Instruction Trace decoding.
  178. The machine_pid and vcpu fields are derived from data resulting from using
  179. perf inject to insert a perf.data file recorded inside a virtual machine into
  180. a perf.data file recorded on the host at the same time.
  181. The cgroup fields requires sample having the cgroup id which is saved
  182. when "--all-cgroups" option is passed to 'perf record'.
  183. Finally, a user may not set fields to none for all event types.
  184. i.e., -F "" is not allowed.
  185. The brstack output includes branch related information with raw addresses using the
  186. FROM/TO/EVENT/INTX/ABORT/CYCLES/TYPE/SPEC syntax in the following order:
  187. FROM : branch source instruction
  188. TO : branch target instruction
  189. EVENT : M=branch target or direction was mispredicted
  190. P=branch target or direction was predicted
  191. N=branch not-taken
  192. -=no event or not supported
  193. INTX : X=branch inside a transactional region
  194. -=branch not in transaction region or not supported
  195. ABORT : A=TSX abort entry
  196. -=not aborted region or not supported
  197. CYCLES: the number of cycles that have elapsed since the last branch was recorded
  198. TYPE : branch type: COND/UNCOND/IND/CALL/IND_CALL/RET etc.
  199. -=not supported
  200. SPEC : branch speculation info: SPEC_WRONG_PATH/NON_SPEC_CORRECT_PATH/SPEC_CORRECT_PATH
  201. -=not supported
  202. The brstacksym is identical to brstack, except that the FROM and TO addresses are printed in a symbolic form if possible.
  203. When brstackinsn is specified the full assembler sequences of branch sequences for each sample
  204. is printed. This is the full execution path leading to the sample. This is only supported when the
  205. sample was recorded with perf record -b or -j any.
  206. Use brstackinsnlen to print the brstackinsn lenght. For example, you
  207. can’t know the next sequential instruction after an unconditional branch unless
  208. you calculate that based on its length.
  209. brstackdisasm acts like brstackinsn, but will print disassembled instructions if
  210. perf is built with the capstone library.
  211. The brstackoff field will print an offset into a specific dso/binary.
  212. With the metric option perf script can compute metrics for
  213. sampling periods, similar to perf stat. This requires
  214. specifying a group with multiple events defining metrics with the :S option
  215. for perf record. perf will sample on the first event, and
  216. print computed metrics for all the events in the group. Please note
  217. that the metric computed is averaged over the whole sampling
  218. period (since the last sample), not just for the sample point.
  219. For sample events it's possible to display misc field with -F +misc option,
  220. following letters are displayed for each bit:
  221. PERF_RECORD_MISC_KERNEL K
  222. PERF_RECORD_MISC_USER U
  223. PERF_RECORD_MISC_HYPERVISOR H
  224. PERF_RECORD_MISC_GUEST_KERNEL G
  225. PERF_RECORD_MISC_GUEST_USER g
  226. PERF_RECORD_MISC_MMAP_DATA* M
  227. PERF_RECORD_MISC_COMM_EXEC E
  228. PERF_RECORD_MISC_SWITCH_OUT S
  229. PERF_RECORD_MISC_SWITCH_OUT_PREEMPT Sp
  230. $ perf script -F +misc ...
  231. sched-messaging 1414 K 28690.636582: 4590 cycles ...
  232. sched-messaging 1407 U 28690.636600: 325620 cycles ...
  233. sched-messaging 1414 K 28690.636608: 19473 cycles ...
  234. misc field ___________/
  235. -k::
  236. --vmlinux=<file>::
  237. vmlinux pathname
  238. --kallsyms=<file>::
  239. kallsyms pathname
  240. --symfs=<directory>::
  241. Look for files with symbols relative to this directory.
  242. -G::
  243. --hide-call-graph::
  244. When printing symbols do not display call chain.
  245. --stop-bt::
  246. Stop display of callgraph at these symbols
  247. -C::
  248. --cpu:: Only report samples for the list of CPUs provided. Multiple CPUs can
  249. be provided as a comma-separated list with no space: 0,1. Ranges of
  250. CPUs are specified with -: 0-2. Default is to report samples on all
  251. CPUs.
  252. -c::
  253. --comms=::
  254. Only display events for these comms. CSV that understands
  255. file://filename entries.
  256. --pid=::
  257. Only show events for given process ID (comma separated list).
  258. --tid=::
  259. Only show events for given thread ID (comma separated list).
  260. -I::
  261. --show-info::
  262. Display extended information about the perf.data file. This adds
  263. information which may be very large and thus may clutter the display.
  264. It currently includes: cpu and numa topology of the host system.
  265. It can only be used with the perf script report mode.
  266. --show-kernel-path::
  267. Try to resolve the path of [kernel.kallsyms]
  268. --show-task-events
  269. Display task related events (e.g. FORK, COMM, EXIT).
  270. --show-mmap-events
  271. Display mmap related events (e.g. MMAP, MMAP2).
  272. --show-namespace-events
  273. Display namespace events i.e. events of type PERF_RECORD_NAMESPACES.
  274. --show-switch-events
  275. Display context switch events i.e. events of type PERF_RECORD_SWITCH or
  276. PERF_RECORD_SWITCH_CPU_WIDE.
  277. --show-lost-events
  278. Display lost events i.e. events of type PERF_RECORD_LOST.
  279. --show-round-events
  280. Display finished round events i.e. events of type PERF_RECORD_FINISHED_ROUND.
  281. --show-bpf-events
  282. Display bpf events i.e. events of type PERF_RECORD_KSYMBOL and PERF_RECORD_BPF_EVENT.
  283. --show-cgroup-events
  284. Display cgroup events i.e. events of type PERF_RECORD_CGROUP.
  285. --show-text-poke-events
  286. Display text poke events i.e. events of type PERF_RECORD_TEXT_POKE and
  287. PERF_RECORD_KSYMBOL.
  288. --demangle::
  289. Demangle symbol names to human readable form. It's enabled by default,
  290. disable with --no-demangle.
  291. --demangle-kernel::
  292. Demangle kernel symbol names to human readable form (for C++ kernels).
  293. --addr2line=<path>::
  294. Path to addr2line binary.
  295. --header
  296. Show perf.data header.
  297. --header-only
  298. Show only perf.data header.
  299. --itrace::
  300. Options for decoding instruction tracing data. The options are:
  301. include::itrace.txt[]
  302. To disable decoding entirely, use --no-itrace.
  303. --full-source-path::
  304. Show the full path for source files for srcline output.
  305. --max-stack::
  306. Set the stack depth limit when parsing the callchain, anything
  307. beyond the specified depth will be ignored. This is a trade-off
  308. between information loss and faster processing especially for
  309. workloads that can have a very long callchain stack.
  310. Note that when using the --itrace option the synthesized callchain size
  311. will override this value if the synthesized callchain size is bigger.
  312. Default: 127
  313. --ns::
  314. Use 9 decimal places when displaying time (i.e. show the nanoseconds)
  315. -f::
  316. --force::
  317. Don't do ownership validation.
  318. --time::
  319. Only analyze samples within given time window: <start>,<stop>. Times
  320. have the format seconds.nanoseconds. If start is not given (i.e. time
  321. string is ',x.y') then analysis starts at the beginning of the file. If
  322. stop time is not given (i.e. time string is 'x.y,') then analysis goes
  323. to end of file. Multiple ranges can be separated by spaces, which
  324. requires the argument to be quoted e.g. --time "1234.567,1234.789 1235,"
  325. Also support time percent with multiple time ranges. Time string is
  326. 'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'.
  327. For example:
  328. Select the second 10% time slice:
  329. perf script --time 10%/2
  330. Select from 0% to 10% time slice:
  331. perf script --time 0%-10%
  332. Select the first and second 10% time slices:
  333. perf script --time 10%/1,10%/2
  334. Select from 0% to 10% and 30% to 40% slices:
  335. perf script --time 0%-10%,30%-40%
  336. --max-blocks::
  337. Set the maximum number of program blocks to print with brstackinsn for
  338. each sample.
  339. --reltime::
  340. Print time stamps relative to trace start.
  341. --deltatime::
  342. Print time stamps relative to previous event.
  343. --per-event-dump::
  344. Create per event files with a "perf.data.EVENT.dump" name instead of
  345. printing to stdout, useful, for instance, for generating flamegraphs.
  346. --inline::
  347. If a callgraph address belongs to an inlined function, the inline stack
  348. will be printed. Each entry has function name and file/line. Enabled by
  349. default, disable with --no-inline.
  350. --insn-trace[=<raw|disasm>]::
  351. Show instruction stream in bytes (raw) or disassembled (disasm)
  352. for intel_pt traces. The default is 'raw'. To use xed, combine
  353. 'raw' with --xed to show disassembly done by xed.
  354. --xed::
  355. Run xed disassembler on output. Requires installing the xed disassembler.
  356. -S::
  357. --symbols=symbol[,symbol...]::
  358. Only consider the listed symbols. Symbols are typically a name
  359. but they may also be hexadecimal address.
  360. The hexadecimal address may be the start address of a symbol or
  361. any other address to filter the trace records
  362. For example, to select the symbol noploop or the address 0x4007a0:
  363. perf script --symbols=noploop,0x4007a0
  364. Support filtering trace records by symbol name, start address of
  365. symbol, any hexadecimal address and address range.
  366. The comparison order is:
  367. 1. symbol name comparison
  368. 2. symbol start address comparison.
  369. 3. any hexadecimal address comparison.
  370. 4. address range comparison (see --addr-range).
  371. --addr-range::
  372. Use with -S or --symbols to list traced records within address range.
  373. For example, to list the traced records within the address range
  374. [0x4007a0, 0x0x4007a9]:
  375. perf script -S 0x4007a0 --addr-range 10
  376. --dsos=::
  377. Only consider symbols in these DSOs.
  378. --call-trace::
  379. Show call stream for intel_pt traces. The CPUs are interleaved, but
  380. can be filtered with -C.
  381. --call-ret-trace::
  382. Show call and return stream for intel_pt traces.
  383. --graph-function::
  384. For itrace only show specified functions and their callees for
  385. itrace. Multiple functions can be separated by comma.
  386. --switch-on EVENT_NAME::
  387. Only consider events after this event is found.
  388. --switch-off EVENT_NAME::
  389. Stop considering events after this event is found.
  390. --show-on-off-events::
  391. Show the --switch-on/off events too.
  392. --stitch-lbr::
  393. Show callgraph with stitched LBRs, which may have more complete
  394. callgraph. The perf.data file must have been obtained using
  395. perf record --call-graph lbr.
  396. Disabled by default. In common cases with call stack overflows,
  397. it can recreate better call stacks than the default lbr call stack
  398. output. But this approach is not foolproof. There can be cases
  399. where it creates incorrect call stacks from incorrect matches.
  400. The known limitations include exception handing such as
  401. setjmp/longjmp will have calls/returns not match.
  402. --merge-callchains::
  403. Enable merging deferred user callchains if available. This is the
  404. default behavior. If you want to see separate CALLCHAIN_DEFERRED
  405. records for some reason, use --no-merge-callchains explicitly.
  406. :GMEXAMPLECMD: script
  407. :GMEXAMPLESUBCMD:
  408. include::guest-files.txt[]
  409. SEE ALSO
  410. --------
  411. linkperf:perf-record[1], linkperf:perf-script-perl[1],
  412. linkperf:perf-script-python[1], linkperf:perf-intel-pt[1],
  413. linkperf:perf-dlfilter[1]