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