1PERF-RECORD(1)                    perf Manual                   PERF-RECORD(1)
2
3
4

NAME

6       perf-record - Run a command and record its profile into perf.data
7

SYNOPSIS

9       perf record [-e <EVENT> | --event=EVENT] [-a] <command>
10       perf record [-e <EVENT> | --event=EVENT] [-a] — <command> [<options>]
11

DESCRIPTION

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

OPTIONS

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

SEE ALSO

569       perf-stat(1), perf-list(1)
570
571
572
573perf                              11/12/2019                    PERF-RECORD(1)
Impressum