perf-record.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. Default is "fp".
  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 or libdw 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. When "dwarf" recording is used, perf also records (user) stack dump
  132. when sampled. Default size of the stack dump is 8192 (bytes).
  133. User can change the size by passing the size after comma like
  134. "--call-graph dwarf,4096".
  135. -q::
  136. --quiet::
  137. Don't print any message, useful for scripting.
  138. -v::
  139. --verbose::
  140. Be more verbose (show counter open errors, etc).
  141. -s::
  142. --stat::
  143. Record per-thread event counts. Use it with 'perf report -T' to see
  144. the values.
  145. -d::
  146. --data::
  147. Record the sample addresses.
  148. -T::
  149. --timestamp::
  150. Record the sample timestamps. Use it with 'perf report -D' to see the
  151. timestamps, for instance.
  152. -P::
  153. --period::
  154. Record the sample period.
  155. -n::
  156. --no-samples::
  157. Don't sample.
  158. -R::
  159. --raw-samples::
  160. Collect raw sample records from all opened counters (default for tracepoint counters).
  161. -C::
  162. --cpu::
  163. Collect samples only on the list of CPUs provided. Multiple CPUs can be provided as a
  164. comma-separated list with no space: 0,1. Ranges of CPUs are specified with -: 0-2.
  165. In per-thread mode with inheritance mode on (default), samples are captured only when
  166. the thread executes on the designated CPUs. Default is to monitor all CPUs.
  167. -N::
  168. --no-buildid-cache::
  169. Do not update the buildid cache. This saves some overhead in situations
  170. where the information in the perf.data file (which includes buildids)
  171. is sufficient.
  172. -G name,...::
  173. --cgroup name,...::
  174. monitor only in the container (cgroup) called "name". This option is available only
  175. in per-cpu mode. The cgroup filesystem must be mounted. All threads belonging to
  176. container "name" are monitored when they run on the monitored CPUs. Multiple cgroups
  177. can be provided. Each cgroup is applied to the corresponding event, i.e., first cgroup
  178. to first event, second cgroup to second event and so on. It is possible to provide
  179. an empty cgroup (monitor all the time) using, e.g., -G foo,,bar. Cgroups must have
  180. corresponding events, i.e., they always refer to events defined earlier on the command
  181. line.
  182. -b::
  183. --branch-any::
  184. Enable taken branch stack sampling. Any type of taken branch may be sampled.
  185. This is a shortcut for --branch-filter any. See --branch-filter for more infos.
  186. -j::
  187. --branch-filter::
  188. Enable taken branch stack sampling. Each sample captures a series of consecutive
  189. taken branches. The number of branches captured with each sample depends on the
  190. underlying hardware, the type of branches of interest, and the executed code.
  191. It is possible to select the types of branches captured by enabling filters. The
  192. following filters are defined:
  193. - any: any type of branches
  194. - any_call: any function call or system call
  195. - any_ret: any function return or system call return
  196. - ind_call: any indirect branch
  197. - call: direct calls, including far (to/from kernel) calls
  198. - u: only when the branch target is at the user level
  199. - k: only when the branch target is in the kernel
  200. - hv: only when the target is at the hypervisor level
  201. - in_tx: only when the target is in a hardware transaction
  202. - no_tx: only when the target is not in a hardware transaction
  203. - abort_tx: only when the target is a hardware transaction abort
  204. - cond: conditional branches
  205. +
  206. The option requires at least one branch type among any, any_call, any_ret, ind_call, cond.
  207. The privilege levels may be omitted, in which case, the privilege levels of the associated
  208. event are applied to the branch filter. Both kernel (k) and hypervisor (hv) privilege
  209. levels are subject to permissions. When sampling on multiple events, branch stack sampling
  210. is enabled for all the sampling events. The sampled branch type is the same for all events.
  211. The various filters must be specified as a comma separated list: --branch-filter any_ret,u,k
  212. Note that this feature may not be available on all processors.
  213. --weight::
  214. Enable weightened sampling. An additional weight is recorded per sample and can be
  215. displayed with the weight and local_weight sort keys. This currently works for TSX
  216. abort events and some memory events in precise mode on modern Intel CPUs.
  217. --transaction::
  218. Record transaction flags for transaction related events.
  219. --per-thread::
  220. Use per-thread mmaps. By default per-cpu mmaps are created. This option
  221. overrides that and uses per-thread mmaps. A side-effect of that is that
  222. inheritance is automatically disabled. --per-thread is ignored with a warning
  223. if combined with -a or -C options.
  224. -D::
  225. --delay=::
  226. After starting the program, wait msecs before measuring. This is useful to
  227. filter out the startup phase of the program, which is often very different.
  228. -I::
  229. --intr-regs::
  230. Capture machine state (registers) at interrupt, i.e., on counter overflows for
  231. each sample. List of captured registers depends on the architecture. This option
  232. is off by default. It is possible to select the registers to sample using their
  233. symbolic names, e.g. on x86, ax, si. To list the available registers use
  234. --intr-regs=\?. To name registers, pass a comma separated list such as
  235. --intr-regs=ax,bx. The list of register is architecture dependent.
  236. --running-time::
  237. Record running and enabled time for read events (:S)
  238. -k::
  239. --clockid::
  240. Sets the clock id to use for the various time fields in the perf_event_type
  241. records. See clock_gettime(). In particular CLOCK_MONOTONIC and
  242. CLOCK_MONOTONIC_RAW are supported, some events might also allow
  243. CLOCK_BOOTTIME, CLOCK_REALTIME and CLOCK_TAI.
  244. -S::
  245. --snapshot::
  246. Select AUX area tracing Snapshot Mode. This option is valid only with an
  247. AUX area tracing event. Optionally the number of bytes to capture per
  248. snapshot can be specified. In Snapshot Mode, trace data is captured only when
  249. signal SIGUSR2 is received.
  250. --proc-map-timeout::
  251. When processing pre-existing threads /proc/XXX/mmap, it may take a long time,
  252. because the file may be huge. A time out is needed in such cases.
  253. This option sets the time out limit. The default value is 500 ms.
  254. --switch-events::
  255. Record context switch events i.e. events of type PERF_RECORD_SWITCH or
  256. PERF_RECORD_SWITCH_CPU_WIDE.
  257. --clang-path::
  258. Path to clang binary to use for compiling BPF scriptlets.
  259. --clang-opt::
  260. Options passed to clang when compiling BPF scriptlets.
  261. SEE ALSO
  262. --------
  263. linkperf:perf-stat[1], linkperf:perf-list[1]