perf-trace.txt 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. -D msecs::
  37. --delay msecs::
  38. After starting the program, wait msecs before measuring. This is useful to
  39. filter out the startup phase of the program, which is often very different.
  40. -o::
  41. --output=::
  42. Output file name.
  43. -p::
  44. --pid=::
  45. Record events on existing process ID (comma separated list).
  46. -t::
  47. --tid=::
  48. Record events on existing thread ID (comma separated list).
  49. -u::
  50. --uid=::
  51. Record events in threads owned by uid. Name or number.
  52. -G::
  53. --cgroup::
  54. Record events in threads in a cgroup.
  55. Look for cgroups to set at the /sys/fs/cgroup/perf_event directory, then
  56. remove the /sys/fs/cgroup/perf_event/ part and try:
  57. perf trace -G A -e sched:*switch
  58. Will set all raw_syscalls:sys_{enter,exit}, pgfault, vfs_getname, etc
  59. _and_ sched:sched_switch to the 'A' cgroup, while:
  60. perf trace -e sched:*switch -G A
  61. will only set the sched:sched_switch event to the 'A' cgroup, all the
  62. other events (raw_syscalls:sys_{enter,exit}, etc are left "without"
  63. a cgroup (on the root cgroup, sys wide, etc).
  64. Multiple cgroups:
  65. perf trace -G A -e sched:*switch -G B
  66. the syscall ones go to the 'A' cgroup, the sched:sched_switch goes
  67. to the 'B' cgroup.
  68. --filter-pids=::
  69. Filter out events for these pids and for 'trace' itself (comma separated list).
  70. -v::
  71. --verbose=::
  72. Verbosity level.
  73. --no-inherit::
  74. Child tasks do not inherit counters.
  75. -m::
  76. --mmap-pages=::
  77. Number of mmap data pages (must be a power of two) or size
  78. specification with appended unit character - B/K/M/G. The
  79. size is rounded up to have nearest pages power of two value.
  80. -C::
  81. --cpu::
  82. Collect samples only on the list of CPUs provided. Multiple CPUs can be provided as a
  83. comma-separated list with no space: 0,1. Ranges of CPUs are specified with -: 0-2.
  84. In per-thread mode with inheritance mode on (default), Events are captured only when
  85. the thread executes on the designated CPUs. Default is to monitor all CPUs.
  86. --duration::
  87. Show only events that had a duration greater than N.M ms.
  88. --sched::
  89. Accrue thread runtime and provide a summary at the end of the session.
  90. --failure::
  91. Show only syscalls that failed, i.e. that returned < 0.
  92. -i::
  93. --input::
  94. Process events from a given perf data file.
  95. -T::
  96. --time::
  97. Print full timestamp rather time relative to first sample.
  98. --comm::
  99. Show process COMM right beside its ID, on by default, disable with --no-comm.
  100. -s::
  101. --summary::
  102. Show only a summary of syscalls by thread with min, max, and average times
  103. (in msec) and relative stddev.
  104. -S::
  105. --with-summary::
  106. Show all syscalls followed by a summary by thread with min, max, and
  107. average times (in msec) and relative stddev.
  108. --tool_stats::
  109. Show tool stats such as number of times fd->pathname was discovered thru
  110. hooking the open syscall return + vfs_getname or via reading /proc/pid/fd, etc.
  111. -f::
  112. --force::
  113. Don't complain, do it.
  114. -F=[all|min|maj]::
  115. --pf=[all|min|maj]::
  116. Trace pagefaults. Optionally, you can specify whether you want minor,
  117. major or all pagefaults. Default value is maj.
  118. --syscalls::
  119. Trace system calls. This options is enabled by default, disable with
  120. --no-syscalls.
  121. --call-graph [mode,type,min[,limit],order[,key][,branch]]::
  122. Setup and enable call-graph (stack chain/backtrace) recording.
  123. See `--call-graph` section in perf-record and perf-report
  124. man pages for details. The ones that are most useful in 'perf trace'
  125. are 'dwarf' and 'lbr', where available, try: 'perf trace --call-graph dwarf'.
  126. Using this will, for the root user, bump the value of --mmap-pages to 4
  127. times the maximum for non-root users, based on the kernel.perf_event_mlock_kb
  128. sysctl. This is done only if the user doesn't specify a --mmap-pages value.
  129. --kernel-syscall-graph::
  130. Show the kernel callchains on the syscall exit path.
  131. --max-stack::
  132. Set the stack depth limit when parsing the callchain, anything
  133. beyond the specified depth will be ignored. Note that at this point
  134. this is just about the presentation part, i.e. the kernel is still
  135. not limiting, the overhead of callchains needs to be set via the
  136. knobs in --call-graph dwarf.
  137. Implies '--call-graph dwarf' when --call-graph not present on the
  138. command line, on systems where DWARF unwinding was built in.
  139. Default: /proc/sys/kernel/perf_event_max_stack when present for
  140. live sessions (without --input/-i), 127 otherwise.
  141. --min-stack::
  142. Set the stack depth limit when parsing the callchain, anything
  143. below the specified depth will be ignored. Disabled by default.
  144. Implies '--call-graph dwarf' when --call-graph not present on the
  145. command line, on systems where DWARF unwinding was built in.
  146. --print-sample::
  147. Print the PERF_RECORD_SAMPLE PERF_SAMPLE_ info for the
  148. raw_syscalls:sys_{enter,exit} tracepoints, for debugging.
  149. --proc-map-timeout::
  150. When processing pre-existing threads /proc/XXX/mmap, it may take a long time,
  151. because the file may be huge. A time out is needed in such cases.
  152. This option sets the time out limit. The default value is 500 ms.
  153. PAGEFAULTS
  154. ----------
  155. When tracing pagefaults, the format of the trace is as follows:
  156. <min|maj>fault [<ip.symbol>+<ip.offset>] => <addr.dso@addr.offset> (<map type><addr level>).
  157. - min/maj indicates whether fault event is minor or major;
  158. - ip.symbol shows symbol for instruction pointer (the code that generated the
  159. fault); if no debug symbols available, perf trace will print raw IP;
  160. - addr.dso shows DSO for the faulted address;
  161. - map type is either 'd' for non-executable maps or 'x' for executable maps;
  162. - addr level is either 'k' for kernel dso or '.' for user dso.
  163. For symbols resolution you may need to install debugging symbols.
  164. Please be aware that duration is currently always 0 and doesn't reflect actual
  165. time it took for fault to be handled!
  166. When --verbose specified, perf trace tries to print all available information
  167. for both IP and fault address in the form of dso@symbol+offset.
  168. EXAMPLES
  169. --------
  170. Trace only major pagefaults:
  171. $ perf trace --no-syscalls -F
  172. Trace syscalls, major and minor pagefaults:
  173. $ perf trace -F all
  174. 1416.547 ( 0.000 ms): python/20235 majfault [CRYPTO_push_info_+0x0] => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0@0x61be0 (x.)
  175. As you can see, there was major pagefault in python process, from
  176. CRYPTO_push_info_ routine which faulted somewhere in libcrypto.so.
  177. SEE ALSO
  178. --------
  179. linkperf:perf-record[1], linkperf:perf-script[1]