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 in the form of rN where N is a hexadecimal
28 value that represents the raw register encoding with the layout
29 of the event control registers as described by entries in
30 /sys/bus/event_source/devices/cpu/format/*.
31
32 • a symbolic or raw PMU event followed by an optional colon and a
33 list of event modifiers, e.g., cpu-cycles:p. See the perf-
34 list(1) man page for details on event modifiers.
35
36 • a symbolically formed PMU event like pmu/param1=0x3,param2/
37 where param1, param2, etc are defined as formats for the PMU in
38 /sys/bus/event_source/devices/<pmu>/format/*.
39
40 • a symbolically formed event like
41 pmu/config=M,config1=N,config3=K/
42
43 where M, N, K are numbers (in decimal, hex, octal format). Acceptable
44 values for each of 'config', 'config1' and 'config2' are defined by
45 corresponding entries in /sys/bus/event_source/devices/<pmu>/format/*
46 param1 and param2 are defined as formats for the PMU in:
47 /sys/bus/event_source/devices/<pmu>/format/*
48
49 There are also some parameters which are not defined in .../<pmu>/format/*.
50 These params can be used to overload default config values per event.
51 Here are some common parameters:
52 - 'period': Set event sampling period
53 - 'freq': Set event sampling frequency
54 - 'time': Disable/enable time stamping. Acceptable values are 1 for
55 enabling time stamping. 0 for disabling time stamping.
56 The default is 1.
57 - 'call-graph': Disable/enable callgraph. Acceptable str are "fp" for
58 FP mode, "dwarf" for DWARF mode, "lbr" for LBR mode and
59 "no" for disable callgraph.
60 - 'stack-size': user stack size for dwarf mode
61 - 'name' : User defined event name. Single quotes (') may be used to
62 escape symbols in the name from parsing by shell and tool
63 like this: name=\'CPU_CLK_UNHALTED.THREAD:cmask=0x1\'.
64 - 'aux-output': Generate AUX records instead of events. This requires
65 that an AUX area event is also provided.
66 - 'aux-sample-size': Set sample size for AUX area sampling. If the
67 '--aux-sample' option has been used, set aux-sample-size=0 to disable
68 AUX area sampling for the event.
69
70 See the linkperf:perf-list[1] man page for more parameters.
71
72 Note: If user explicitly sets options which conflict with the params,
73 the value set by the parameters will be overridden.
74
75 Also not defined in .../<pmu>/format/* are PMU driver specific
76 configuration parameters. Any configuration parameter preceded by
77 the letter '@' is not interpreted in user space and sent down directly
78 to the PMU driver. For example:
79
80 perf record -e some_event/@cfg1,@cfg2=config/ ...
81
82 will see 'cfg1' and 'cfg2=config' pushed to the PMU driver associated
83 with the event for further processing. There is no restriction on
84 what the configuration parameters are, as long as their semantic is
85 understood and supported by the PMU driver.
86
87 • a hardware breakpoint event in the form of
88 \mem:addr[/len][:access] where addr is the address in memory
89 you want to break in. Access is the memory access type (read,
90 write, execute) it can be passed as follows:
91 \mem:addr[:[r][w][x]]. len is the range, number of bytes from
92 specified addr, which the breakpoint will cover. If you want to
93 profile read-write accesses in 0x1000, just set mem:0x1000:rw.
94 If you want to profile write accesses in [0x1000~1008), just
95 set mem:0x1000/8:w.
96
97 • a group of events surrounded by a pair of brace
98 ("{event1,event2,...}"). Each event is separated by commas and
99 the group should be quoted to prevent the shell interpretation.
100 You also need to use --group on "perf report" to view group
101 events together.
102
103 --filter=<filter>
104 Event filter. This option should follow an event selector (-e). If
105 the event is a tracepoint, the filter string will be parsed by the
106 kernel. If the event is a hardware trace PMU (e.g. Intel PT or
107 CoreSight), it’ll be processed as an address filter. Otherwise it
108 means a general filter using BPF which can be applied for any kind
109 of event.
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 • bpf filters
165
166 A BPF filter can access the sample data and make a decision based on the
167 data. Users need to set an appropriate sample type to use the BPF
168 filter. BPF filters need root privilege.
169
170 The sample data field can be specified in lower case letter. Multiple
171 filters can be separated with comma. For example,
172
173 --filter 'period > 1000, cpu == 1'
174 or
175 --filter 'mem_op == load || mem_op == store, mem_lvl > l1'
176
177 The former filter only accept samples with period greater than 1000 AND
178 CPU number is 1. The latter one accepts either load and store memory
179 operations but it should have memory level above the L1. Since the
180 mem_op and mem_lvl fields come from the (memory) data_source, it'd only
181 work with some events which set the data_source field.
182
183 Also user should request to collect that information (with -d option in
184 the above case). Otherwise, the following message will be shown.
185
186 $ sudo perf record -e cycles --filter 'mem_op == load'
187 Error: cycles event does not have PERF_SAMPLE_DATA_SRC
188 Hint: please add -d option to perf record.
189 failed to set filter "BPF" on event cycles with 22 (Invalid argument)
190
191 Essentially the BPF filter expression is:
192
193 <term> <operator> <value> (("," | "||") <term> <operator> <value>)*
194
195 The <term> can be one of:
196 ip, id, tid, pid, cpu, time, addr, period, txn, weight, phys_addr,
197 code_pgsz, data_pgsz, weight1, weight2, weight3, ins_lat, retire_lat,
198 p_stage_cyc, mem_op, mem_lvl, mem_snoop, mem_remote, mem_lock,
199 mem_dtlb, mem_blk, mem_hops
200
201 The <operator> can be one of:
202 ==, !=, >, >=, <, <=, &
203
204 The <value> can be one of:
205 <number> (for any term)
206 na, load, store, pfetch, exec (for mem_op)
207 l1, l2, l3, l4, cxl, io, any_cache, lfb, ram, pmem (for mem_lvl)
208 na, none, hit, miss, hitm, fwd, peer (for mem_snoop)
209 remote (for mem_remote)
210 na, locked (for mem_locked)
211 na, l1_hit, l1_miss, l2_hit, l2_miss, any_hit, any_miss, walk, fault (for mem_dtlb)
212 na, by_data, by_addr (for mem_blk)
213 hops0, hops1, hops2, hops3 (for mem_hops)
214
215 --exclude-perf
216 Don’t record events issued by perf itself. This option should
217 follow an event selector (-e) which selects tracepoint event(s). It
218 adds a filter expression common_pid != $PERFPID to filters. If
219 other --filter exists, the new filter expression will be combined
220 with them by &&.
221
222 -a, --all-cpus
223 System-wide collection from all CPUs (default if no target is
224 specified).
225
226 -p, --pid=
227 Record events on existing process ID (comma separated list).
228
229 -t, --tid=
230 Record events on existing thread ID (comma separated list). This
231 option also disables inheritance by default. Enable it by adding
232 --inherit.
233
234 -u, --uid=
235 Record events in threads owned by uid. Name or number.
236
237 -r, --realtime=
238 Collect data with this RT SCHED_FIFO priority.
239
240 --no-buffering
241 Collect data without buffering.
242
243 -c, --count=
244 Event period to sample.
245
246 -o, --output=
247 Output file name.
248
249 -i, --no-inherit
250 Child tasks do not inherit counters.
251
252 -F, --freq=
253 Profile at this frequency. Use max to use the currently maximum
254 allowed frequency, i.e. the value in the
255 kernel.perf_event_max_sample_rate sysctl. Will throttle down to the
256 currently maximum allowed frequency. See --strict-freq.
257
258 --strict-freq
259 Fail if the specified frequency can’t be used.
260
261 -m, --mmap-pages=
262 Number of mmap data pages (must be a power of two) or size
263 specification with appended unit character - B/K/M/G. The size is
264 rounded up to have nearest pages power of two value. Also, by
265 adding a comma, the number of mmap pages for AUX area tracing can
266 be specified.
267
268 -g
269 Enables call-graph (stack chain/backtrace) recording for both
270 kernel space and user space.
271
272 --call-graph
273 Setup and enable call-graph (stack chain/backtrace) recording,
274 implies -g. Default is "fp" (for user space).
275
276 The unwinding method used for kernel space is dependent on the
277 unwinder used by the active kernel configuration, i.e
278 CONFIG_UNWINDER_FRAME_POINTER (fp) or CONFIG_UNWINDER_ORC (orc)
279
280 Any option specified here controls the method used for user space.
281
282 Valid options are "fp" (frame pointer), "dwarf" (DWARF's CFI -
283 Call Frame Information) or "lbr" (Hardware Last Branch Record
284 facility).
285
286 In some systems, where binaries are build with gcc
287 --fomit-frame-pointer, using the "fp" method will produce bogus
288 call graphs, using "dwarf", if available (perf tools linked to
289 the libunwind or libdw library) should be used instead.
290 Using the "lbr" method doesn't require any compiler options. It
291 will produce call graphs from the hardware LBR registers. The
292 main limitation is that it is only available on new Intel
293 platforms, such as Haswell. It can only get user call chain. It
294 doesn't work with branch stack sampling at the same time.
295
296 When "dwarf" recording is used, perf also records (user) stack dump
297 when sampled. Default size of the stack dump is 8192 (bytes).
298 User can change the size by passing the size after comma like
299 "--call-graph dwarf,4096".
300
301 When "fp" recording is used, perf tries to save stack enties
302 up to the number specified in sysctl.kernel.perf_event_max_stack
303 by default. User can change the number by passing it after comma
304 like "--call-graph fp,32".
305
306 -q, --quiet
307 Don’t print any warnings or messages, useful for scripting.
308
309 -v, --verbose
310 Be more verbose (show counter open errors, etc).
311
312 -s, --stat
313 Record per-thread event counts. Use it with perf report -T to see
314 the values.
315
316 -d, --data
317 Record the sample virtual addresses.
318
319 --phys-data
320 Record the sample physical addresses.
321
322 --data-page-size
323 Record the sampled data address data page size.
324
325 --code-page-size
326 Record the sampled code address (ip) page size
327
328 -T, --timestamp
329 Record the sample timestamps. Use it with perf report -D to see the
330 timestamps, for instance.
331
332 -P, --period
333 Record the sample period.
334
335 --sample-cpu
336 Record the sample cpu.
337
338 --sample-identifier
339 Record the sample identifier i.e. PERF_SAMPLE_IDENTIFIER bit set in
340 the sample_type member of the struct perf_event_attr argument to
341 the perf_event_open system call.
342
343 -n, --no-samples
344 Don’t sample.
345
346 -R, --raw-samples
347 Collect raw sample records from all opened counters (default for
348 tracepoint counters).
349
350 -C, --cpu
351 Collect samples only on the list of CPUs provided. Multiple CPUs
352 can be provided as a comma-separated list with no space: 0,1.
353 Ranges of CPUs are specified with -: 0-2. In per-thread mode with
354 inheritance mode on (default), samples are captured only when the
355 thread executes on the designated CPUs. Default is to monitor all
356 CPUs.
357
358 -B, --no-buildid
359 Do not save the build ids of binaries in the perf.data files. This
360 skips post processing after recording, which sometimes makes the
361 final step in the recording process to take a long time, as it
362 needs to process all events looking for mmap records. The downside
363 is that it can misresolve symbols if the workload binaries used
364 when recording get locally rebuilt or upgraded, because the only
365 key available in this case is the pathname. You can also set the
366 "record.build-id" config variable to 'skip to have this behaviour
367 permanently.
368
369 -N, --no-buildid-cache
370 Do not update the buildid cache. This saves some overhead in
371 situations where the information in the perf.data file (which
372 includes buildids) is sufficient. You can also set the
373 "record.build-id" config variable to no-cache to have the same
374 effect.
375
376 -G name,..., --cgroup name,...
377 monitor only in the container (cgroup) called "name". This option
378 is available only in per-cpu mode. The cgroup filesystem must be
379 mounted. All threads belonging to container "name" are monitored
380 when they run on the monitored CPUs. Multiple cgroups can be
381 provided. Each cgroup is applied to the corresponding event, i.e.,
382 first cgroup to first event, second cgroup to second event and so
383 on. It is possible to provide an empty cgroup (monitor all the
384 time) using, e.g., -G foo,,bar. Cgroups must have corresponding
385 events, i.e., they always refer to events defined earlier on the
386 command line. If the user wants to track multiple events for a
387 specific cgroup, the user can use -e e1 -e e2 -G foo,foo or just
388 use -e e1 -e e2 -G foo.
389
390 If wanting to monitor, say, cycles for a cgroup and also for system
391 wide, this command line can be used: perf stat -e cycles -G cgroup_name
392 -a -e cycles.
393
394 -b, --branch-any
395 Enable taken branch stack sampling. Any type of taken branch may be
396 sampled. This is a shortcut for --branch-filter any. See
397 --branch-filter for more infos.
398
399 -j, --branch-filter
400 Enable taken branch stack sampling. Each sample captures a series
401 of consecutive taken branches. The number of branches captured with
402 each sample depends on the underlying hardware, the type of
403 branches of interest, and the executed code. It is possible to
404 select the types of branches captured by enabling filters. The
405 following filters are defined:
406
407 • any: any type of branches
408
409 • any_call: any function call or system call
410
411 • any_ret: any function return or system call return
412
413 • ind_call: any indirect branch
414
415 • ind_jmp: any indirect jump
416
417 • call: direct calls, including far (to/from kernel) calls
418
419 • u: only when the branch target is at the user level
420
421 • k: only when the branch target is in the kernel
422
423 • hv: only when the target is at the hypervisor level
424
425 • in_tx: only when the target is in a hardware transaction
426
427 • no_tx: only when the target is not in a hardware transaction
428
429 • abort_tx: only when the target is a hardware transaction abort
430
431 • cond: conditional branches
432
433 • call_stack: save call stack
434
435 • no_flags: don’t save branch flags e.g prediction, misprediction
436 etc
437
438 • no_cycles: don’t save branch cycles
439
440 • hw_index: save branch hardware index
441
442 • save_type: save branch type during sampling in case binary is
443 not available later For the platforms with Intel Arch LBR
444 support (12th-Gen+ client or 4th-Gen Xeon+ server), the save
445 branch type is unconditionally enabled when the taken branch
446 stack sampling is enabled.
447
448 • priv: save privilege state during sampling in case binary is
449 not available later
450
451 The option requires at least one branch type among any, any_call,
452 any_ret, ind_call, cond. The privilege levels may be omitted, in
453 which case, the privilege levels of the associated event are
454 applied to the branch filter. Both kernel (k) and hypervisor (hv)
455 privilege levels are subject to permissions. When sampling on
456 multiple events, branch stack sampling is enabled for all the
457 sampling events. The sampled branch type is the same for all
458 events. The various filters must be specified as a comma separated
459 list: --branch-filter any_ret,u,k Note that this feature may not be
460 available on all processors.
461
462 -W, --weight
463 Enable weightened sampling. An additional weight is recorded per
464 sample and can be displayed with the weight and local_weight sort
465 keys. This currently works for TSX abort events and some memory
466 events in precise mode on modern Intel CPUs.
467
468 --namespaces
469 Record events of type PERF_RECORD_NAMESPACES. This enables
470 cgroup_id sort key.
471
472 --all-cgroups
473 Record events of type PERF_RECORD_CGROUP. This enables cgroup sort
474 key.
475
476 --transaction
477 Record transaction flags for transaction related events.
478
479 --per-thread
480 Use per-thread mmaps. By default per-cpu mmaps are created. This
481 option overrides that and uses per-thread mmaps. A side-effect of
482 that is that inheritance is automatically disabled. --per-thread is
483 ignored with a warning if combined with -a or -C options.
484
485 -D, --delay=
486 After starting the program, wait msecs before measuring (-1: start
487 with events disabled), or enable events only for specified ranges
488 of msecs (e.g. -D 10-20,30-40 means wait 10 msecs, enable for 10
489 msecs, wait 10 msecs, enable for 10 msecs, then stop). Note,
490 delaying enabling of events is useful to filter out the startup
491 phase of the program, which is often very different.
492
493 -I, --intr-regs
494 Capture machine state (registers) at interrupt, i.e., on counter
495 overflows for each sample. List of captured registers depends on
496 the architecture. This option is off by default. It is possible to
497 select the registers to sample using their symbolic names, e.g. on
498 x86, ax, si. To list the available registers use --intr-regs=\?. To
499 name registers, pass a comma separated list such as
500 --intr-regs=ax,bx. The list of register is architecture dependent.
501
502 --user-regs
503 Similar to -I, but capture user registers at sample time. To list
504 the available user registers use --user-regs=\?.
505
506 --running-time
507 Record running and enabled time for read events (:S)
508
509 -k, --clockid
510 Sets the clock id to use for the various time fields in the
511 perf_event_type records. See clock_gettime(). In particular
512 CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW are supported, some events
513 might also allow CLOCK_BOOTTIME, CLOCK_REALTIME and CLOCK_TAI.
514
515 -S, --snapshot
516 Select AUX area tracing Snapshot Mode. This option is valid only
517 with an AUX area tracing event. Optionally, certain snapshot
518 capturing parameters can be specified in a string that follows this
519 option:
520
521 • e: take one last snapshot on exit; guarantees that there is at
522 least one snapshot in the output file;
523
524 • <size>: if the PMU supports this, specify the desired snapshot
525 size.
526
527 In Snapshot Mode trace data is captured only when signal SIGUSR2 is
528 received and on exit if the above e option is given.
529
530 --aux-sample[=OPTIONS]
531 Select AUX area sampling. At least one of the events selected by
532 the -e option must be an AUX area event. Samples on other events
533 will be created containing data from the AUX area. Optionally
534 sample size may be specified, otherwise it defaults to 4KiB.
535
536 --proc-map-timeout
537 When processing pre-existing threads /proc/XXX/mmap, it may take a
538 long time, because the file may be huge. A time out is needed in
539 such cases. This option sets the time out limit. The default value
540 is 500 ms.
541
542 --switch-events
543 Record context switch events i.e. events of type PERF_RECORD_SWITCH
544 or PERF_RECORD_SWITCH_CPU_WIDE. In some cases (e.g. Intel PT,
545 CoreSight or Arm SPE) switch events will be enabled automatically,
546 which can be suppressed by by the option --no-switch-events.
547
548 --vmlinux=PATH
549 Specify vmlinux path which has debuginfo. (enabled when BPF
550 prologue is on)
551
552 --buildid-all
553 Record build-id of all DSOs regardless whether it’s actually hit or
554 not.
555
556 --buildid-mmap
557 Record build ids in mmap2 events, disables build id cache (implies
558 --no-buildid).
559
560 --aio[=n]
561 Use <n> control blocks in asynchronous (Posix AIO) trace writing
562 mode (default: 1, max: 4). Asynchronous mode is supported only when
563 linking Perf tool with libc library providing implementation for
564 Posix AIO API.
565
566 --affinity=mode
567 Set affinity mask of trace reading thread according to the policy
568 defined by mode value:
569
570 • node - thread affinity mask is set to NUMA node cpu mask of the
571 processed mmap buffer
572
573 • cpu - thread affinity mask is set to cpu of the processed mmap
574 buffer
575
576 --mmap-flush=number
577 Specify minimal number of bytes that is extracted from mmap data
578 pages and processed for output. One can specify the number using
579 B/K/M/G suffixes.
580
581 The maximal allowed value is a quarter of the size of mmaped data
582 pages.
583
584 The default option value is 1 byte which means that every time that the
585 output writing thread finds some new data in the mmaped buffer the data
586 is extracted, possibly compressed (-z) and written to the output,
587 perf.data or pipe.
588
589 Larger data chunks are compressed more effectively in comparison to
590 smaller chunks so extraction of larger chunks from the mmap data pages
591 is preferable from the perspective of output size reduction.
592
593 Also at some cases executing less output write syscalls with bigger
594 data size can take less time than executing more output write syscalls
595 with smaller data size thus lowering runtime profiling overhead.
596
597 -z, --compression-level[=n]
598 Produce compressed trace using specified level n (default: 1 -
599 fastest compression, 22 - smallest trace)
600
601 --all-kernel
602 Configure all used events to run in kernel space.
603
604 --all-user
605 Configure all used events to run in user space.
606
607 --kernel-callchains
608 Collect callchains only from kernel space. I.e. this option sets
609 perf_event_attr.exclude_callchain_user to 1.
610
611 --user-callchains
612 Collect callchains only from user space. I.e. this option sets
613 perf_event_attr.exclude_callchain_kernel to 1.
614
615 Don’t use both --kernel-callchains and --user-callchains at the same
616 time or no callchains will be collected.
617
618 --timestamp-filename Append timestamp to output file name.
619
620 --timestamp-boundary
621 Record timestamp boundary (time of first/last samples).
622
623 --switch-output[=mode]
624 Generate multiple perf.data files, timestamp prefixed, switching to
625 a new one based on mode value:
626
627 • "signal" - when receiving a SIGUSR2 (default value) or
628
629 • <size> - when reaching the size threshold, size is expected to
630 be a number with appended unit character - B/K/M/G
631
632 • <time> - when reaching the time threshold, size is expected to
633 be a number with appended unit character - s/m/h/d
634
635 Note: the precision of the size threshold hugely depends
636 on your configuration - the number and size of your ring
637 buffers (-m). It is generally more precise for higher sizes
638 (like >5M), for lower values expect different sizes.
639
640 A possible use case is to, given an external event, slice the perf.data
641 file that gets then processed, possibly via a perf script, to decide if
642 that particular perf.data snapshot should be kept or not.
643
644 Implies --timestamp-filename, --no-buildid and --no-buildid-cache. The
645 reason for the latter two is to reduce the data file switching
646 overhead. You can still switch them on with:
647
648 --switch-output --no-no-buildid --no-no-buildid-cache
649
650 --switch-output-event
651 Events that will cause the switch of the perf.data file,
652 auto-selecting --switch-output=signal, the results are similar as
653 internally the side band thread will also send a SIGUSR2 to the
654 main one.
655
656 Uses the same syntax as --event, it will just not be recorded, serving
657 only to switch the perf.data file as soon as the --switch-output event
658 is processed by a separate sideband thread.
659
660 This sideband thread is also used to other purposes, like processing
661 the PERF_RECORD_BPF_EVENT records as they happen, asking the kernel for
662 extra BPF information, etc.
663
664 --switch-max-files=N
665 When rotating perf.data with --switch-output, only keep N files.
666
667 --dry-run
668 Parse options then exit. --dry-run can be used to detect errors in
669 cmdline options.
670
671 perf record --dry-run -e can act as a BPF script compiler if
672 llvm.dump-obj in config file is set to true.
673
674 --synth=TYPE
675 Collect and synthesize given type of events (comma separated). Note
676 that this option controls the synthesis from the /proc filesystem
677 which represent task status for pre-existing threads.
678
679 Kernel (and some other) events are recorded regardless of the choice in
680 this option. For example, --synth=no would have MMAP events for kernel
681 and modules.
682
683 Available types are:
684
685 • task - synthesize FORK and COMM events for each task
686
687 • mmap - synthesize MMAP events for each process (implies task)
688
689 • cgroup - synthesize CGROUP events for each cgroup
690
691 • all - synthesize all events (default)
692
693 • no - do not synthesize any of the above events
694
695 --tail-synthesize
696 Instead of collecting non-sample events (for example, fork,
697 comm, mmap) at the beginning of record, collect them during
698 finalizing an output file. The collected non-sample events
699 reflects the status of the system when record is finished.
700
701 --overwrite
702 Makes all events use an overwritable ring buffer. An
703 overwritable ring buffer works like a flight recorder: when it
704 gets full, the kernel will overwrite the oldest records, that
705 thus will never make it to the perf.data file.
706
707 When --overwrite and --switch-output are used perf records and drops
708 events until it receives a signal, meaning that something unusual was
709 detected that warrants taking a snapshot of the most current events,
710 those fitting in the ring buffer at that moment.
711
712 overwrite attribute can also be set or canceled for an event using
713 config terms. For example: cycles/overwrite/ and
714 instructions/no-overwrite/.
715
716 Implies --tail-synthesize.
717
718 --kcore
719 Make a copy of /proc/kcore and place it into a directory with the
720 perf data file.
721
722 --max-size=<size>
723 Limit the sample data max size, <size> is expected to be a number
724 with appended unit character - B/K/M/G
725
726 --num-thread-synthesize
727 The number of threads to run when synthesizing events for existing
728 processes. By default, the number of threads equals 1.
729
730 --control=fifo:ctl-fifo[,ack-fifo], --control=fd:ctl-fd[,ack-fd]
731 ctl-fifo / ack-fifo are opened and used as ctl-fd / ack-fd as
732 follows. Listen on ctl-fd descriptor for command to control
733 measurement.
734
735 Available commands:
736
737 • enable : enable events
738
739 • disable : disable events
740
741 • enable name : enable event name
742
743 • disable name : disable event name
744
745 • snapshot : AUX area tracing snapshot).
746
747 • stop : stop perf record
748
749 • ping : ping
750
751 • 'evlist [-v|-g|-F] : display all events
752
753 -F Show just the sample frequency used for each event.
754 -v Show all fields.
755 -g Show event group information.
756
757 Measurements can be started with events disabled using --delay=-1
758 option. Optionally send control command completion (ack\n) to ack-fd
759 descriptor to synchronize with the controlling process. Example of bash
760 shell script to enable and disable events during measurements:
761
762 #!/bin/bash
763
764 ctl_dir=/tmp/
765
766 ctl_fifo=${ctl_dir}perf_ctl.fifo
767 test -p ${ctl_fifo} && unlink ${ctl_fifo}
768 mkfifo ${ctl_fifo}
769 exec {ctl_fd}<>${ctl_fifo}
770
771 ctl_ack_fifo=${ctl_dir}perf_ctl_ack.fifo
772 test -p ${ctl_ack_fifo} && unlink ${ctl_ack_fifo}
773 mkfifo ${ctl_ack_fifo}
774 exec {ctl_fd_ack}<>${ctl_ack_fifo}
775
776 perf record -D -1 -e cpu-cycles -a \
777 --control fd:${ctl_fd},${ctl_fd_ack} \
778 -- sleep 30 &
779 perf_pid=$!
780
781 sleep 5 && echo 'enable' >&${ctl_fd} && read -u ${ctl_fd_ack} e1 && echo "enabled(${e1})"
782 sleep 10 && echo 'disable' >&${ctl_fd} && read -u ${ctl_fd_ack} d1 && echo "disabled(${d1})"
783
784 exec {ctl_fd_ack}>&-
785 unlink ${ctl_ack_fifo}
786
787 exec {ctl_fd}>&-
788 unlink ${ctl_fifo}
789
790 wait -n ${perf_pid}
791 exit $?
792
793 --threads=<spec>
794 Write collected trace data into several data files using parallel
795 threads. <spec> value can be user defined list of masks. Masks
796 separated by colon define CPUs to be monitored by a thread and
797 affinity mask of that thread is separated by slash:
798
799 <cpus mask 1>/<affinity mask 1>:<cpus mask 2>/<affinity mask 2>:...
800
801 CPUs or affinity masks must not overlap with other corresponding masks.
802 Invalid CPUs are ignored, but masks containing only invalid CPUs are
803 not allowed.
804
805 For example user specification like the following:
806
807 0,2-4/2-4:1,5-7/5-7
808
809 specifies parallel threads layout that consists of two threads, the
810 first thread monitors CPUs 0 and 2-4 with the affinity mask 2-4, the
811 second monitors CPUs 1 and 5-7 with the affinity mask 5-7.
812
813 <spec> value can also be a string meaning predefined parallel threads
814 layout:
815
816 • cpu - create new data streaming thread for every monitored cpu
817
818 • core - create new thread to monitor CPUs grouped by a core
819
820 • package - create new thread to monitor CPUs grouped by a package
821
822 • numa - create new threed to monitor CPUs grouped by a NUMA domain
823
824 Predefined layouts can be used on systems with large number of CPUs in
825 order not to spawn multiple per-cpu streaming threads but still avoid
826 LOST events in data directory files. Option specified with no or empty
827 value defaults to CPU layout. Masks defined or provided by the option
828 value are filtered through the mask provided by -C option.
829
830 --debuginfod[=URLs]
831 Specify debuginfod URL to be used when cacheing perf.data binaries,
832 it follows the same syntax as the DEBUGINFOD_URLS variable, like:
833
834 http://192.168.122.174:8002
835
836 If the URLs is not specified, the value of DEBUGINFOD_URLS
837 system environment variable is used.
838
839 --off-cpu
840 Enable off-cpu profiling with BPF. The BPF program will collect
841 task scheduling information with (user) stacktrace and save them as
842 sample data of a software event named "offcpu-time". The sample
843 period will have the time the task slept in nanoseconds.
844
845 Note that BPF can collect stack traces using frame pointer ("fp")
846 only, as of now. So the applications built without the frame
847 pointer might see bogus addresses.
848
850 Support for Intel hybrid events within perf tools.
851
852 For some Intel platforms, such as AlderLake, which is hybrid platform
853 and it consists of atom cpu and core cpu. Each cpu has dedicated event
854 list. Part of events are available on core cpu, part of events are
855 available on atom cpu and even part of events are available on both.
856
857 Kernel exports two new cpu pmus via sysfs: /sys/devices/cpu_core
858 /sys/devices/cpu_atom
859
860 The cpus files are created under the directories. For example,
861
862 cat /sys/devices/cpu_core/cpus 0-15
863
864 cat /sys/devices/cpu_atom/cpus 16-23
865
866 It indicates cpu0-cpu15 are core cpus and cpu16-cpu23 are atom cpus.
867
868 As before, use perf-list to list the symbolic event.
869
870 perf list
871
872 inst_retired.any [Fixed Counter: Counts the number of instructions
873 retired. Unit: cpu_atom] inst_retired.any [Number of instructions
874 retired. Fixed Counter - architectural event. Unit: cpu_core]
875
876 The Unit: xxx is added to brief description to indicate which pmu the
877 event is belong to. Same event name but with different pmu can be
878 supported.
879
880 Enable hybrid event with a specific pmu
881
882 To enable a core only event or atom only event, following syntax is
883 supported:
884
885 cpu_core/<event name>/
886 or
887 cpu_atom/<event name>/
888
889 For example, count the cycles event on core cpus.
890
891 perf stat -e cpu_core/cycles/
892
893 Create two events for one hardware event automatically
894
895 When creating one event and the event is available on both atom and
896 core, two events are created automatically. One is for atom, the other
897 is for core. Most of hardware events and cache events are available on
898 both cpu_core and cpu_atom.
899
900 For hardware events, they have pre-defined configs (e.g. 0 for cycles).
901 But on hybrid platform, kernel needs to know where the event comes from
902 (from atom or from core). The original perf event type
903 PERF_TYPE_HARDWARE can’t carry pmu information. So now this type is
904 extended to be PMU aware type. The PMU type ID is stored at
905 attr.config[63:32].
906
907 PMU type ID is retrieved from sysfs. /sys/devices/cpu_atom/type
908 /sys/devices/cpu_core/type
909
910 The new attr.config layout for PERF_TYPE_HARDWARE:
911
912 PERF_TYPE_HARDWARE: 0xEEEEEEEE000000AA AA: hardware event ID EEEEEEEE:
913 PMU type ID
914
915 Cache event is similar. The type PERF_TYPE_HW_CACHE is extended to be
916 PMU aware type. The PMU type ID is stored at attr.config[63:32].
917
918 The new attr.config layout for PERF_TYPE_HW_CACHE:
919
920 PERF_TYPE_HW_CACHE: 0xEEEEEEEE00DDCCBB BB: hardware cache ID CC:
921 hardware cache op ID DD: hardware cache op result ID EEEEEEEE: PMU type
922 ID
923
924 When enabling a hardware event without specified pmu, such as, perf
925 stat -e cycles -a (use system-wide in this example), two events are
926 created automatically.
927
928 ------------------------------------------------------------
929 perf_event_attr:
930 size 120
931 config 0x400000000
932 sample_type IDENTIFIER
933 read_format TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING
934 disabled 1
935 inherit 1
936 exclude_guest 1
937 ------------------------------------------------------------
938
939 and
940
941 ------------------------------------------------------------
942 perf_event_attr:
943 size 120
944 config 0x800000000
945 sample_type IDENTIFIER
946 read_format TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING
947 disabled 1
948 inherit 1
949 exclude_guest 1
950 ------------------------------------------------------------
951
952 type 0 is PERF_TYPE_HARDWARE. 0x4 in 0x400000000 indicates it’s
953 cpu_core pmu. 0x8 in 0x800000000 indicates it’s cpu_atom pmu (atom pmu
954 type id is random).
955
956 The kernel creates cycles (0x400000000) on cpu0-cpu15 (core cpus), and
957 create cycles (0x800000000) on cpu16-cpu23 (atom cpus).
958
959 For perf-stat result, it displays two events:
960
961 Performance counter stats for 'system wide':
962
963 6,744,979 cpu_core/cycles/
964 1,965,552 cpu_atom/cycles/
965
966 The first cycles is core event, the second cycles is atom event.
967
968 Thread mode example:
969
970 perf-stat reports the scaled counts for hybrid event and with a
971 percentage displayed. The percentage is the event’s running
972 time/enabling time.
973
974 One example, triad_loop runs on cpu16 (atom core), while we can see the
975 scaled value for core cycles is 160,444,092 and the percentage is
976 0.47%.
977
978 perf stat -e cycles -- taskset -c 16 ./triad_loop
979
980 As previous, two events are created.
981
982
983 .ft C
984 perf_event_attr:
985 size 120
986 config 0x400000000
987 sample_type IDENTIFIER
988 read_format TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING
989 disabled 1
990 inherit 1
991 enable_on_exec 1
992 exclude_guest 1
993 .ft
994
995
996 and
997
998
999 .ft C
1000 perf_event_attr:
1001 size 120
1002 config 0x800000000
1003 sample_type IDENTIFIER
1004 read_format TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING
1005 disabled 1
1006 inherit 1
1007 enable_on_exec 1
1008 exclude_guest 1
1009 .ft
1010
1011
1012 Performance counter stats for 'taskset -c 16 ./triad_loop':
1013
1014 233,066,666 cpu_core/cycles/ (0.43%)
1015 604,097,080 cpu_atom/cycles/ (99.57%)
1016
1017 perf-record:
1018
1019 If there is no -e specified in perf record, on hybrid platform, it
1020 creates two default cycles and adds them to event list. One is for
1021 core, the other is for atom.
1022
1023 perf-stat:
1024
1025 If there is no -e specified in perf stat, on hybrid platform, besides
1026 of software events, following events are created and added to event
1027 list in order.
1028
1029 cpu_core/cycles/, cpu_atom/cycles/, cpu_core/instructions/,
1030 cpu_atom/instructions/, cpu_core/branches/, cpu_atom/branches/,
1031 cpu_core/branch-misses/, cpu_atom/branch-misses/
1032
1033 Of course, both perf-stat and perf-record support to enable hybrid
1034 event with a specific pmu.
1035
1036 e.g. perf stat -e cpu_core/cycles/ perf stat -e cpu_atom/cycles/ perf
1037 stat -e cpu_core/r1a/ perf stat -e cpu_atom/L1-icache-loads/ perf stat
1038 -e cpu_core/cycles/,cpu_atom/instructions/ perf stat -e
1039 {cpu_core/cycles/,cpu_core/instructions/}
1040
1041 But {cpu_core/cycles/,cpu_atom/instructions/} will return warning and
1042 disable grouping, because the pmus in group are not matched (cpu_core
1043 vs. cpu_atom).
1044
1046 perf-stat(1), perf-list(1), perf-intel-pt(1)
1047
1048
1049
1050perf 11/28/2023 PERF-RECORD(1)