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