perf-record.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. perf-record(1)
  2. ==============
  3. NAME
  4. ----
  5. perf-record - Run a command and record its profile into perf.data
  6. SYNOPSIS
  7. --------
  8. [verse]
  9. 'perf record' [-e <EVENT> | --event=EVENT] [-l] [-a] <command>
  10. 'perf record' [-e <EVENT> | --event=EVENT] [-l] [-a] -- <command> [<options>]
  11. DESCRIPTION
  12. -----------
  13. This command runs a command and gathers a performance counter profile
  14. from it, into perf.data - without displaying anything.
  15. This file can then be inspected later on, using 'perf report'.
  16. OPTIONS
  17. -------
  18. <command>...::
  19. Any command you can specify in a shell.
  20. -e::
  21. --event=::
  22. Select the PMU event. Selection can be:
  23. - a symbolic event name (use 'perf list' to list all events)
  24. - a raw PMU event (eventsel+umask) in the form of rNNN where NNN is a
  25. hexadecimal event descriptor.
  26. - a symbolically formed PMU event like 'pmu/param1=0x3,param2/' where
  27. 'param1', 'param2', etc are defined as formats for the PMU in
  28. /sys/bus/event_sources/devices/<pmu>/format/*.
  29. - a symbolically formed event like 'pmu/config=M,config1=N,config3=K/'
  30. where M, N, K are numbers (in decimal, hex, octal format). Acceptable
  31. values for each of 'config', 'config1' and 'config2' are defined by
  32. corresponding entries in /sys/bus/event_sources/devices/<pmu>/format/*
  33. param1 and param2 are defined as formats for the PMU in:
  34. /sys/bus/event_sources/devices/<pmu>/format/*
  35. There are also some params which are not defined in .../<pmu>/format/*.
  36. These params can be used to overload default config values per event.
  37. Here is a list of the params.
  38. - 'period': Set event sampling period
  39. - 'freq': Set event sampling frequency
  40. - 'time': Disable/enable time stamping. Acceptable values are 1 for
  41. enabling time stamping. 0 for disabling time stamping.
  42. The default is 1.
  43. - 'call-graph': Disable/enable callgraph. Acceptable str are "fp" for
  44. FP mode, "dwarf" for DWARF mode, "lbr" for LBR mode and
  45. "no" for disable callgraph.
  46. - 'stack-size': user stack size for dwarf mode
  47. Note: If user explicitly sets options which conflict with the params,
  48. the value set by the params will be overridden.
  49. - a hardware breakpoint event in the form of '\mem:addr[/len][:access]'
  50. where addr is the address in memory you want to break in.
  51. Access is the memory access type (read, write, execute) it can
  52. be passed as follows: '\mem:addr[:[r][w][x]]'. len is the range,
  53. number of bytes from specified addr, which the breakpoint will cover.
  54. If you want to profile read-write accesses in 0x1000, just set
  55. 'mem:0x1000:rw'.
  56. If you want to profile write accesses in [0x1000~1008), just set
  57. 'mem:0x1000/8:w'.
  58. - a group of events surrounded by a pair of brace ("{event1,event2,...}").
  59. Each event is separated by commas and the group should be quoted to
  60. prevent the shell interpretation. You also need to use --group on
  61. "perf report" to view group events together.
  62. --filter=<filter>::
  63. Event filter. This option should follow a event selector (-e) which
  64. selects tracepoint event(s). Multiple '--filter' options are combined
  65. using '&&'.
  66. --exclude-perf::
  67. Don't record events issued by perf itself. This option should follow
  68. a event selector (-e) which selects tracepoint event(s). It adds a
  69. filter expression 'common_pid != $PERFPID' to filters. If other
  70. '--filter' exists, the new filter expression will be combined with
  71. them by '&&'.
  72. -a::
  73. --all-cpus::
  74. System-wide collection from all CPUs.
  75. -p::
  76. --pid=::
  77. Record events on existing process ID (comma separated list).
  78. -t::
  79. --tid=::
  80. Record events on existing thread ID (comma separated list).
  81. This option also disables inheritance by default. Enable it by adding
  82. --inherit.
  83. -u::
  84. --uid=::
  85. Record events in threads owned by uid. Name or number.
  86. -r::
  87. --realtime=::
  88. Collect data with this RT SCHED_FIFO priority.
  89. --no-buffering::
  90. Collect data without buffering.
  91. -c::
  92. --count=::
  93. Event period to sample.
  94. -o::
  95. --output=::
  96. Output file name.
  97. -i::
  98. --no-inherit::
  99. Child tasks do not inherit counters.
  100. -F::
  101. --freq=::
  102. Profile at this frequency.
  103. -m::
  104. --mmap-pages=::
  105. Number of mmap data pages (must be a power of two) or size
  106. specification with appended unit character - B/K/M/G. The
  107. size is rounded up to have nearest pages power of two value.
  108. Also, by adding a comma, the number of mmap pages for AUX
  109. area tracing can be specified.
  110. --group::
  111. Put all events in a single event group. This precedes the --event
  112. option and remains only for backward compatibility. See --event.
  113. -g::
  114. Enables call-graph (stack chain/backtrace) recording.
  115. --call-graph::
  116. Setup and enable call-graph (stack chain/backtrace) recording,
  117. implies -g.
  118. Allows specifying "fp" (frame pointer) or "dwarf"
  119. (DWARF's CFI - Call Frame Information) or "lbr"
  120. (Hardware Last Branch Record facility) as the method to collect
  121. the information used to show the call graphs.
  122. In some systems, where binaries are build with gcc
  123. --fomit-frame-pointer, using the "fp" method will produce bogus
  124. call graphs, using "dwarf", if available (perf tools linked to
  125. the libunwind library) should be used instead.
  126. Using the "lbr" method doesn't require any compiler options. It
  127. will produce call graphs from the hardware LBR registers. The
  128. main limition is that it is only available on new Intel
  129. platforms, such as Haswell. It can only get user call chain. It
  130. doesn't work with branch stack sampling at the same time.
  131. -q::
  132. --quiet::
  133. Don't print any message, useful for scripting.
  134. -v::
  135. --verbose::
  136. Be more verbose (show counter open errors, etc).
  137. -s::
  138. --stat::
  139. Record per-thread event counts. Use it with 'perf report -T' to see
  140. the values.
  141. -d::
  142. --data::
  143. Record the sample addresses.
  144. -T::
  145. --timestamp::
  146. Record the sample timestamps. Use it with 'perf report -D' to see the
  147. timestamps, for instance.
  148. -P::
  149. --period::
  150. Record the sample period.
  151. -n::
  152. --no-samples::
  153. Don't sample.
  154. -R::
  155. --raw-samples::
  156. Collect raw sample records from all opened counters (default for tracepoint counters).
  157. -C::
  158. --cpu::
  159. Collect samples only on the list of CPUs provided. Multiple CPUs can be provided as a
  160. comma-separated list with no space: 0,1. Ranges of CPUs are specified with -: 0-2.
  161. In per-thread mode with inheritance mode on (default), samples are captured only when
  162. the thread executes on the designated CPUs. Default is to monitor all CPUs.
  163. -N::
  164. --no-buildid-cache::
  165. Do not update the buildid cache. This saves some overhead in situations
  166. where the information in the perf.data file (which includes buildids)
  167. is sufficient.
  168. -G name,...::
  169. --cgroup name,...::
  170. monitor only in the container (cgroup) called "name". This option is available only
  171. in per-cpu mode. The cgroup filesystem must be mounted. All threads belonging to
  172. container "name" are monitored when they run on the monitored CPUs. Multiple cgroups
  173. can be provided. Each cgroup is applied to the corresponding event, i.e., first cgroup
  174. to first event, second cgroup to second event and so on. It is possible to provide
  175. an empty cgroup (monitor all the time) using, e.g., -G foo,,bar. Cgroups must have
  176. corresponding events, i.e., they always refer to events defined earlier on the command
  177. line.
  178. -b::
  179. --branch-any::
  180. Enable taken branch stack sampling. Any type of taken branch may be sampled.
  181. This is a shortcut for --branch-filter any. See --branch-filter for more infos.
  182. -j::
  183. --branch-filter::
  184. Enable taken branch stack sampling. Each sample captures a series of consecutive
  185. taken branches. The number of branches captured with each sample depends on the
  186. underlying hardware, the type of branches of interest, and the executed code.
  187. It is possible to select the types of branches captured by enabling filters. The
  188. following filters are defined:
  189. - any: any type of branches
  190. - any_call: any function call or system call
  191. - any_ret: any function return or system call return
  192. - ind_call: any indirect branch
  193. - u: only when the branch target is at the user level
  194. - k: only when the branch target is in the kernel
  195. - hv: only when the target is at the hypervisor level
  196. - in_tx: only when the target is in a hardware transaction
  197. - no_tx: only when the target is not in a hardware transaction
  198. - abort_tx: only when the target is a hardware transaction abort
  199. - cond: conditional branches
  200. +
  201. The option requires at least one branch type among any, any_call, any_ret, ind_call, cond.
  202. The privilege levels may be omitted, in which case, the privilege levels of the associated
  203. event are applied to the branch filter. Both kernel (k) and hypervisor (hv) privilege
  204. levels are subject to permissions. When sampling on multiple events, branch stack sampling
  205. is enabled for all the sampling events. The sampled branch type is the same for all events.
  206. The various filters must be specified as a comma separated list: --branch-filter any_ret,u,k
  207. Note that this feature may not be available on all processors.
  208. --weight::
  209. Enable weightened sampling. An additional weight is recorded per sample and can be
  210. displayed with the weight and local_weight sort keys. This currently works for TSX
  211. abort events and some memory events in precise mode on modern Intel CPUs.
  212. --transaction::
  213. Record transaction flags for transaction related events.
  214. --per-thread::
  215. Use per-thread mmaps. By default per-cpu mmaps are created. This option
  216. overrides that and uses per-thread mmaps. A side-effect of that is that
  217. inheritance is automatically disabled. --per-thread is ignored with a warning
  218. if combined with -a or -C options.
  219. -D::
  220. --delay=::
  221. After starting the program, wait msecs before measuring. This is useful to
  222. filter out the startup phase of the program, which is often very different.
  223. -I::
  224. --intr-regs::
  225. Capture machine state (registers) at interrupt, i.e., on counter overflows for
  226. each sample. List of captured registers depends on the architecture. This option
  227. is off by default. It is possible to select the registers to sample using their
  228. symbolic names, e.g. on x86, ax, si. To list the available registers use
  229. --intr-regs=\?. To name registers, pass a comma separated list such as
  230. --intr-regs=ax,bx. The list of register is architecture dependent.
  231. --running-time::
  232. Record running and enabled time for read events (:S)
  233. -k::
  234. --clockid::
  235. Sets the clock id to use for the various time fields in the perf_event_type
  236. records. See clock_gettime(). In particular CLOCK_MONOTONIC and
  237. CLOCK_MONOTONIC_RAW are supported, some events might also allow
  238. CLOCK_BOOTTIME, CLOCK_REALTIME and CLOCK_TAI.
  239. -S::
  240. --snapshot::
  241. Select AUX area tracing Snapshot Mode. This option is valid only with an
  242. AUX area tracing event. Optionally the number of bytes to capture per
  243. snapshot can be specified. In Snapshot Mode, trace data is captured only when
  244. signal SIGUSR2 is received.
  245. --proc-map-timeout::
  246. When processing pre-existing threads /proc/XXX/mmap, it may take a long time,
  247. because the file may be huge. A time out is needed in such cases.
  248. This option sets the time out limit. The default value is 500 ms.
  249. --switch-events::
  250. Record context switch events i.e. events of type PERF_RECORD_SWITCH or
  251. PERF_RECORD_SWITCH_CPU_WIDE.
  252. SEE ALSO
  253. --------
  254. linkperf:perf-stat[1], linkperf:perf-list[1]