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_sources/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 BPF source file (ending in .c) or a precompiled object file
98 (ending in .o) selects one or more BPF events. The BPF program
99 can attach to various perf events based on the ELF section
100 names.
101
102 When processing a '.c' file, perf searches an installed LLVM to compile it
103 into an object file first. Optional clang options can be passed via the
104 '--clang-opt' command line option, e.g.:
105
106 perf record --clang-opt "-DLINUX_VERSION_CODE=0x50000" \
107 -e tests/bpf-script-example.c
108
109 Note: '--clang-opt' must be placed before '--event/-e'.
110
111 • a group of events surrounded by a pair of brace
112 ("{event1,event2,...}"). Each event is separated by commas and
113 the group should be quoted to prevent the shell interpretation.
114 You also need to use --group on "perf report" to view group
115 events together.
116
117 --filter=<filter>
118 Event filter. This option should follow an event selector (-e)
119 which selects either tracepoint event(s) or a hardware trace PMU
120 (e.g. Intel PT or CoreSight).
121
122 • tracepoint filters
123
124 In the case of tracepoints, multiple '--filter' options are combined
125 using '&&'.
126
127 • address filters
128
129 A hardware trace PMU advertises its ability to accept a number of
130 address filters by specifying a non-zero value in
131 /sys/bus/event_source/devices/<pmu>/nr_addr_filters.
132
133 Address filters have the format:
134
135 filter|start|stop|tracestop <start> [/ <size>] [@<file name>]
136
137 Where:
138 - 'filter': defines a region that will be traced.
139 - 'start': defines an address at which tracing will begin.
140 - 'stop': defines an address at which tracing will stop.
141 - 'tracestop': defines a region in which tracing will stop.
142
143 <file name> is the name of the object file, <start> is the offset to the
144 code to trace in that file, and <size> is the size of the region to
145 trace. 'start' and 'stop' filters need not specify a <size>.
146
147 If no object file is specified then the kernel is assumed, in which case
148 the start address must be a current kernel memory address.
149
150 <start> can also be specified by providing the name of a symbol. If the
151 symbol name is not unique, it can be disambiguated by inserting #n where
152 'n' selects the n'th symbol in address order. Alternately #0, #g or #G
153 select only a global symbol. <size> can also be specified by providing
154 the name of a symbol, in which case the size is calculated to the end
155 of that symbol. For 'filter' and 'tracestop' filters, if <size> is
156 omitted and <start> is a symbol, then the size is calculated to the end
157 of that symbol.
158
159 If <size> is omitted and <start> is '*', then the start and size will
160 be calculated from the first and last symbols, i.e. to trace the whole
161 file.
162
163 If symbol names (or '*') are provided, they must be surrounded by white
164 space.
165
166 The filter passed to the kernel is not necessarily the same as entered.
167 To see the filter that is passed, use the -v option.
168
169 The kernel may not be able to configure a trace region if it is not
170 within a single mapping. MMAP events (or /proc/<pid>/maps) can be
171 examined to determine if that is a possibility.
172
173 Multiple filters can be separated with space or comma.
174
175 --exclude-perf
176 Don’t record events issued by perf itself. This option should
177 follow an event selector (-e) which selects tracepoint event(s). It
178 adds a filter expression common_pid != $PERFPID to filters. If
179 other --filter exists, the new filter expression will be combined
180 with them by &&.
181
182 -a, --all-cpus
183 System-wide collection from all CPUs (default if no target is
184 specified).
185
186 -p, --pid=
187 Record events on existing process ID (comma separated list).
188
189 -t, --tid=
190 Record events on existing thread ID (comma separated list). This
191 option also disables inheritance by default. Enable it by adding
192 --inherit.
193
194 -u, --uid=
195 Record events in threads owned by uid. Name or number.
196
197 -r, --realtime=
198 Collect data with this RT SCHED_FIFO priority.
199
200 --no-buffering
201 Collect data without buffering.
202
203 -c, --count=
204 Event period to sample.
205
206 -o, --output=
207 Output file name.
208
209 -i, --no-inherit
210 Child tasks do not inherit counters.
211
212 -F, --freq=
213 Profile at this frequency. Use max to use the currently maximum
214 allowed frequency, i.e. the value in the
215 kernel.perf_event_max_sample_rate sysctl. Will throttle down to the
216 currently maximum allowed frequency. See --strict-freq.
217
218 --strict-freq
219 Fail if the specified frequency can’t be used.
220
221 -m, --mmap-pages=
222 Number of mmap data pages (must be a power of two) or size
223 specification with appended unit character - B/K/M/G. The size is
224 rounded up to have nearest pages power of two value. Also, by
225 adding a comma, the number of mmap pages for AUX area tracing can
226 be specified.
227
228 --group
229 Put all events in a single event group. This precedes the --event
230 option and remains only for backward compatibility. See --event.
231
232 -g
233 Enables call-graph (stack chain/backtrace) recording for both
234 kernel space and user space.
235
236 --call-graph
237 Setup and enable call-graph (stack chain/backtrace) recording,
238 implies -g. Default is "fp" (for user space).
239
240 The unwinding method used for kernel space is dependent on the
241 unwinder used by the active kernel configuration, i.e
242 CONFIG_UNWINDER_FRAME_POINTER (fp) or CONFIG_UNWINDER_ORC (orc)
243
244 Any option specified here controls the method used for user space.
245
246 Valid options are "fp" (frame pointer), "dwarf" (DWARF's CFI -
247 Call Frame Information) or "lbr" (Hardware Last Branch Record
248 facility).
249
250 In some systems, where binaries are build with gcc
251 --fomit-frame-pointer, using the "fp" method will produce bogus
252 call graphs, using "dwarf", if available (perf tools linked to
253 the libunwind or libdw library) should be used instead.
254 Using the "lbr" method doesn't require any compiler options. It
255 will produce call graphs from the hardware LBR registers. The
256 main limitation is that it is only available on new Intel
257 platforms, such as Haswell. It can only get user call chain. It
258 doesn't work with branch stack sampling at the same time.
259
260 When "dwarf" recording is used, perf also records (user) stack dump
261 when sampled. Default size of the stack dump is 8192 (bytes).
262 User can change the size by passing the size after comma like
263 "--call-graph dwarf,4096".
264
265 -q, --quiet
266 Don’t print any message, useful for scripting.
267
268 -v, --verbose
269 Be more verbose (show counter open errors, etc).
270
271 -s, --stat
272 Record per-thread event counts. Use it with perf report -T to see
273 the values.
274
275 -d, --data
276 Record the sample virtual addresses.
277
278 --phys-data
279 Record the sample physical addresses.
280
281 --data-page-size
282 Record the sampled data address data page size.
283
284 --code-page-size
285 Record the sampled code address (ip) page size
286
287 -T, --timestamp
288 Record the sample timestamps. Use it with perf report -D to see the
289 timestamps, for instance.
290
291 -P, --period
292 Record the sample period.
293
294 --sample-cpu
295 Record the sample cpu.
296
297 -n, --no-samples
298 Don’t sample.
299
300 -R, --raw-samples
301 Collect raw sample records from all opened counters (default for
302 tracepoint counters).
303
304 -C, --cpu
305 Collect samples only on the list of CPUs provided. Multiple CPUs
306 can be provided as a comma-separated list with no space: 0,1.
307 Ranges of CPUs are specified with -: 0-2. In per-thread mode with
308 inheritance mode on (default), samples are captured only when the
309 thread executes on the designated CPUs. Default is to monitor all
310 CPUs.
311
312 -B, --no-buildid
313 Do not save the build ids of binaries in the perf.data files. This
314 skips post processing after recording, which sometimes makes the
315 final step in the recording process to take a long time, as it
316 needs to process all events looking for mmap records. The downside
317 is that it can misresolve symbols if the workload binaries used
318 when recording get locally rebuilt or upgraded, because the only
319 key available in this case is the pathname. You can also set the
320 "record.build-id" config variable to 'skip to have this behaviour
321 permanently.
322
323 -N, --no-buildid-cache
324 Do not update the buildid cache. This saves some overhead in
325 situations where the information in the perf.data file (which
326 includes buildids) is sufficient. You can also set the
327 "record.build-id" config variable to no-cache to have the same
328 effect.
329
330 -G name,..., --cgroup name,...
331 monitor only in the container (cgroup) called "name". This option
332 is available only in per-cpu mode. The cgroup filesystem must be
333 mounted. All threads belonging to container "name" are monitored
334 when they run on the monitored CPUs. Multiple cgroups can be
335 provided. Each cgroup is applied to the corresponding event, i.e.,
336 first cgroup to first event, second cgroup to second event and so
337 on. It is possible to provide an empty cgroup (monitor all the
338 time) using, e.g., -G foo,,bar. Cgroups must have corresponding
339 events, i.e., they always refer to events defined earlier on the
340 command line. If the user wants to track multiple events for a
341 specific cgroup, the user can use -e e1 -e e2 -G foo,foo or just
342 use -e e1 -e e2 -G foo.
343
344 If wanting to monitor, say, cycles for a cgroup and also for system
345 wide, this command line can be used: perf stat -e cycles -G cgroup_name
346 -a -e cycles.
347
348 -b, --branch-any
349 Enable taken branch stack sampling. Any type of taken branch may be
350 sampled. This is a shortcut for --branch-filter any. See
351 --branch-filter for more infos.
352
353 -j, --branch-filter
354 Enable taken branch stack sampling. Each sample captures a series
355 of consecutive taken branches. The number of branches captured with
356 each sample depends on the underlying hardware, the type of
357 branches of interest, and the executed code. It is possible to
358 select the types of branches captured by enabling filters. The
359 following filters are defined:
360
361 • any: any type of branches
362
363 • any_call: any function call or system call
364
365 • any_ret: any function return or system call return
366
367 • ind_call: any indirect branch
368
369 • call: direct calls, including far (to/from kernel) calls
370
371 • u: only when the branch target is at the user level
372
373 • k: only when the branch target is in the kernel
374
375 • hv: only when the target is at the hypervisor level
376
377 • in_tx: only when the target is in a hardware transaction
378
379 • no_tx: only when the target is not in a hardware transaction
380
381 • abort_tx: only when the target is a hardware transaction abort
382
383 • cond: conditional branches
384
385 • save_type: save branch type during sampling in case binary is
386 not available later
387
388 The option requires at least one branch type among any, any_call,
389 any_ret, ind_call, cond. The privilege levels may be omitted, in
390 which case, the privilege levels of the associated event are
391 applied to the branch filter. Both kernel (k) and hypervisor (hv)
392 privilege levels are subject to permissions. When sampling on
393 multiple events, branch stack sampling is enabled for all the
394 sampling events. The sampled branch type is the same for all
395 events. The various filters must be specified as a comma separated
396 list: --branch-filter any_ret,u,k Note that this feature may not be
397 available on all processors.
398
399 --weight
400 Enable weightened sampling. An additional weight is recorded per
401 sample and can be displayed with the weight and local_weight sort
402 keys. This currently works for TSX abort events and some memory
403 events in precise mode on modern Intel CPUs.
404
405 --namespaces
406 Record events of type PERF_RECORD_NAMESPACES. This enables
407 cgroup_id sort key.
408
409 --all-cgroups
410 Record events of type PERF_RECORD_CGROUP. This enables cgroup sort
411 key.
412
413 --transaction
414 Record transaction flags for transaction related events.
415
416 --per-thread
417 Use per-thread mmaps. By default per-cpu mmaps are created. This
418 option overrides that and uses per-thread mmaps. A side-effect of
419 that is that inheritance is automatically disabled. --per-thread is
420 ignored with a warning if combined with -a or -C options.
421
422 -D, --delay=
423 After starting the program, wait msecs before measuring (-1: start
424 with events disabled). This is useful to filter out the startup
425 phase of the program, which is often very different.
426
427 -I, --intr-regs
428 Capture machine state (registers) at interrupt, i.e., on counter
429 overflows for each sample. List of captured registers depends on
430 the architecture. This option is off by default. It is possible to
431 select the registers to sample using their symbolic names, e.g. on
432 x86, ax, si. To list the available registers use --intr-regs=\?. To
433 name registers, pass a comma separated list such as
434 --intr-regs=ax,bx. The list of register is architecture dependent.
435
436 --user-regs
437 Similar to -I, but capture user registers at sample time. To list
438 the available user registers use --user-regs=\?.
439
440 --running-time
441 Record running and enabled time for read events (:S)
442
443 -k, --clockid
444 Sets the clock id to use for the various time fields in the
445 perf_event_type records. See clock_gettime(). In particular
446 CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW are supported, some events
447 might also allow CLOCK_BOOTTIME, CLOCK_REALTIME and CLOCK_TAI.
448
449 -S, --snapshot
450 Select AUX area tracing Snapshot Mode. This option is valid only
451 with an AUX area tracing event. Optionally, certain snapshot
452 capturing parameters can be specified in a string that follows this
453 option: e: take one last snapshot on exit; guarantees that there is
454 at least one snapshot in the output file; <size>: if the PMU
455 supports this, specify the desired snapshot size.
456
457 In Snapshot Mode trace data is captured only when signal SIGUSR2 is
458 received and on exit if the above e option is given.
459
460 --aux-sample[=OPTIONS]
461 Select AUX area sampling. At least one of the events selected by
462 the -e option must be an AUX area event. Samples on other events
463 will be created containing data from the AUX area. Optionally
464 sample size may be specified, otherwise it defaults to 4KiB.
465
466 --proc-map-timeout
467 When processing pre-existing threads /proc/XXX/mmap, it may take a
468 long time, because the file may be huge. A time out is needed in
469 such cases. This option sets the time out limit. The default value
470 is 500 ms.
471
472 --switch-events
473 Record context switch events i.e. events of type PERF_RECORD_SWITCH
474 or PERF_RECORD_SWITCH_CPU_WIDE. In some cases (e.g. Intel PT,
475 CoreSight or Arm SPE) switch events will be enabled automatically,
476 which can be suppressed by by the option --no-switch-events.
477
478 --clang-path=PATH
479 Path to clang binary to use for compiling BPF scriptlets. (enabled
480 when BPF support is on)
481
482 --clang-opt=OPTIONS
483 Options passed to clang when compiling BPF scriptlets. (enabled
484 when BPF support is on)
485
486 --vmlinux=PATH
487 Specify vmlinux path which has debuginfo. (enabled when BPF
488 prologue is on)
489
490 --buildid-all
491 Record build-id of all DSOs regardless whether it’s actually hit or
492 not.
493
494 --buildid-mmap
495 Record build ids in mmap2 events, disables build id cache (implies
496 --no-buildid).
497
498 --aio[=n]
499 Use <n> control blocks in asynchronous (Posix AIO) trace writing
500 mode (default: 1, max: 4). Asynchronous mode is supported only when
501 linking Perf tool with libc library providing implementation for
502 Posix AIO API.
503
504 --affinity=mode
505 Set affinity mask of trace reading thread according to the policy
506 defined by mode value: node - thread affinity mask is set to NUMA
507 node cpu mask of the processed mmap buffer cpu - thread affinity
508 mask is set to cpu of the processed mmap buffer
509
510 --mmap-flush=number
511 Specify minimal number of bytes that is extracted from mmap data
512 pages and processed for output. One can specify the number using
513 B/K/M/G suffixes.
514
515 The maximal allowed value is a quarter of the size of mmaped data
516 pages.
517
518 The default option value is 1 byte which means that every time that the
519 output writing thread finds some new data in the mmaped buffer the data
520 is extracted, possibly compressed (-z) and written to the output,
521 perf.data or pipe.
522
523 Larger data chunks are compressed more effectively in comparison to
524 smaller chunks so extraction of larger chunks from the mmap data pages
525 is preferable from the perspective of output size reduction.
526
527 Also at some cases executing less output write syscalls with bigger
528 data size can take less time than executing more output write syscalls
529 with smaller data size thus lowering runtime profiling overhead.
530
531 -z, --compression-level[=n]
532 Produce compressed trace using specified level n (default: 1 -
533 fastest compression, 22 - smallest trace)
534
535 --all-kernel
536 Configure all used events to run in kernel space.
537
538 --all-user
539 Configure all used events to run in user space.
540
541 --kernel-callchains
542 Collect callchains only from kernel space. I.e. this option sets
543 perf_event_attr.exclude_callchain_user to 1.
544
545 --user-callchains
546 Collect callchains only from user space. I.e. this option sets
547 perf_event_attr.exclude_callchain_kernel to 1.
548
549 Don’t use both --kernel-callchains and --user-callchains at the same
550 time or no callchains will be collected.
551
552 --timestamp-filename Append timestamp to output file name.
553
554 --timestamp-boundary
555 Record timestamp boundary (time of first/last samples).
556
557 --switch-output[=mode]
558 Generate multiple perf.data files, timestamp prefixed, switching to
559 a new one based on mode value: "signal" - when receiving a SIGUSR2
560 (default value) or <size> - when reaching the size threshold, size
561 is expected to be a number with appended unit character - B/K/M/G
562 <time> - when reaching the time threshold, size is expected to be a
563 number with appended unit character - s/m/h/d
564
565 Note: the precision of the size threshold hugely depends
566 on your configuration - the number and size of your ring
567 buffers (-m). It is generally more precise for higher sizes
568 (like >5M), for lower values expect different sizes.
569
570 A possible use case is to, given an external event, slice the perf.data
571 file that gets then processed, possibly via a perf script, to decide if
572 that particular perf.data snapshot should be kept or not.
573
574 Implies --timestamp-filename, --no-buildid and --no-buildid-cache. The
575 reason for the latter two is to reduce the data file switching
576 overhead. You can still switch them on with:
577
578 --switch-output --no-no-buildid --no-no-buildid-cache
579
580 --switch-output-event
581 Events that will cause the switch of the perf.data file,
582 auto-selecting --switch-output=signal, the results are similar as
583 internally the side band thread will also send a SIGUSR2 to the
584 main one.
585
586 Uses the same syntax as --event, it will just not be recorded, serving
587 only to switch the perf.data file as soon as the --switch-output event
588 is processed by a separate sideband thread.
589
590 This sideband thread is also used to other purposes, like processing
591 the PERF_RECORD_BPF_EVENT records as they happen, asking the kernel for
592 extra BPF information, etc.
593
594 --switch-max-files=N
595 When rotating perf.data with --switch-output, only keep N files.
596
597 --dry-run
598 Parse options then exit. --dry-run can be used to detect errors in
599 cmdline options.
600
601 perf record --dry-run -e can act as a BPF script compiler if
602 llvm.dump-obj in config file is set to true.
603
604 --synth=TYPE
605 Collect and synthesize given type of events (comma separated). Note
606 that this option controls the synthesis from the /proc filesystem
607 which represent task status for pre-existing threads.
608
609 Kernel (and some other) events are recorded regardless of the choice in
610 this option. For example, --synth=no would have MMAP events for kernel
611 and modules.
612
613 Available types are: task - synthesize FORK and COMM events for each
614 task mmap - synthesize MMAP events for each process (implies task)
615 cgroup - synthesize CGROUP events for each cgroup all - synthesize all
616 events (default) no - do not synthesize any of the above events
617
618 --tail-synthesize
619 Instead of collecting non-sample events (for example, fork, comm,
620 mmap) at the beginning of record, collect them during finalizing an
621 output file. The collected non-sample events reflects the status of
622 the system when record is finished.
623
624 --overwrite
625 Makes all events use an overwritable ring buffer. An overwritable
626 ring buffer works like a flight recorder: when it gets full, the
627 kernel will overwrite the oldest records, that thus will never make
628 it to the perf.data file.
629
630 When --overwrite and --switch-output are used perf records and drops
631 events until it receives a signal, meaning that something unusual was
632 detected that warrants taking a snapshot of the most current events,
633 those fitting in the ring buffer at that moment.
634
635 overwrite attribute can also be set or canceled for an event using
636 config terms. For example: cycles/overwrite/ and
637 instructions/no-overwrite/.
638
639 Implies --tail-synthesize.
640
641 --kcore
642 Make a copy of /proc/kcore and place it into a directory with the
643 perf data file.
644
645 --max-size=<size>
646 Limit the sample data max size, <size> is expected to be a number
647 with appended unit character - B/K/M/G
648
649 --num-thread-synthesize
650 The number of threads to run when synthesizing events for existing
651 processes. By default, the number of threads equals 1.
652
653 --control=fifo:ctl-fifo[,ack-fifo], --control=fd:ctl-fd[,ack-fd]
654 ctl-fifo / ack-fifo are opened and used as ctl-fd / ack-fd as
655 follows. Listen on ctl-fd descriptor for command to control
656 measurement.
657
658 Available commands: enable : enable events disable : disable events
659 enable name : enable event name disable name : disable event name
660 snapshot : AUX area tracing snapshot). stop : stop perf record ping :
661 ping
662
663 'evlist [-v|-g|-F] : display all events
664 -F Show just the sample frequency used for each event.
665 -v Show all fields.
666 -g Show event group information.
667
668 Measurements can be started with events disabled using --delay=-1
669 option. Optionally send control command completion (ack\n) to ack-fd
670 descriptor to synchronize with the controlling process. Example of bash
671 shell script to enable and disable events during measurements:
672
673 #!/bin/bash
674
675 ctl_dir=/tmp/
676
677 ctl_fifo=${ctl_dir}perf_ctl.fifo
678 test -p ${ctl_fifo} && unlink ${ctl_fifo}
679 mkfifo ${ctl_fifo}
680 exec {ctl_fd}<>${ctl_fifo}
681
682 ctl_ack_fifo=${ctl_dir}perf_ctl_ack.fifo
683 test -p ${ctl_ack_fifo} && unlink ${ctl_ack_fifo}
684 mkfifo ${ctl_ack_fifo}
685 exec {ctl_fd_ack}<>${ctl_ack_fifo}
686
687 perf record -D -1 -e cpu-cycles -a \
688 --control fd:${ctl_fd},${ctl_fd_ack} \
689 -- sleep 30 &
690 perf_pid=$!
691
692 sleep 5 && echo 'enable' >&${ctl_fd} && read -u ${ctl_fd_ack} e1 && echo "enabled(${e1})"
693 sleep 10 && echo 'disable' >&${ctl_fd} && read -u ${ctl_fd_ack} d1 && echo "disabled(${d1})"
694
695 exec {ctl_fd_ack}>&-
696 unlink ${ctl_ack_fifo}
697
698 exec {ctl_fd}>&-
699 unlink ${ctl_fifo}
700
701 wait -n ${perf_pid}
702 exit $?
703
704 --threads=<spec>
705 Write collected trace data into several data files using parallel
706 threads. <spec> value can be user defined list of masks. Masks
707 separated by colon define CPUs to be monitored by a thread and
708 affinity mask of that thread is separated by slash:
709
710 <cpus mask 1>/<affinity mask 1>:<cpus mask 2>/<affinity mask 2>:...
711
712 CPUs or affinity masks must not overlap with other corresponding masks.
713 Invalid CPUs are ignored, but masks containing only invalid CPUs are
714 not allowed.
715
716 For example user specification like the following:
717
718 0,2-4/2-4:1,5-7/5-7
719
720 specifies parallel threads layout that consists of two threads, the
721 first thread monitors CPUs 0 and 2-4 with the affinity mask 2-4, the
722 second monitors CPUs 1 and 5-7 with the affinity mask 5-7.
723
724 <spec> value can also be a string meaning predefined parallel threads
725 layout:
726
727 cpu - create new data streaming thread for every monitored cpu
728 core - create new thread to monitor CPUs grouped by a core
729 package - create new thread to monitor CPUs grouped by a package
730 numa - create new threed to monitor CPUs grouped by a NUMA domain
731
732 Predefined layouts can be used on systems with large number of CPUs in
733 order not to spawn multiple per-cpu streaming threads but still avoid
734 LOST events in data directory files. Option specified with no or empty
735 value defaults to CPU layout. Masks defined or provided by the option
736 value are filtered through the mask provided by -C option.
737
739 Support for Intel hybrid events within perf tools.
740
741 For some Intel platforms, such as AlderLake, which is hybrid platform
742 and it consists of atom cpu and core cpu. Each cpu has dedicated event
743 list. Part of events are available on core cpu, part of events are
744 available on atom cpu and even part of events are available on both.
745
746 Kernel exports two new cpu pmus via sysfs: /sys/devices/cpu_core
747 /sys/devices/cpu_atom
748
749 The cpus files are created under the directories. For example,
750
751 cat /sys/devices/cpu_core/cpus 0-15
752
753 cat /sys/devices/cpu_atom/cpus 16-23
754
755 It indicates cpu0-cpu15 are core cpus and cpu16-cpu23 are atom cpus.
756
757 Quickstart
758
760 As before, use perf-list to list the symbolic event.
761
762 perf list
763
764 inst_retired.any [Fixed Counter: Counts the number of instructions
765 retired. Unit: cpu_atom] inst_retired.any [Number of instructions
766 retired. Fixed Counter - architectural event. Unit: cpu_core]
767
768 The Unit: xxx is added to brief description to indicate which pmu the
769 event is belong to. Same event name but with different pmu can be
770 supported.
771
773 To enable a core only event or atom only event, following syntax is
774 supported:
775
776 cpu_core/<event name>/
777 or
778 cpu_atom/<event name>/
779
780 For example, count the cycles event on core cpus.
781
782 perf stat -e cpu_core/cycles/
783
785 When creating one event and the event is available on both atom and
786 core, two events are created automatically. One is for atom, the other
787 is for core. Most of hardware events and cache events are available on
788 both cpu_core and cpu_atom.
789
790 For hardware events, they have pre-defined configs (e.g. 0 for cycles).
791 But on hybrid platform, kernel needs to know where the event comes from
792 (from atom or from core). The original perf event type
793 PERF_TYPE_HARDWARE can’t carry pmu information. So now this type is
794 extended to be PMU aware type. The PMU type ID is stored at
795 attr.config[63:32].
796
797 PMU type ID is retrieved from sysfs. /sys/devices/cpu_atom/type
798 /sys/devices/cpu_core/type
799
800 The new attr.config layout for PERF_TYPE_HARDWARE:
801
802 PERF_TYPE_HARDWARE: 0xEEEEEEEE000000AA AA: hardware event ID EEEEEEEE:
803 PMU type ID
804
805 Cache event is similar. The type PERF_TYPE_HW_CACHE is extended to be
806 PMU aware type. The PMU type ID is stored at attr.config[63:32].
807
808 The new attr.config layout for PERF_TYPE_HW_CACHE:
809
810 PERF_TYPE_HW_CACHE: 0xEEEEEEEE00DDCCBB BB: hardware cache ID CC:
811 hardware cache op ID DD: hardware cache op result ID EEEEEEEE: PMU type
812 ID
813
814 When enabling a hardware event without specified pmu, such as, perf
815 stat -e cycles -a (use system-wide in this example), two events are
816 created automatically.
817
818 ------------------------------------------------------------
819 perf_event_attr:
820 size 120
821 config 0x400000000
822 sample_type IDENTIFIER
823 read_format TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING
824 disabled 1
825 inherit 1
826 exclude_guest 1
827 ------------------------------------------------------------
828
829 and
830
831 ------------------------------------------------------------
832 perf_event_attr:
833 size 120
834 config 0x800000000
835 sample_type IDENTIFIER
836 read_format TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING
837 disabled 1
838 inherit 1
839 exclude_guest 1
840 ------------------------------------------------------------
841
842 type 0 is PERF_TYPE_HARDWARE. 0x4 in 0x400000000 indicates it’s
843 cpu_core pmu. 0x8 in 0x800000000 indicates it’s cpu_atom pmu (atom pmu
844 type id is random).
845
846 The kernel creates cycles (0x400000000) on cpu0-cpu15 (core cpus), and
847 create cycles (0x800000000) on cpu16-cpu23 (atom cpus).
848
849 For perf-stat result, it displays two events:
850
851 Performance counter stats for 'system wide':
852
853 6,744,979 cpu_core/cycles/
854 1,965,552 cpu_atom/cycles/
855
856 The first cycles is core event, the second cycles is atom event.
857
859 perf-stat reports the scaled counts for hybrid event and with a
860 percentage displayed. The percentage is the event’s running
861 time/enabling time.
862
863 One example, triad_loop runs on cpu16 (atom core), while we can see the
864 scaled value for core cycles is 160,444,092 and the percentage is
865 0.47%.
866
867 perf stat -e cycles -- taskset -c 16 ./triad_loop
868
869 As previous, two events are created.
870
871
872 .ft C
873 perf_event_attr:
874 size 120
875 config 0x400000000
876 sample_type IDENTIFIER
877 read_format TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING
878 disabled 1
879 inherit 1
880 enable_on_exec 1
881 exclude_guest 1
882 .ft
883
884
885 and
886
887
888 .ft C
889 perf_event_attr:
890 size 120
891 config 0x800000000
892 sample_type IDENTIFIER
893 read_format TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING
894 disabled 1
895 inherit 1
896 enable_on_exec 1
897 exclude_guest 1
898 .ft
899
900
901 Performance counter stats for 'taskset -c 16 ./triad_loop':
902
903 233,066,666 cpu_core/cycles/ (0.43%)
904 604,097,080 cpu_atom/cycles/ (99.57%)
905
907 If there is no -e specified in perf record, on hybrid platform, it
908 creates two default cycles and adds them to event list. One is for
909 core, the other is for atom.
910
912 If there is no -e specified in perf stat, on hybrid platform, besides
913 of software events, following events are created and added to event
914 list in order.
915
916 cpu_core/cycles/, cpu_atom/cycles/, cpu_core/instructions/,
917 cpu_atom/instructions/, cpu_core/branches/, cpu_atom/branches/,
918 cpu_core/branch-misses/, cpu_atom/branch-misses/
919
920 Of course, both perf-stat and perf-record support to enable hybrid
921 event with a specific pmu.
922
923 e.g. perf stat -e cpu_core/cycles/ perf stat -e cpu_atom/cycles/ perf
924 stat -e cpu_core/r1a/ perf stat -e cpu_atom/L1-icache-loads/ perf stat
925 -e cpu_core/cycles/,cpu_atom/instructions/ perf stat -e
926 {cpu_core/cycles/,cpu_core/instructions/}
927
928 But {cpu_core/cycles/,cpu_atom/instructions/} will return warning and
929 disable grouping, because the pmus in group are not matched (cpu_core
930 vs. cpu_atom).
931
932 --debuginfod[=URLs]
933 Specify debuginfod URL to be used when cacheing perf.data binaries,
934 it follows the same syntax as the DEBUGINFOD_URLS variable, like:
935
936 http://192.168.122.174:8002
937
938 If the URLs is not specified, the value of DEBUGINFOD_URLS
939 system environment variable is used.
940
942 perf-stat(1), perf-list(1), perf-intel-pt(1)
943
944
945
946perf 06/14/2022 PERF-RECORD(1)