perf-record.txt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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_source/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_source/devices/<pmu>/format/*
  33. param1 and param2 are defined as formats for the PMU in:
  34. /sys/bus/event_source/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. Also not defined in .../<pmu>/format/* are PMU driver specific
  50. configuration parameters. Any configuration parameter preceded by
  51. the letter '@' is not interpreted in user space and sent down directly
  52. to the PMU driver. For example:
  53. perf record -e some_event/@cfg1,@cfg2=config/ ...
  54. will see 'cfg1' and 'cfg2=config' pushed to the PMU driver associated
  55. with the event for further processing. There is no restriction on
  56. what the configuration parameters are, as long as their semantic is
  57. understood and supported by the PMU driver.
  58. - a hardware breakpoint event in the form of '\mem:addr[/len][:access]'
  59. where addr is the address in memory you want to break in.
  60. Access is the memory access type (read, write, execute) it can
  61. be passed as follows: '\mem:addr[:[r][w][x]]'. len is the range,
  62. number of bytes from specified addr, which the breakpoint will cover.
  63. If you want to profile read-write accesses in 0x1000, just set
  64. 'mem:0x1000:rw'.
  65. If you want to profile write accesses in [0x1000~1008), just set
  66. 'mem:0x1000/8:w'.
  67. - a group of events surrounded by a pair of brace ("{event1,event2,...}").
  68. Each event is separated by commas and the group should be quoted to
  69. prevent the shell interpretation. You also need to use --group on
  70. "perf report" to view group events together.
  71. --filter=<filter>::
  72. Event filter. This option should follow a event selector (-e) which
  73. selects either tracepoint event(s) or a hardware trace PMU
  74. (e.g. Intel PT or CoreSight).
  75. - tracepoint filters
  76. In the case of tracepoints, multiple '--filter' options are combined
  77. using '&&'.
  78. - address filters
  79. A hardware trace PMU advertises its ability to accept a number of
  80. address filters by specifying a non-zero value in
  81. /sys/bus/event_source/devices/<pmu>/nr_addr_filters.
  82. Address filters have the format:
  83. filter|start|stop|tracestop <start> [/ <size>] [@<file name>]
  84. Where:
  85. - 'filter': defines a region that will be traced.
  86. - 'start': defines an address at which tracing will begin.
  87. - 'stop': defines an address at which tracing will stop.
  88. - 'tracestop': defines a region in which tracing will stop.
  89. <file name> is the name of the object file, <start> is the offset to the
  90. code to trace in that file, and <size> is the size of the region to
  91. trace. 'start' and 'stop' filters need not specify a <size>.
  92. If no object file is specified then the kernel is assumed, in which case
  93. the start address must be a current kernel memory address.
  94. <start> can also be specified by providing the name of a symbol. If the
  95. symbol name is not unique, it can be disambiguated by inserting #n where
  96. 'n' selects the n'th symbol in address order. Alternately #0, #g or #G
  97. select only a global symbol. <size> can also be specified by providing
  98. the name of a symbol, in which case the size is calculated to the end
  99. of that symbol. For 'filter' and 'tracestop' filters, if <size> is
  100. omitted and <start> is a symbol, then the size is calculated to the end
  101. of that symbol.
  102. If <size> is omitted and <start> is '*', then the start and size will
  103. be calculated from the first and last symbols, i.e. to trace the whole
  104. file.
  105. If symbol names (or '*') are provided, they must be surrounded by white
  106. space.
  107. The filter passed to the kernel is not necessarily the same as entered.
  108. To see the filter that is passed, use the -v option.
  109. The kernel may not be able to configure a trace region if it is not
  110. within a single mapping. MMAP events (or /proc/<pid>/maps) can be
  111. examined to determine if that is a possibility.
  112. Multiple filters can be separated with space or comma.
  113. --exclude-perf::
  114. Don't record events issued by perf itself. This option should follow
  115. a event selector (-e) which selects tracepoint event(s). It adds a
  116. filter expression 'common_pid != $PERFPID' to filters. If other
  117. '--filter' exists, the new filter expression will be combined with
  118. them by '&&'.
  119. -a::
  120. --all-cpus::
  121. System-wide collection from all CPUs.
  122. -p::
  123. --pid=::
  124. Record events on existing process ID (comma separated list).
  125. -t::
  126. --tid=::
  127. Record events on existing thread ID (comma separated list).
  128. This option also disables inheritance by default. Enable it by adding
  129. --inherit.
  130. -u::
  131. --uid=::
  132. Record events in threads owned by uid. Name or number.
  133. -r::
  134. --realtime=::
  135. Collect data with this RT SCHED_FIFO priority.
  136. --no-buffering::
  137. Collect data without buffering.
  138. -c::
  139. --count=::
  140. Event period to sample.
  141. -o::
  142. --output=::
  143. Output file name.
  144. -i::
  145. --no-inherit::
  146. Child tasks do not inherit counters.
  147. -F::
  148. --freq=::
  149. Profile at this frequency.
  150. -m::
  151. --mmap-pages=::
  152. Number of mmap data pages (must be a power of two) or size
  153. specification with appended unit character - B/K/M/G. The
  154. size is rounded up to have nearest pages power of two value.
  155. Also, by adding a comma, the number of mmap pages for AUX
  156. area tracing can be specified.
  157. --group::
  158. Put all events in a single event group. This precedes the --event
  159. option and remains only for backward compatibility. See --event.
  160. -g::
  161. Enables call-graph (stack chain/backtrace) recording.
  162. --call-graph::
  163. Setup and enable call-graph (stack chain/backtrace) recording,
  164. implies -g. Default is "fp".
  165. Allows specifying "fp" (frame pointer) or "dwarf"
  166. (DWARF's CFI - Call Frame Information) or "lbr"
  167. (Hardware Last Branch Record facility) as the method to collect
  168. the information used to show the call graphs.
  169. In some systems, where binaries are build with gcc
  170. --fomit-frame-pointer, using the "fp" method will produce bogus
  171. call graphs, using "dwarf", if available (perf tools linked to
  172. the libunwind or libdw library) should be used instead.
  173. Using the "lbr" method doesn't require any compiler options. It
  174. will produce call graphs from the hardware LBR registers. The
  175. main limition is that it is only available on new Intel
  176. platforms, such as Haswell. It can only get user call chain. It
  177. doesn't work with branch stack sampling at the same time.
  178. When "dwarf" recording is used, perf also records (user) stack dump
  179. when sampled. Default size of the stack dump is 8192 (bytes).
  180. User can change the size by passing the size after comma like
  181. "--call-graph dwarf,4096".
  182. -q::
  183. --quiet::
  184. Don't print any message, useful for scripting.
  185. -v::
  186. --verbose::
  187. Be more verbose (show counter open errors, etc).
  188. -s::
  189. --stat::
  190. Record per-thread event counts. Use it with 'perf report -T' to see
  191. the values.
  192. -d::
  193. --data::
  194. Record the sample addresses.
  195. -T::
  196. --timestamp::
  197. Record the sample timestamps. Use it with 'perf report -D' to see the
  198. timestamps, for instance.
  199. -P::
  200. --period::
  201. Record the sample period.
  202. --sample-cpu::
  203. Record the sample cpu.
  204. -n::
  205. --no-samples::
  206. Don't sample.
  207. -R::
  208. --raw-samples::
  209. Collect raw sample records from all opened counters (default for tracepoint counters).
  210. -C::
  211. --cpu::
  212. Collect samples only on the list of CPUs provided. Multiple CPUs can be provided as a
  213. comma-separated list with no space: 0,1. Ranges of CPUs are specified with -: 0-2.
  214. In per-thread mode with inheritance mode on (default), samples are captured only when
  215. the thread executes on the designated CPUs. Default is to monitor all CPUs.
  216. -B::
  217. --no-buildid::
  218. Do not save the build ids of binaries in the perf.data files. This skips
  219. post processing after recording, which sometimes makes the final step in
  220. the recording process to take a long time, as it needs to process all
  221. events looking for mmap records. The downside is that it can misresolve
  222. symbols if the workload binaries used when recording get locally rebuilt
  223. or upgraded, because the only key available in this case is the
  224. pathname. You can also set the "record.build-id" config variable to
  225. 'skip to have this behaviour permanently.
  226. -N::
  227. --no-buildid-cache::
  228. Do not update the buildid cache. This saves some overhead in situations
  229. where the information in the perf.data file (which includes buildids)
  230. is sufficient. You can also set the "record.build-id" config variable to
  231. 'no-cache' to have the same effect.
  232. -G name,...::
  233. --cgroup name,...::
  234. monitor only in the container (cgroup) called "name". This option is available only
  235. in per-cpu mode. The cgroup filesystem must be mounted. All threads belonging to
  236. container "name" are monitored when they run on the monitored CPUs. Multiple cgroups
  237. can be provided. Each cgroup is applied to the corresponding event, i.e., first cgroup
  238. to first event, second cgroup to second event and so on. It is possible to provide
  239. an empty cgroup (monitor all the time) using, e.g., -G foo,,bar. Cgroups must have
  240. corresponding events, i.e., they always refer to events defined earlier on the command
  241. line.
  242. -b::
  243. --branch-any::
  244. Enable taken branch stack sampling. Any type of taken branch may be sampled.
  245. This is a shortcut for --branch-filter any. See --branch-filter for more infos.
  246. -j::
  247. --branch-filter::
  248. Enable taken branch stack sampling. Each sample captures a series of consecutive
  249. taken branches. The number of branches captured with each sample depends on the
  250. underlying hardware, the type of branches of interest, and the executed code.
  251. It is possible to select the types of branches captured by enabling filters. The
  252. following filters are defined:
  253. - any: any type of branches
  254. - any_call: any function call or system call
  255. - any_ret: any function return or system call return
  256. - ind_call: any indirect branch
  257. - call: direct calls, including far (to/from kernel) calls
  258. - u: only when the branch target is at the user level
  259. - k: only when the branch target is in the kernel
  260. - hv: only when the target is at the hypervisor level
  261. - in_tx: only when the target is in a hardware transaction
  262. - no_tx: only when the target is not in a hardware transaction
  263. - abort_tx: only when the target is a hardware transaction abort
  264. - cond: conditional branches
  265. +
  266. The option requires at least one branch type among any, any_call, any_ret, ind_call, cond.
  267. The privilege levels may be omitted, in which case, the privilege levels of the associated
  268. event are applied to the branch filter. Both kernel (k) and hypervisor (hv) privilege
  269. levels are subject to permissions. When sampling on multiple events, branch stack sampling
  270. is enabled for all the sampling events. The sampled branch type is the same for all events.
  271. The various filters must be specified as a comma separated list: --branch-filter any_ret,u,k
  272. Note that this feature may not be available on all processors.
  273. --weight::
  274. Enable weightened sampling. An additional weight is recorded per sample and can be
  275. displayed with the weight and local_weight sort keys. This currently works for TSX
  276. abort events and some memory events in precise mode on modern Intel CPUs.
  277. --transaction::
  278. Record transaction flags for transaction related events.
  279. --per-thread::
  280. Use per-thread mmaps. By default per-cpu mmaps are created. This option
  281. overrides that and uses per-thread mmaps. A side-effect of that is that
  282. inheritance is automatically disabled. --per-thread is ignored with a warning
  283. if combined with -a or -C options.
  284. -D::
  285. --delay=::
  286. After starting the program, wait msecs before measuring. This is useful to
  287. filter out the startup phase of the program, which is often very different.
  288. -I::
  289. --intr-regs::
  290. Capture machine state (registers) at interrupt, i.e., on counter overflows for
  291. each sample. List of captured registers depends on the architecture. This option
  292. is off by default. It is possible to select the registers to sample using their
  293. symbolic names, e.g. on x86, ax, si. To list the available registers use
  294. --intr-regs=\?. To name registers, pass a comma separated list such as
  295. --intr-regs=ax,bx. The list of register is architecture dependent.
  296. --running-time::
  297. Record running and enabled time for read events (:S)
  298. -k::
  299. --clockid::
  300. Sets the clock id to use for the various time fields in the perf_event_type
  301. records. See clock_gettime(). In particular CLOCK_MONOTONIC and
  302. CLOCK_MONOTONIC_RAW are supported, some events might also allow
  303. CLOCK_BOOTTIME, CLOCK_REALTIME and CLOCK_TAI.
  304. -S::
  305. --snapshot::
  306. Select AUX area tracing Snapshot Mode. This option is valid only with an
  307. AUX area tracing event. Optionally the number of bytes to capture per
  308. snapshot can be specified. In Snapshot Mode, trace data is captured only when
  309. signal SIGUSR2 is received.
  310. --proc-map-timeout::
  311. When processing pre-existing threads /proc/XXX/mmap, it may take a long time,
  312. because the file may be huge. A time out is needed in such cases.
  313. This option sets the time out limit. The default value is 500 ms.
  314. --switch-events::
  315. Record context switch events i.e. events of type PERF_RECORD_SWITCH or
  316. PERF_RECORD_SWITCH_CPU_WIDE.
  317. --clang-path=PATH::
  318. Path to clang binary to use for compiling BPF scriptlets.
  319. (enabled when BPF support is on)
  320. --clang-opt=OPTIONS::
  321. Options passed to clang when compiling BPF scriptlets.
  322. (enabled when BPF support is on)
  323. --vmlinux=PATH::
  324. Specify vmlinux path which has debuginfo.
  325. (enabled when BPF prologue is on)
  326. --buildid-all::
  327. Record build-id of all DSOs regardless whether it's actually hit or not.
  328. --all-kernel::
  329. Configure all used events to run in kernel space.
  330. --all-user::
  331. Configure all used events to run in user space.
  332. --timestamp-filename
  333. Append timestamp to output file name.
  334. --switch-output::
  335. Generate multiple perf.data files, timestamp prefixed, switching to a new one
  336. when receiving a SIGUSR2.
  337. A possible use case is to, given an external event, slice the perf.data file
  338. that gets then processed, possibly via a perf script, to decide if that
  339. particular perf.data snapshot should be kept or not.
  340. Implies --timestamp-filename, --no-buildid and --no-buildid-cache.
  341. --dry-run::
  342. Parse options then exit. --dry-run can be used to detect errors in cmdline
  343. options.
  344. 'perf record --dry-run -e' can act as a BPF script compiler if llvm.dump-obj
  345. in config file is set to true.
  346. --tail-synthesize::
  347. Instead of collecting non-sample events (for example, fork, comm, mmap) at
  348. the beginning of record, collect them during finalizing an output file.
  349. The collected non-sample events reflects the status of the system when
  350. record is finished.
  351. --overwrite::
  352. Makes all events use an overwritable ring buffer. An overwritable ring
  353. buffer works like a flight recorder: when it gets full, the kernel will
  354. overwrite the oldest records, that thus will never make it to the
  355. perf.data file.
  356. When '--overwrite' and '--switch-output' are used perf records and drops
  357. events until it receives a signal, meaning that something unusual was
  358. detected that warrants taking a snapshot of the most current events,
  359. those fitting in the ring buffer at that moment.
  360. 'overwrite' attribute can also be set or canceled for an event using
  361. config terms. For example: 'cycles/overwrite/' and 'instructions/no-overwrite/'.
  362. Implies --tail-synthesize.
  363. SEE ALSO
  364. --------
  365. linkperf:perf-stat[1], linkperf:perf-list[1]