perf-trace.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. perf-trace(1)
  2. =============
  3. NAME
  4. ----
  5. perf-trace - strace inspired tool
  6. SYNOPSIS
  7. --------
  8. [verse]
  9. 'perf trace'
  10. 'perf trace record'
  11. DESCRIPTION
  12. -----------
  13. This command will show the events associated with the target, initially
  14. syscalls, but other system events like pagefaults, task lifetime events,
  15. scheduling events, etc.
  16. This is a live mode tool in addition to working with perf.data files like
  17. the other perf tools. Files can be generated using the 'perf record' command
  18. but the session needs to include the raw_syscalls events (-e 'raw_syscalls:*').
  19. Alternatively, 'perf trace record' can be used as a shortcut to
  20. automatically include the raw_syscalls events when writing events to a file.
  21. The following options apply to perf trace; options to perf trace record are
  22. found in the perf record man page.
  23. OPTIONS
  24. -------
  25. -a::
  26. --all-cpus::
  27. System-wide collection from all CPUs.
  28. -e::
  29. --expr::
  30. --event::
  31. List of syscalls and other perf events (tracepoints, HW cache events,
  32. etc) to show. Globbing is supported, e.g.: "epoll_*", "*msg*", etc.
  33. See 'perf list' for a complete list of events.
  34. Prefixing with ! shows all syscalls but the ones specified. You may
  35. need to escape it.
  36. --filter=<filter>::
  37. Event filter. This option should follow an event selector (-e) which
  38. selects tracepoint event(s).
  39. -D msecs::
  40. --delay msecs::
  41. After starting the program, wait msecs before measuring. This is useful to
  42. filter out the startup phase of the program, which is often very different.
  43. -o::
  44. --output=::
  45. Output file name.
  46. -p::
  47. --pid=::
  48. Record events on existing process ID (comma separated list).
  49. -t::
  50. --tid=::
  51. Record events on existing thread ID (comma separated list).
  52. -u::
  53. --uid=::
  54. Record events in threads owned by uid. Name or number.
  55. -G::
  56. --cgroup::
  57. Record events in threads in a cgroup.
  58. Look for cgroups to set at the /sys/fs/cgroup/perf_event directory, then
  59. remove the /sys/fs/cgroup/perf_event/ part and try:
  60. perf trace -G A -e sched:*switch
  61. Will set all raw_syscalls:sys_{enter,exit}, pgfault, vfs_getname, etc
  62. _and_ sched:sched_switch to the 'A' cgroup, while:
  63. perf trace -e sched:*switch -G A
  64. will only set the sched:sched_switch event to the 'A' cgroup, all the
  65. other events (raw_syscalls:sys_{enter,exit}, etc are left "without"
  66. a cgroup (on the root cgroup, sys wide, etc).
  67. Multiple cgroups:
  68. perf trace -G A -e sched:*switch -G B
  69. the syscall ones go to the 'A' cgroup, the sched:sched_switch goes
  70. to the 'B' cgroup.
  71. --filter-pids=::
  72. Filter out events for these pids and for 'trace' itself (comma separated list).
  73. -v::
  74. --verbose::
  75. Increase the verbosity level.
  76. --no-inherit::
  77. Child tasks do not inherit counters.
  78. -m::
  79. --mmap-pages=::
  80. Number of mmap data pages (must be a power of two) or size
  81. specification in bytes with appended unit character - B/K/M/G.
  82. The size is rounded up to the nearest power-of-two page value.
  83. -C::
  84. --cpu::
  85. Collect samples only on the list of CPUs provided. Multiple CPUs can be provided as a
  86. comma-separated list with no space: 0,1. Ranges of CPUs are specified with -: 0-2.
  87. In per-thread mode with inheritance mode on (default), Events are captured only when
  88. the thread executes on the designated CPUs. Default is to monitor all CPUs.
  89. --duration::
  90. Show only events that had a duration greater than N.M ms.
  91. --sched::
  92. Accrue thread runtime and provide a summary at the end of the session.
  93. --failure::
  94. Show only syscalls that failed, i.e. that returned < 0.
  95. -i::
  96. --input::
  97. Process events from a given perf data file.
  98. -T::
  99. --time::
  100. Print full timestamp rather time relative to first sample.
  101. --comm::
  102. Show process COMM right beside its ID, on by default, disable with --no-comm.
  103. -s::
  104. --summary::
  105. Show only a summary of syscalls by thread with min, max, and average times
  106. (in msec) and relative stddev.
  107. -S::
  108. --with-summary::
  109. Show all syscalls followed by a summary by thread with min, max, and
  110. average times (in msec) and relative stddev.
  111. --errno-summary::
  112. To be used with -s or -S, to show stats for the errnos experienced by
  113. syscalls, using only this option will trigger --summary.
  114. --summary-mode=mode::
  115. To be used with -s or -S, to select how to show summary. By default it'll
  116. show the syscall summary by thread. Possible values are: thread, total,
  117. cgroup.
  118. --tool_stats::
  119. Show tool stats such as number of times fd->pathname was discovered thru
  120. hooking the open syscall return + vfs_getname or via reading /proc/pid/fd, etc.
  121. -f::
  122. --force::
  123. Don't complain, do it.
  124. -F=[all|min|maj]::
  125. --pf=[all|min|maj]::
  126. Trace pagefaults. Optionally, you can specify whether you want minor,
  127. major or all pagefaults. Default value is maj.
  128. --syscalls::
  129. Trace system calls. This options is enabled by default, disable with
  130. --no-syscalls.
  131. --call-graph [mode,type,min[,limit],order[,key][,branch]]::
  132. Setup and enable call-graph (stack chain/backtrace) recording.
  133. See `--call-graph` section in perf-record and perf-report
  134. man pages for details. The ones that are most useful in 'perf trace'
  135. are 'dwarf' and 'lbr', where available, try: 'perf trace --call-graph dwarf'.
  136. Using this will, for the root user, bump the value of --mmap-pages to 4
  137. times the maximum for non-root users, based on the kernel.perf_event_mlock_kb
  138. sysctl. This is done only if the user doesn't specify a --mmap-pages value.
  139. --kernel-syscall-graph::
  140. Show the kernel callchains on the syscall exit path.
  141. --max-events=N::
  142. Stop after processing N events. Note that strace-like events are considered
  143. only at exit time or when a syscall is interrupted, i.e. in those cases this
  144. option is equivalent to the number of lines printed.
  145. --switch-on EVENT_NAME::
  146. Only consider events after this event is found.
  147. --switch-off EVENT_NAME::
  148. Stop considering events after this event is found.
  149. --show-on-off-events::
  150. Show the --switch-on/off events too.
  151. --max-stack::
  152. Set the stack depth limit when parsing the callchain, anything
  153. beyond the specified depth will be ignored. Note that at this point
  154. this is just about the presentation part, i.e. the kernel is still
  155. not limiting, the overhead of callchains needs to be set via the
  156. knobs in --call-graph dwarf.
  157. Implies '--call-graph dwarf' when --call-graph not present on the
  158. command line, on systems where DWARF unwinding was built in.
  159. Default: /proc/sys/kernel/perf_event_max_stack when present for
  160. live sessions (without --input/-i), 127 otherwise.
  161. --min-stack::
  162. Set the stack depth limit when parsing the callchain, anything
  163. below the specified depth will be ignored. Disabled by default.
  164. Implies '--call-graph dwarf' when --call-graph not present on the
  165. command line, on systems where DWARF unwinding was built in.
  166. --print-sample::
  167. Print the PERF_RECORD_SAMPLE PERF_SAMPLE_ info for the
  168. raw_syscalls:sys_{enter,exit} tracepoints, for debugging.
  169. --proc-map-timeout::
  170. When processing pre-existing threads /proc/XXX/mmap, it may take a long time,
  171. because the file may be huge. A time out is needed in such cases.
  172. This option sets the time out limit. The default value is 500 ms.
  173. --sort-events::
  174. Do sorting on batches of events, use when noticing out of order events that
  175. may happen, for instance, when a thread gets migrated to a different CPU
  176. while processing a syscall.
  177. --libtraceevent_print::
  178. Use libtraceevent to print tracepoint arguments. By default 'perf trace' uses
  179. the same beautifiers used in the strace-like enter+exit lines to augment the
  180. tracepoint arguments.
  181. --force-btf::
  182. Use btf_dump to pretty print syscall argument data, instead of using hand-crafted pretty
  183. printers. This option is intended for testing BTF integration in perf trace. btf_dump-based
  184. pretty-printing serves as a fallback to hand-crafted pretty printers, as the latter can
  185. better pretty-print integer flags and struct pointers.
  186. --bpf-summary::
  187. Collect system call statistics in BPF. This is only for live mode and
  188. works well with -s/--summary option where no argument information is
  189. required.
  190. --max-summary=N::
  191. Maximum number of lines in the summary mode. Note that this applies to
  192. each entry (thread or cgroup).
  193. PAGEFAULTS
  194. ----------
  195. When tracing pagefaults, the format of the trace is as follows:
  196. <min|maj>fault [<ip.symbol>+<ip.offset>] => <addr.dso@addr.offset> (<map type><addr level>).
  197. - min/maj indicates whether fault event is minor or major;
  198. - ip.symbol shows symbol for instruction pointer (the code that generated the
  199. fault); if no debug symbols available, perf trace will print raw IP;
  200. - addr.dso shows DSO for the faulted address;
  201. - map type is either 'd' for non-executable maps or 'x' for executable maps;
  202. - addr level is either 'k' for kernel dso or '.' for user dso.
  203. For symbols resolution you may need to install debugging symbols.
  204. Please be aware that duration is currently always 0 and doesn't reflect actual
  205. time it took for fault to be handled!
  206. When --verbose specified, perf trace tries to print all available information
  207. for both IP and fault address in the form of dso@symbol+offset.
  208. EXAMPLES
  209. --------
  210. Trace only major pagefaults:
  211. $ perf trace --no-syscalls -F
  212. Trace syscalls, major and minor pagefaults:
  213. $ perf trace -F all
  214. 1416.547 ( 0.000 ms): python/20235 majfault [CRYPTO_push_info_+0x0] => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0@0x61be0 (x.)
  215. As you can see, there was major pagefault in python process, from
  216. CRYPTO_push_info_ routine which faulted somewhere in libcrypto.so.
  217. Trace the first 4 open, openat or open_by_handle_at syscalls (in the future more syscalls may match here):
  218. $ perf trace -e open* --max-events 4
  219. [root@jouet perf]# trace -e open* --max-events 4
  220. 2272.992 ( 0.037 ms): gnome-shell/1370 openat(dfd: CWD, filename: /proc/self/stat) = 31
  221. 2277.481 ( 0.139 ms): gnome-shell/3039 openat(dfd: CWD, filename: /proc/self/stat) = 65
  222. 3026.398 ( 0.076 ms): gnome-shell/3039 openat(dfd: CWD, filename: /proc/self/stat) = 65
  223. 4294.665 ( 0.015 ms): sed/15879 openat(dfd: CWD, filename: /etc/ld.so.cache, flags: CLOEXEC) = 3
  224. $
  225. Trace the first minor page fault when running a workload:
  226. # perf trace -F min --max-stack=7 --max-events 1 sleep 1
  227. 0.000 ( 0.000 ms): sleep/18006 minfault [__clear_user+0x1a] => 0x5626efa56080 (?k)
  228. __clear_user ([kernel.kallsyms])
  229. load_elf_binary ([kernel.kallsyms])
  230. search_binary_handler ([kernel.kallsyms])
  231. __do_execve_file.isra.33 ([kernel.kallsyms])
  232. __x64_sys_execve ([kernel.kallsyms])
  233. do_syscall_64 ([kernel.kallsyms])
  234. entry_SYSCALL_64 ([kernel.kallsyms])
  235. #
  236. Trace the next min page page fault to take place on the first CPU:
  237. # perf trace -F min --call-graph=dwarf --max-events 1 --cpu 0
  238. 0.000 ( 0.000 ms): Web Content/17136 minfault [js::gc::Chunk::fetchNextDecommittedArena+0x4b] => 0x7fbe6181b000 (?.)
  239. js::gc::FreeSpan::initAsEmpty (inlined)
  240. js::gc::Arena::setAsNotAllocated (inlined)
  241. js::gc::Chunk::fetchNextDecommittedArena (/usr/lib64/firefox/libxul.so)
  242. js::gc::Chunk::allocateArena (/usr/lib64/firefox/libxul.so)
  243. js::gc::GCRuntime::allocateArena (/usr/lib64/firefox/libxul.so)
  244. js::gc::ArenaLists::allocateFromArena (/usr/lib64/firefox/libxul.so)
  245. js::gc::GCRuntime::tryNewTenuredThing<JSString, (js::AllowGC)1> (inlined)
  246. js::AllocateString<JSString, (js::AllowGC)1> (/usr/lib64/firefox/libxul.so)
  247. js::Allocate<JSThinInlineString, (js::AllowGC)1> (inlined)
  248. JSThinInlineString::new_<(js::AllowGC)1> (inlined)
  249. AllocateInlineString<(js::AllowGC)1, unsigned char> (inlined)
  250. js::ConcatStrings<(js::AllowGC)1> (/usr/lib64/firefox/libxul.so)
  251. [0x18b26e6bc2bd] (/tmp/perf-17136.map)
  252. #
  253. Trace the next two sched:sched_switch events, four block:*_plug events, the
  254. next block:*_unplug and the next three net:*dev_queue events, this last one
  255. with a backtrace of at most 16 entries, system wide:
  256. # perf trace -e sched:*switch/nr=2/,block:*_plug/nr=4/,block:*_unplug/nr=1/,net:*dev_queue/nr=3,max-stack=16/
  257. 0.000 :0/0 sched:sched_switch:swapper/2:0 [120] S ==> rcu_sched:10 [120]
  258. 0.015 rcu_sched/10 sched:sched_switch:rcu_sched:10 [120] R ==> swapper/2:0 [120]
  259. 254.198 irq/50-iwlwifi/680 net:net_dev_queue:dev=wlp3s0 skbaddr=0xffff93498051f600 len=66
  260. __dev_queue_xmit ([kernel.kallsyms])
  261. 273.977 :0/0 net:net_dev_queue:dev=wlp3s0 skbaddr=0xffff93498051f600 len=78
  262. __dev_queue_xmit ([kernel.kallsyms])
  263. 274.007 :0/0 net:net_dev_queue:dev=wlp3s0 skbaddr=0xffff93498051ff00 len=78
  264. __dev_queue_xmit ([kernel.kallsyms])
  265. 2930.140 kworker/u16:58/2722 block:block_plug:[kworker/u16:58]
  266. 2930.162 kworker/u16:58/2722 block:block_unplug:[kworker/u16:58] 1
  267. 4466.094 jbd2/dm-2-8/748 block:block_plug:[jbd2/dm-2-8]
  268. 8050.123 kworker/u16:30/2694 block:block_plug:[kworker/u16:30]
  269. 8050.271 kworker/u16:30/2694 block:block_plug:[kworker/u16:30]
  270. #
  271. SEE ALSO
  272. --------
  273. linkperf:perf-record[1], linkperf:perf-script[1]