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           Capture user registers at sample time. Same arguments as -I.
410
411       --running-time
412           Record running and enabled time for read events (:S)
413
414       -k, --clockid
415           Sets the clock id to use for the various time fields in the
416           perf_event_type records. See clock_gettime(). In particular
417           CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW are supported, some events
418           might also allow CLOCK_BOOTTIME, CLOCK_REALTIME and CLOCK_TAI.
419
420       -S, --snapshot
421           Select AUX area tracing Snapshot Mode. This option is valid only
422           with an AUX area tracing event. Optionally the number of bytes to
423           capture per snapshot can be specified. In Snapshot Mode, trace data
424           is captured only when signal SIGUSR2 is received.
425
426       --proc-map-timeout
427           When processing pre-existing threads /proc/XXX/mmap, it may take a
428           long time, because the file may be huge. A time out is needed in
429           such cases. This option sets the time out limit. The default value
430           is 500 ms.
431
432       --switch-events
433           Record context switch events i.e. events of type PERF_RECORD_SWITCH
434           or PERF_RECORD_SWITCH_CPU_WIDE.
435
436       --clang-path=PATH
437           Path to clang binary to use for compiling BPF scriptlets. (enabled
438           when BPF support is on)
439
440       --clang-opt=OPTIONS
441           Options passed to clang when compiling BPF scriptlets. (enabled
442           when BPF support is on)
443
444       --vmlinux=PATH
445           Specify vmlinux path which has debuginfo. (enabled when BPF
446           prologue is on)
447
448       --buildid-all
449           Record build-id of all DSOs regardless whether it’s actually hit or
450           not.
451
452       --aio[=n]
453           Use <n> control blocks in asynchronous (Posix AIO) trace writing
454           mode (default: 1, max: 4). Asynchronous mode is supported only when
455           linking Perf tool with libc library providing implementation for
456           Posix AIO API.
457
458       --affinity=mode
459           Set affinity mask of trace reading thread according to the policy
460           defined by mode value: node - thread affinity mask is set to NUMA
461           node cpu mask of the processed mmap buffer cpu - thread affinity
462           mask is set to cpu of the processed mmap buffer
463
464       --all-kernel
465           Configure all used events to run in kernel space.
466
467       --all-user
468           Configure all used events to run in user space.
469
470       --timestamp-filename Append timestamp to output file name.
471
472       --timestamp-boundary
473           Record timestamp boundary (time of first/last samples).
474
475       --switch-output[=mode]
476           Generate multiple perf.data files, timestamp prefixed, switching to
477           a new one based on mode value: "signal" - when receiving a SIGUSR2
478           (default value) or <size> - when reaching the size threshold, size
479           is expected to be a number with appended unit character - B/K/M/G
480           <time> - when reaching the time threshold, size is expected to be a
481           number with appended unit character - s/m/h/d
482
483               Note: the precision of  the size  threshold  hugely depends
484               on your configuration  - the number and size of  your  ring
485               buffers (-m). It is generally more precise for higher sizes
486               (like >5M), for lower values expect different sizes.
487
488       A possible use case is to, given an external event, slice the perf.data
489       file that gets then processed, possibly via a perf script, to decide if
490       that particular perf.data snapshot should be kept or not.
491
492       Implies --timestamp-filename, --no-buildid and --no-buildid-cache. The
493       reason for the latter two is to reduce the data file switching
494       overhead. You can still switch them on with:
495
496           --switch-output --no-no-buildid  --no-no-buildid-cache
497
498       --switch-max-files=N
499           When rotating perf.data with --switch-output, only keep N files.
500
501       --dry-run
502           Parse options then exit. --dry-run can be used to detect errors in
503           cmdline options.
504
505       perf record --dry-run -e can act as a BPF script compiler if
506       llvm.dump-obj in config file is set to true.
507
508       --tail-synthesize
509           Instead of collecting non-sample events (for example, fork, comm,
510           mmap) at the beginning of record, collect them during finalizing an
511           output file. The collected non-sample events reflects the status of
512           the system when record is finished.
513
514       --overwrite
515           Makes all events use an overwritable ring buffer. An overwritable
516           ring buffer works like a flight recorder: when it gets full, the
517           kernel will overwrite the oldest records, that thus will never make
518           it to the perf.data file.
519
520       When --overwrite and --switch-output are used perf records and drops
521       events until it receives a signal, meaning that something unusual was
522       detected that warrants taking a snapshot of the most current events,
523       those fitting in the ring buffer at that moment.
524
525       overwrite attribute can also be set or canceled for an event using
526       config terms. For example: cycles/overwrite/ and
527       instructions/no-overwrite/.
528
529       Implies --tail-synthesize.
530

SEE ALSO

532       perf-stat(1), perf-list(1)
533
534
535
536perf                              06/03/2019                    PERF-RECORD(1)
Impressum