table of contents
PERF_5.9-RECORD(1) | perf Manual | PERF_5.9-RECORD(1) |
NAME¶
perf-record - Run a command and record its profile into perf.data
SYNOPSIS¶
perf record [-e <EVENT> | --event=EVENT] [-a] <command> perf record [-e <EVENT> | --event=EVENT] [-a] — <command> [<options>]
DESCRIPTION¶
This command runs a command and gathers a performance counter profile from it, into perf.data - without displaying anything.
This file can then be inspected later on, using perf report.
OPTIONS¶
<command>...
-e, --event=
where M, N, K are numbers (in decimal, hex, octal format). Acceptable values for each of 'config', 'config1' and 'config2' are defined by corresponding entries in /sys/bus/event_source/devices/<pmu>/format/* param1 and param2 are defined as formats for the PMU in: /sys/bus/event_source/devices/<pmu>/format/*
There are also some parameters which are not defined in .../<pmu>/format/*. These params can be used to overload default config values per event. Here are some common parameters: - 'period': Set event sampling period - 'freq': Set event sampling frequency - 'time': Disable/enable time stamping. Acceptable values are 1 for
enabling time stamping. 0 for disabling time stamping.
The default is 1. - 'call-graph': Disable/enable callgraph. Acceptable str are "fp" for
FP mode, "dwarf" for DWARF mode, "lbr" for LBR mode and
"no" for disable callgraph. - 'stack-size': user stack size for dwarf mode - 'name' : User defined event name. Single quotes (') may be used to
escape symbols in the name from parsing by shell and tool
like this: name=\'CPU_CLK_UNHALTED.THREAD:cmask=0x1\'. - 'aux-output': Generate AUX records instead of events. This requires
that an AUX area event is also provided. - 'aux-sample-size': Set sample size for AUX area sampling. If the '--aux-sample' option has been used, set aux-sample-size=0 to disable AUX area sampling for the event.
See the linkperf:perf-list[1] man page for more parameters.
Note: If user explicitly sets options which conflict with the params, the value set by the parameters will be overridden.
Also not defined in .../<pmu>/format/* are PMU driver specific configuration parameters. Any configuration parameter preceded by the letter '@' is not interpreted in user space and sent down directly to the PMU driver. For example:
perf record -e some_event/@cfg1,@cfg2=config/ ...
will see 'cfg1' and 'cfg2=config' pushed to the PMU driver associated with the event for further processing. There is no restriction on what the configuration parameters are, as long as their semantic is understood and supported by the PMU driver.
When processing a '.c' file, perf searches an installed LLVM to compile it into an object file first. Optional clang options can be passed via the '--clang-opt' command line option, e.g.:
perf record --clang-opt "-DLINUX_VERSION_CODE=0x50000" \
-e tests/bpf-script-example.c
Note: '--clang-opt' must be placed before '--event/-e'.
--filter=<filter>
Event filter. This option should follow an event selector (-e) which selects either tracepoint event(s) or a hardware trace PMU (e.g. Intel PT or CoreSight).
In the case of tracepoints, multiple '--filter' options are combined using '&&'.
A hardware trace PMU advertises its ability to accept a number of address filters by specifying a non-zero value in /sys/bus/event_source/devices/<pmu>/nr_addr_filters.
Address filters have the format:
filter|start|stop|tracestop <start> [/ <size>] [@<file name>]
Where: - 'filter': defines a region that will be traced. - 'start': defines an address at which tracing will begin. - 'stop': defines an address at which tracing will stop. - 'tracestop': defines a region in which tracing will stop.
<file name> is the name of the object file, <start> is the offset to the code to trace in that file, and <size> is the size of the region to trace. 'start' and 'stop' filters need not specify a <size>.
If no object file is specified then the kernel is assumed, in which case the start address must be a current kernel memory address.
<start> can also be specified by providing the name of a symbol. If the symbol name is not unique, it can be disambiguated by inserting #n where 'n' selects the n'th symbol in address order. Alternately #0, #g or #G select only a global symbol. <size> can also be specified by providing the name of a symbol, in which case the size is calculated to the end of that symbol. For 'filter' and 'tracestop' filters, if <size> is omitted and <start> is a symbol, then the size is calculated to the end of that symbol.
If <size> is omitted and <start> is '*', then the start and size will be calculated from the first and last symbols, i.e. to trace the whole file.
If symbol names (or '*') are provided, they must be surrounded by white space.
The filter passed to the kernel is not necessarily the same as entered. To see the filter that is passed, use the -v option.
The kernel may not be able to configure a trace region if it is not within a single mapping. MMAP events (or /proc/<pid>/maps) can be examined to determine if that is a possibility.
Multiple filters can be separated with space or comma.
--exclude-perf
-a, --all-cpus
-p, --pid=
-t, --tid=
-u, --uid=
-r, --realtime=
--no-buffering
-c, --count=
-o, --output=
-i, --no-inherit
-F, --freq=
--strict-freq
-m, --mmap-pages=
--group
-g
--call-graph
The unwinding method used for kernel space is dependent on the unwinder used by the active kernel configuration, i.e CONFIG_UNWINDER_FRAME_POINTER (fp) or CONFIG_UNWINDER_ORC (orc)
Any option specified here controls the method used for user space.
Valid options are "fp" (frame pointer), "dwarf" (DWARF's CFI - Call Frame Information) or "lbr" (Hardware Last Branch Record facility).
In some systems, where binaries are build with gcc --fomit-frame-pointer, using the "fp" method will produce bogus call graphs, using "dwarf", if available (perf tools linked to the libunwind or libdw library) should be used instead. Using the "lbr" method doesn't require any compiler options. It will produce call graphs from the hardware LBR registers. The main limitation is that it is only available on new Intel platforms, such as Haswell. It can only get user call chain. It doesn't work with branch stack sampling at the same time.
When "dwarf" recording is used, perf also records (user) stack dump when sampled. Default size of the stack dump is 8192 (bytes). User can change the size by passing the size after comma like "--call-graph dwarf,4096".
-q, --quiet
-v, --verbose
-s, --stat
-d, --data
--phys-data
-T, --timestamp
-P, --period
--sample-cpu
-n, --no-samples
-R, --raw-samples
-C, --cpu
-B, --no-buildid
-N, --no-buildid-cache
-G name,..., --cgroup name,...
If wanting to monitor, say, cycles for a cgroup and also for system wide, this command line can be used: perf stat -e cycles -G cgroup_name -a -e cycles.
-b, --branch-any
-j, --branch-filter
The option requires at least one branch type among any, any_call, any_ret, ind_call, cond. The privilege levels may be omitted, in which case, the privilege levels of the associated event are applied to the branch filter. Both kernel (k) and hypervisor (hv) privilege levels are subject to permissions. When sampling on multiple events, branch stack sampling is enabled for all the sampling events. The sampled branch type is the same for all events. The various filters must be specified as a comma separated list: --branch-filter any_ret,u,k Note that this feature may not be available on all processors.
--weight
--namespaces
--all-cgroups
--transaction
--per-thread
-D, --delay=
-I, --intr-regs
--user-regs
--running-time
-k, --clockid
-S, --snapshot
In Snapshot Mode trace data is captured only when signal SIGUSR2 is received and on exit if the above e option is given.
--aux-sample[=OPTIONS]
--proc-map-timeout
--switch-events
--clang-path=PATH
--clang-opt=OPTIONS
--vmlinux=PATH
--buildid-all
--aio[=n]
--affinity=mode
--mmap-flush=number
The maximal allowed value is a quarter of the size of mmaped data pages.
The default option value is 1 byte which means that every time that the output writing thread finds some new data in the mmaped buffer the data is extracted, possibly compressed (-z) and written to the output, perf.data or pipe.
Larger data chunks are compressed more effectively in comparison to smaller chunks so extraction of larger chunks from the mmap data pages is preferable from the perspective of output size reduction.
Also at some cases executing less output write syscalls with bigger data size can take less time than executing more output write syscalls with smaller data size thus lowering runtime profiling overhead.
-z, --compression-level[=n]
--all-kernel
--all-user
--kernel-callchains
--user-callchains
Don’t use both --kernel-callchains and --user-callchains at the same time or no callchains will be collected.
--timestamp-filename Append timestamp to output file name.
--timestamp-boundary
--switch-output[=mode]
Note: the precision of the size threshold hugely depends on your configuration - the number and size of your ring buffers (-m). It is generally more precise for higher sizes (like >5M), for lower values expect different sizes.
A possible use case is to, given an external event, slice the perf.data file that gets then processed, possibly via a perf script, to decide if that particular perf.data snapshot should be kept or not.
Implies --timestamp-filename, --no-buildid and --no-buildid-cache. The reason for the latter two is to reduce the data file switching overhead. You can still switch them on with:
--switch-output --no-no-buildid --no-no-buildid-cache
--switch-output-event
Uses the same syntax as --event, it will just not be recorded, serving only to switch the perf.data file as soon as the --switch-output event is processed by a separate sideband thread.
This sideband thread is also used to other purposes, like processing the PERF_RECORD_BPF_EVENT records as they happen, asking the kernel for extra BPF information, etc.
--switch-max-files=N
--dry-run
perf record --dry-run -e can act as a BPF script compiler if llvm.dump-obj in config file is set to true.
--tail-synthesize
--overwrite
When --overwrite and --switch-output are used perf records and drops events until it receives a signal, meaning that something unusual was detected that warrants taking a snapshot of the most current events, those fitting in the ring buffer at that moment.
overwrite attribute can also be set or canceled for an event using config terms. For example: cycles/overwrite/ and instructions/no-overwrite/.
Implies --tail-synthesize.
--kcore
--max-size=<size>
--num-thread-synthesize
--control fd:ctl-fd[,ack-fd] Listen on ctl-fd descriptor for command to control measurement (enable: enable events, disable: disable events). Measurements can be started with events disabled using --delay=-1 option. Optionally send control command completion (ack\n) to ack-fd descriptor to synchronize with the controlling process. Example of bash shell script to enable and disable events during measurements:
#!/bin/bash
ctl_dir=/tmp/
ctl_fifo=${ctl_dir}perf_ctl.fifo test -p ${ctl_fifo} && unlink ${ctl_fifo} mkfifo ${ctl_fifo} exec {ctl_fd}<>${ctl_fifo}
ctl_ack_fifo=${ctl_dir}perf_ctl_ack.fifo test -p ${ctl_ack_fifo} && unlink ${ctl_ack_fifo} mkfifo ${ctl_ack_fifo} exec {ctl_fd_ack}<>${ctl_ack_fifo}
perf record -D -1 -e cpu-cycles -a \ --control
fd:${ctl_fd},${ctl_fd_ack} \
— sleep 30 & perf_pid=$!
sleep 5 && echo enable >&${ctl_fd} && read -u ${ctl_fd_ack} e1 && echo "enabled(${e1})" sleep 10 && echo disable >&${ctl_fd} && read -u ${ctl_fd_ack} d1 && echo "disabled(${d1})"
exec {ctl_fd_ack}>&- unlink ${ctl_ack_fifo}
exec {ctl_fd}>&- unlink ${ctl_fifo}
wait -n ${perf_pid} exit $?
SEE ALSO¶
perf-stat(1), perf-list(1), perf-intel-pt(1)
2020-10-05 | perf |