perf-record.txt 19 KB

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