perf-record.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. -B::
  168. --no-buildid::
  169. Do not save the build ids of binaries in the perf.data files. This skips
  170. post processing after recording, which sometimes makes the final step in
  171. the recording process to take a long time, as it needs to process all
  172. events looking for mmap records. The downside is that it can misresolve
  173. symbols if the workload binaries used when recording get locally rebuilt
  174. or upgraded, because the only key available in this case is the
  175. pathname. You can also set the "record.build-id" config variable to
  176. 'skip to have this behaviour permanently.
  177. -N::
  178. --no-buildid-cache::
  179. Do not update the buildid cache. This saves some overhead in situations
  180. where the information in the perf.data file (which includes buildids)
  181. is sufficient. You can also set the "record.build-id" config variable to
  182. 'no-cache' to have the same effect.
  183. -G name,...::
  184. --cgroup name,...::
  185. monitor only in the container (cgroup) called "name". This option is available only
  186. in per-cpu mode. The cgroup filesystem must be mounted. All threads belonging to
  187. container "name" are monitored when they run on the monitored CPUs. Multiple cgroups
  188. can be provided. Each cgroup is applied to the corresponding event, i.e., first cgroup
  189. to first event, second cgroup to second event and so on. It is possible to provide
  190. an empty cgroup (monitor all the time) using, e.g., -G foo,,bar. Cgroups must have
  191. corresponding events, i.e., they always refer to events defined earlier on the command
  192. line.
  193. -b::
  194. --branch-any::
  195. Enable taken branch stack sampling. Any type of taken branch may be sampled.
  196. This is a shortcut for --branch-filter any. See --branch-filter for more infos.
  197. -j::
  198. --branch-filter::
  199. Enable taken branch stack sampling. Each sample captures a series of consecutive
  200. taken branches. The number of branches captured with each sample depends on the
  201. underlying hardware, the type of branches of interest, and the executed code.
  202. It is possible to select the types of branches captured by enabling filters. The
  203. following filters are defined:
  204. - any: any type of branches
  205. - any_call: any function call or system call
  206. - any_ret: any function return or system call return
  207. - ind_call: any indirect branch
  208. - call: direct calls, including far (to/from kernel) calls
  209. - u: only when the branch target is at the user level
  210. - k: only when the branch target is in the kernel
  211. - hv: only when the target is at the hypervisor level
  212. - in_tx: only when the target is in a hardware transaction
  213. - no_tx: only when the target is not in a hardware transaction
  214. - abort_tx: only when the target is a hardware transaction abort
  215. - cond: conditional branches
  216. +
  217. The option requires at least one branch type among any, any_call, any_ret, ind_call, cond.
  218. The privilege levels may be omitted, in which case, the privilege levels of the associated
  219. event are applied to the branch filter. Both kernel (k) and hypervisor (hv) privilege
  220. levels are subject to permissions. When sampling on multiple events, branch stack sampling
  221. is enabled for all the sampling events. The sampled branch type is the same for all events.
  222. The various filters must be specified as a comma separated list: --branch-filter any_ret,u,k
  223. Note that this feature may not be available on all processors.
  224. --weight::
  225. Enable weightened sampling. An additional weight is recorded per sample and can be
  226. displayed with the weight and local_weight sort keys. This currently works for TSX
  227. abort events and some memory events in precise mode on modern Intel CPUs.
  228. --transaction::
  229. Record transaction flags for transaction related events.
  230. --per-thread::
  231. Use per-thread mmaps. By default per-cpu mmaps are created. This option
  232. overrides that and uses per-thread mmaps. A side-effect of that is that
  233. inheritance is automatically disabled. --per-thread is ignored with a warning
  234. if combined with -a or -C options.
  235. -D::
  236. --delay=::
  237. After starting the program, wait msecs before measuring. This is useful to
  238. filter out the startup phase of the program, which is often very different.
  239. -I::
  240. --intr-regs::
  241. Capture machine state (registers) at interrupt, i.e., on counter overflows for
  242. each sample. List of captured registers depends on the architecture. This option
  243. is off by default. It is possible to select the registers to sample using their
  244. symbolic names, e.g. on x86, ax, si. To list the available registers use
  245. --intr-regs=\?. To name registers, pass a comma separated list such as
  246. --intr-regs=ax,bx. The list of register is architecture dependent.
  247. --running-time::
  248. Record running and enabled time for read events (:S)
  249. -k::
  250. --clockid::
  251. Sets the clock id to use for the various time fields in the perf_event_type
  252. records. See clock_gettime(). In particular CLOCK_MONOTONIC and
  253. CLOCK_MONOTONIC_RAW are supported, some events might also allow
  254. CLOCK_BOOTTIME, CLOCK_REALTIME and CLOCK_TAI.
  255. -S::
  256. --snapshot::
  257. Select AUX area tracing Snapshot Mode. This option is valid only with an
  258. AUX area tracing event. Optionally the number of bytes to capture per
  259. snapshot can be specified. In Snapshot Mode, trace data is captured only when
  260. signal SIGUSR2 is received.
  261. --proc-map-timeout::
  262. When processing pre-existing threads /proc/XXX/mmap, it may take a long time,
  263. because the file may be huge. A time out is needed in such cases.
  264. This option sets the time out limit. The default value is 500 ms.
  265. --switch-events::
  266. Record context switch events i.e. events of type PERF_RECORD_SWITCH or
  267. PERF_RECORD_SWITCH_CPU_WIDE.
  268. --clang-path=PATH::
  269. Path to clang binary to use for compiling BPF scriptlets.
  270. (enabled when BPF support is on)
  271. --clang-opt=OPTIONS::
  272. Options passed to clang when compiling BPF scriptlets.
  273. (enabled when BPF support is on)
  274. --vmlinux=PATH::
  275. Specify vmlinux path which has debuginfo.
  276. (enabled when BPF prologue is on)
  277. --buildid-all::
  278. Record build-id of all DSOs regardless whether it's actually hit or not.
  279. --all-kernel::
  280. Configure all used events to run in kernel space.
  281. --all-user::
  282. Configure all used events to run in user space.
  283. SEE ALSO
  284. --------
  285. linkperf:perf-stat[1], linkperf:perf-list[1]