Back to home page

OSCL-LXR

 
 

    


0001 perf-stat(1)
0002 ============
0003 
0004 NAME
0005 ----
0006 perf-stat - Run a command and gather performance counter statistics
0007 
0008 SYNOPSIS
0009 --------
0010 [verse]
0011 'perf stat' [-e <EVENT> | --event=EVENT] [-a] <command>
0012 'perf stat' [-e <EVENT> | --event=EVENT] [-a] \-- <command> [<options>]
0013 'perf stat' [-e <EVENT> | --event=EVENT] [-a] record [-o file] \-- <command> [<options>]
0014 'perf stat' report [-i file]
0015 
0016 DESCRIPTION
0017 -----------
0018 This command runs a command and gathers performance counter statistics
0019 from it.
0020 
0021 
0022 OPTIONS
0023 -------
0024 <command>...::
0025         Any command you can specify in a shell.
0026 
0027 record::
0028         See STAT RECORD.
0029 
0030 report::
0031         See STAT REPORT.
0032 
0033 -e::
0034 --event=::
0035         Select the PMU event. Selection can be:
0036 
0037         - a symbolic event name (use 'perf list' to list all events)
0038 
0039         - a raw PMU event in the form of rN where N is a hexadecimal value
0040           that represents the raw register encoding with the layout of the
0041           event control registers as described by entries in
0042           /sys/bus/event_source/devices/cpu/format/*.
0043 
0044         - a symbolic or raw PMU event followed by an optional colon
0045           and a list of event modifiers, e.g., cpu-cycles:p.  See the
0046           linkperf:perf-list[1] man page for details on event modifiers.
0047 
0048         - a symbolically formed event like 'pmu/param1=0x3,param2/' where
0049           param1 and param2 are defined as formats for the PMU in
0050           /sys/bus/event_source/devices/<pmu>/format/*
0051 
0052           'percore' is a event qualifier that sums up the event counts for both
0053           hardware threads in a core. For example:
0054           perf stat -A -a -e cpu/event,percore=1/,otherevent ...
0055 
0056         - a symbolically formed event like 'pmu/config=M,config1=N,config2=K/'
0057           where M, N, K are numbers (in decimal, hex, octal format).
0058           Acceptable values for each of 'config', 'config1' and 'config2'
0059           parameters are defined by corresponding entries in
0060           /sys/bus/event_source/devices/<pmu>/format/*
0061 
0062         Note that the last two syntaxes support prefix and glob matching in
0063         the PMU name to simplify creation of events across multiple instances
0064         of the same type of PMU in large systems (e.g. memory controller PMUs).
0065         Multiple PMU instances are typical for uncore PMUs, so the prefix
0066         'uncore_' is also ignored when performing this match.
0067 
0068 
0069 -i::
0070 --no-inherit::
0071         child tasks do not inherit counters
0072 -p::
0073 --pid=<pid>::
0074         stat events on existing process id (comma separated list)
0075 
0076 -t::
0077 --tid=<tid>::
0078         stat events on existing thread id (comma separated list)
0079 
0080 -b::
0081 --bpf-prog::
0082         stat events on existing bpf program id (comma separated list),
0083         requiring root rights. bpftool-prog could be used to find program
0084         id all bpf programs in the system. For example:
0085 
0086   # bpftool prog | head -n 1
0087   17247: tracepoint  name sys_enter  tag 192d548b9d754067  gpl
0088 
0089   # perf stat -e cycles,instructions --bpf-prog 17247 --timeout 1000
0090 
0091    Performance counter stats for 'BPF program(s) 17247':
0092 
0093              85,967      cycles
0094              28,982      instructions              #    0.34  insn per cycle
0095 
0096         1.102235068 seconds time elapsed
0097 
0098 --bpf-counters::
0099         Use BPF programs to aggregate readings from perf_events.  This
0100         allows multiple perf-stat sessions that are counting the same metric (cycles,
0101         instructions, etc.) to share hardware counters.
0102         To use BPF programs on common events by default, use
0103         "perf config stat.bpf-counter-events=<list_of_events>".
0104 
0105 --bpf-attr-map::
0106         With option "--bpf-counters", different perf-stat sessions share
0107         information about shared BPF programs and maps via a pinned hashmap.
0108         Use "--bpf-attr-map" to specify the path of this pinned hashmap.
0109         The default path is /sys/fs/bpf/perf_attr_map.
0110 
0111 ifdef::HAVE_LIBPFM[]
0112 --pfm-events events::
0113 Select a PMU event using libpfm4 syntax (see http://perfmon2.sf.net)
0114 including support for event filters. For example '--pfm-events
0115 inst_retired:any_p:u:c=1:i'. More than one event can be passed to the
0116 option using the comma separator. Hardware events and generic hardware
0117 events cannot be mixed together. The latter must be used with the -e
0118 option. The -e option and this one can be mixed and matched.  Events
0119 can be grouped using the {} notation.
0120 endif::HAVE_LIBPFM[]
0121 
0122 -a::
0123 --all-cpus::
0124         system-wide collection from all CPUs (default if no target is specified)
0125 
0126 --no-scale::
0127         Don't scale/normalize counter values
0128 
0129 -d::
0130 --detailed::
0131         print more detailed statistics, can be specified up to 3 times
0132 
0133            -d:          detailed events, L1 and LLC data cache
0134         -d -d:     more detailed events, dTLB and iTLB events
0135      -d -d -d:     very detailed events, adding prefetch events
0136 
0137 -r::
0138 --repeat=<n>::
0139         repeat command and print average + stddev (max: 100). 0 means forever.
0140 
0141 -B::
0142 --big-num::
0143         print large numbers with thousands' separators according to locale.
0144         Enabled by default. Use "--no-big-num" to disable.
0145         Default setting can be changed with "perf config stat.big-num=false".
0146 
0147 -C::
0148 --cpu=::
0149 Count only on the list of CPUs provided. Multiple CPUs can be provided as a
0150 comma-separated list with no space: 0,1. Ranges of CPUs are specified with -: 0-2.
0151 In per-thread mode, this option is ignored. The -a option is still necessary
0152 to activate system-wide monitoring. Default is to count on all CPUs.
0153 
0154 -A::
0155 --no-aggr::
0156 Do not aggregate counts across all monitored CPUs.
0157 
0158 -n::
0159 --null::
0160 null run - Don't start any counters.
0161 
0162 This can be useful to measure just elapsed wall-clock time - or to assess the
0163 raw overhead of perf stat itself, without running any counters.
0164 
0165 -v::
0166 --verbose::
0167         be more verbose (show counter open errors, etc)
0168 
0169 -x SEP::
0170 --field-separator SEP::
0171 print counts using a CSV-style output to make it easy to import directly into
0172 spreadsheets. Columns are separated by the string specified in SEP.
0173 
0174 --table:: Display time for each run (-r option), in a table format, e.g.:
0175 
0176   $ perf stat --null -r 5 --table perf bench sched pipe
0177 
0178    Performance counter stats for 'perf bench sched pipe' (5 runs):
0179 
0180              # Table of individual measurements:
0181              5.189 (-0.293) #
0182              5.189 (-0.294) #
0183              5.186 (-0.296) #
0184              5.663 (+0.181) ##
0185              6.186 (+0.703) ####
0186 
0187              # Final result:
0188              5.483 +- 0.198 seconds time elapsed  ( +-  3.62% )
0189 
0190 -G name::
0191 --cgroup name::
0192 monitor only in the container (cgroup) called "name". This option is available only
0193 in per-cpu mode. The cgroup filesystem must be mounted. All threads belonging to
0194 container "name" are monitored when they run on the monitored CPUs. Multiple cgroups
0195 can be provided. Each cgroup is applied to the corresponding event, i.e., first cgroup
0196 to first event, second cgroup to second event and so on. It is possible to provide
0197 an empty cgroup (monitor all the time) using, e.g., -G foo,,bar. Cgroups must have
0198 corresponding events, i.e., they always refer to events defined earlier on the command
0199 line. If the user wants to track multiple events for a specific cgroup, the user can
0200 use '-e e1 -e e2 -G foo,foo' or just use '-e e1 -e e2 -G foo'.
0201 
0202 If wanting to monitor, say, 'cycles' for a cgroup and also for system wide, this
0203 command line can be used: 'perf stat -e cycles -G cgroup_name -a -e cycles'.
0204 
0205 --for-each-cgroup name::
0206 Expand event list for each cgroup in "name" (allow multiple cgroups separated
0207 by comma).  It also support regex patterns to match multiple groups.  This has same
0208 effect that repeating -e option and -G option for each event x name.  This option
0209 cannot be used with -G/--cgroup option.
0210 
0211 -o file::
0212 --output file::
0213 Print the output into the designated file.
0214 
0215 --append::
0216 Append to the output file designated with the -o option. Ignored if -o is not specified.
0217 
0218 --log-fd::
0219 
0220 Log output to fd, instead of stderr.  Complementary to --output, and mutually exclusive
0221 with it.  --append may be used here.  Examples:
0222      3>results  perf stat --log-fd 3          \-- $cmd
0223      3>>results perf stat --log-fd 3 --append \-- $cmd
0224 
0225 --control=fifo:ctl-fifo[,ack-fifo]::
0226 --control=fd:ctl-fd[,ack-fd]::
0227 ctl-fifo / ack-fifo are opened and used as ctl-fd / ack-fd as follows.
0228 Listen on ctl-fd descriptor for command to control measurement ('enable': enable events,
0229 'disable': disable events). Measurements can be started with events disabled using
0230 --delay=-1 option. Optionally send control command completion ('ack\n') to ack-fd descriptor
0231 to synchronize with the controlling process. Example of bash shell script to enable and
0232 disable events during measurements:
0233 
0234  #!/bin/bash
0235 
0236  ctl_dir=/tmp/
0237 
0238  ctl_fifo=${ctl_dir}perf_ctl.fifo
0239  test -p ${ctl_fifo} && unlink ${ctl_fifo}
0240  mkfifo ${ctl_fifo}
0241  exec {ctl_fd}<>${ctl_fifo}
0242 
0243  ctl_ack_fifo=${ctl_dir}perf_ctl_ack.fifo
0244  test -p ${ctl_ack_fifo} && unlink ${ctl_ack_fifo}
0245  mkfifo ${ctl_ack_fifo}
0246  exec {ctl_fd_ack}<>${ctl_ack_fifo}
0247 
0248  perf stat -D -1 -e cpu-cycles -a -I 1000       \
0249            --control fd:${ctl_fd},${ctl_fd_ack} \
0250            \-- sleep 30 &
0251  perf_pid=$!
0252 
0253  sleep 5  && echo 'enable' >&${ctl_fd} && read -u ${ctl_fd_ack} e1 && echo "enabled(${e1})"
0254  sleep 10 && echo 'disable' >&${ctl_fd} && read -u ${ctl_fd_ack} d1 && echo "disabled(${d1})"
0255 
0256  exec {ctl_fd_ack}>&-
0257  unlink ${ctl_ack_fifo}
0258 
0259  exec {ctl_fd}>&-
0260  unlink ${ctl_fifo}
0261 
0262  wait -n ${perf_pid}
0263  exit $?
0264 
0265 
0266 --pre::
0267 --post::
0268         Pre and post measurement hooks, e.g.:
0269 
0270 perf stat --repeat 10 --null --sync --pre 'make -s O=defconfig-build/clean' \-- make -s -j64 O=defconfig-build/ bzImage
0271 
0272 -I msecs::
0273 --interval-print msecs::
0274 Print count deltas every N milliseconds (minimum: 1ms)
0275 The overhead percentage could be high in some cases, for instance with small, sub 100ms intervals.  Use with caution.
0276         example: 'perf stat -I 1000 -e cycles -a sleep 5'
0277 
0278 If the metric exists, it is calculated by the counts generated in this interval and the metric is printed after #.
0279 
0280 --interval-count times::
0281 Print count deltas for fixed number of times.
0282 This option should be used together with "-I" option.
0283         example: 'perf stat -I 1000 --interval-count 2 -e cycles -a'
0284 
0285 --interval-clear::
0286 Clear the screen before next interval.
0287 
0288 --timeout msecs::
0289 Stop the 'perf stat' session and print count deltas after N milliseconds (minimum: 10 ms).
0290 This option is not supported with the "-I" option.
0291         example: 'perf stat --time 2000 -e cycles -a'
0292 
0293 --metric-only::
0294 Only print computed metrics. Print them in a single line.
0295 Don't show any raw values. Not supported with --per-thread.
0296 
0297 --per-socket::
0298 Aggregate counts per processor socket for system-wide mode measurements.  This
0299 is a useful mode to detect imbalance between sockets.  To enable this mode,
0300 use --per-socket in addition to -a. (system-wide).  The output includes the
0301 socket number and the number of online processors on that socket. This is
0302 useful to gauge the amount of aggregation.
0303 
0304 --per-die::
0305 Aggregate counts per processor die for system-wide mode measurements.  This
0306 is a useful mode to detect imbalance between dies.  To enable this mode,
0307 use --per-die in addition to -a. (system-wide).  The output includes the
0308 die number and the number of online processors on that die. This is
0309 useful to gauge the amount of aggregation.
0310 
0311 --per-core::
0312 Aggregate counts per physical processor for system-wide mode measurements.  This
0313 is a useful mode to detect imbalance between physical cores.  To enable this mode,
0314 use --per-core in addition to -a. (system-wide).  The output includes the
0315 core number and the number of online logical processors on that physical processor.
0316 
0317 --per-thread::
0318 Aggregate counts per monitored threads, when monitoring threads (-t option)
0319 or processes (-p option).
0320 
0321 --per-node::
0322 Aggregate counts per NUMA nodes for system-wide mode measurements. This
0323 is a useful mode to detect imbalance between NUMA nodes. To enable this
0324 mode, use --per-node in addition to -a. (system-wide).
0325 
0326 -D msecs::
0327 --delay msecs::
0328 After starting the program, wait msecs before measuring (-1: start with events
0329 disabled). This is useful to filter out the startup phase of the program,
0330 which is often very different.
0331 
0332 -T::
0333 --transaction::
0334 
0335 Print statistics of transactional execution if supported.
0336 
0337 --metric-no-group::
0338 By default, events to compute a metric are placed in weak groups. The
0339 group tries to enforce scheduling all or none of the events. The
0340 --metric-no-group option places events outside of groups and may
0341 increase the chance of the event being scheduled - leading to more
0342 accuracy. However, as events may not be scheduled together accuracy
0343 for metrics like instructions per cycle can be lower - as both metrics
0344 may no longer be being measured at the same time.
0345 
0346 --metric-no-merge::
0347 By default metric events in different weak groups can be shared if one
0348 group contains all the events needed by another. In such cases one
0349 group will be eliminated reducing event multiplexing and making it so
0350 that certain groups of metrics sum to 100%. A downside to sharing a
0351 group is that the group may require multiplexing and so accuracy for a
0352 small group that need not have multiplexing is lowered. This option
0353 forbids the event merging logic from sharing events between groups and
0354 may be used to increase accuracy in this case.
0355 
0356 --quiet::
0357 Don't print output. This is useful with perf stat record below to only
0358 write data to the perf.data file.
0359 
0360 STAT RECORD
0361 -----------
0362 Stores stat data into perf data file.
0363 
0364 -o file::
0365 --output file::
0366 Output file name.
0367 
0368 STAT REPORT
0369 -----------
0370 Reads and reports stat data from perf data file.
0371 
0372 -i file::
0373 --input file::
0374 Input file name.
0375 
0376 --per-socket::
0377 Aggregate counts per processor socket for system-wide mode measurements.
0378 
0379 --per-die::
0380 Aggregate counts per processor die for system-wide mode measurements.
0381 
0382 --per-core::
0383 Aggregate counts per physical processor for system-wide mode measurements.
0384 
0385 -M::
0386 --metrics::
0387 Print metrics or metricgroups specified in a comma separated list.
0388 For a group all metrics from the group are added.
0389 The events from the metrics are automatically measured.
0390 See perf list output for the possible metrics and metricgroups.
0391 
0392 -A::
0393 --no-aggr::
0394 Do not aggregate counts across all monitored CPUs.
0395 
0396 --topdown::
0397 Print complete top-down metrics supported by the CPU. This allows to
0398 determine bottle necks in the CPU pipeline for CPU bound workloads,
0399 by breaking the cycles consumed down into frontend bound, backend bound,
0400 bad speculation and retiring.
0401 
0402 Frontend bound means that the CPU cannot fetch and decode instructions fast
0403 enough. Backend bound means that computation or memory access is the bottle
0404 neck. Bad Speculation means that the CPU wasted cycles due to branch
0405 mispredictions and similar issues. Retiring means that the CPU computed without
0406 an apparently bottleneck. The bottleneck is only the real bottleneck
0407 if the workload is actually bound by the CPU and not by something else.
0408 
0409 For best results it is usually a good idea to use it with interval
0410 mode like -I 1000, as the bottleneck of workloads can change often.
0411 
0412 This enables --metric-only, unless overridden with --no-metric-only.
0413 
0414 The following restrictions only apply to older Intel CPUs and Atom,
0415 on newer CPUs (IceLake and later) TopDown can be collected for any thread:
0416 
0417 The top down metrics are collected per core instead of per
0418 CPU thread. Per core mode is automatically enabled
0419 and -a (global monitoring) is needed, requiring root rights or
0420 perf.perf_event_paranoid=-1.
0421 
0422 Topdown uses the full Performance Monitoring Unit, and needs
0423 disabling of the NMI watchdog (as root):
0424 echo 0 > /proc/sys/kernel/nmi_watchdog
0425 for best results. Otherwise the bottlenecks may be inconsistent
0426 on workload with changing phases.
0427 
0428 To interpret the results it is usually needed to know on which
0429 CPUs the workload runs on. If needed the CPUs can be forced using
0430 taskset.
0431 
0432 --td-level::
0433 Print the top-down statistics that equal to or lower than the input level.
0434 It allows users to print the interested top-down metrics level instead of
0435 the complete top-down metrics.
0436 
0437 The availability of the top-down metrics level depends on the hardware. For
0438 example, Ice Lake only supports L1 top-down metrics. The Sapphire Rapids
0439 supports both L1 and L2 top-down metrics.
0440 
0441 Default: 0 means the max level that the current hardware support.
0442 Error out if the input is higher than the supported max level.
0443 
0444 --no-merge::
0445 Do not merge results from same PMUs.
0446 
0447 When multiple events are created from a single event specification,
0448 stat will, by default, aggregate the event counts and show the result
0449 in a single row. This option disables that behavior and shows
0450 the individual events and counts.
0451 
0452 Multiple events are created from a single event specification when:
0453 1. Prefix or glob matching is used for the PMU name.
0454 2. Aliases, which are listed immediately after the Kernel PMU events
0455    by perf list, are used.
0456 
0457 --hybrid-merge::
0458 Merge the hybrid event counts from all PMUs.
0459 
0460 For hybrid events, by default, the stat aggregates and reports the event
0461 counts per PMU. But sometimes, it's also useful to aggregate event counts
0462 from all PMUs. This option enables that behavior and reports the counts
0463 without PMUs.
0464 
0465 For non-hybrid events, it should be no effect.
0466 
0467 --smi-cost::
0468 Measure SMI cost if msr/aperf/ and msr/smi/ events are supported.
0469 
0470 During the measurement, the /sys/device/cpu/freeze_on_smi will be set to
0471 freeze core counters on SMI.
0472 The aperf counter will not be effected by the setting.
0473 The cost of SMI can be measured by (aperf - unhalted core cycles).
0474 
0475 In practice, the percentages of SMI cycles is very useful for performance
0476 oriented analysis. --metric_only will be applied by default.
0477 The output is SMI cycles%, equals to (aperf - unhalted core cycles) / aperf
0478 
0479 Users who wants to get the actual value can apply --no-metric-only.
0480 
0481 --all-kernel::
0482 Configure all used events to run in kernel space.
0483 
0484 --all-user::
0485 Configure all used events to run in user space.
0486 
0487 --percore-show-thread::
0488 The event modifier "percore" has supported to sum up the event counts
0489 for all hardware threads in a core and show the counts per core.
0490 
0491 This option with event modifier "percore" enabled also sums up the event
0492 counts for all hardware threads in a core but show the sum counts per
0493 hardware thread. This is essentially a replacement for the any bit and
0494 convenient for post processing.
0495 
0496 --summary::
0497 Print summary for interval mode (-I).
0498 
0499 --no-csv-summary::
0500 Don't print 'summary' at the first column for CVS summary output.
0501 This option must be used with -x and --summary.
0502 
0503 This option can be enabled in perf config by setting the variable
0504 'stat.no-csv-summary'.
0505 
0506 $ perf config stat.no-csv-summary=true
0507 
0508 --cputype::
0509 Only enable events on applying cpu with this type for hybrid platform
0510 (e.g. core or atom)"
0511 
0512 EXAMPLES
0513 --------
0514 
0515 $ perf stat \-- make
0516 
0517    Performance counter stats for 'make':
0518 
0519         83723.452481      task-clock:u (msec)       #    1.004 CPUs utilized
0520                    0      context-switches:u        #    0.000 K/sec
0521                    0      cpu-migrations:u          #    0.000 K/sec
0522            3,228,188      page-faults:u             #    0.039 M/sec
0523      229,570,665,834      cycles:u                  #    2.742 GHz
0524      313,163,853,778      instructions:u            #    1.36  insn per cycle
0525       69,704,684,856      branches:u                #  832.559 M/sec
0526        2,078,861,393      branch-misses:u           #    2.98% of all branches
0527 
0528         83.409183620 seconds time elapsed
0529 
0530         74.684747000 seconds user
0531          8.739217000 seconds sys
0532 
0533 TIMINGS
0534 -------
0535 As displayed in the example above we can display 3 types of timings.
0536 We always display the time the counters were enabled/alive:
0537 
0538         83.409183620 seconds time elapsed
0539 
0540 For workload sessions we also display time the workloads spent in
0541 user/system lands:
0542 
0543         74.684747000 seconds user
0544          8.739217000 seconds sys
0545 
0546 Those times are the very same as displayed by the 'time' tool.
0547 
0548 CSV FORMAT
0549 ----------
0550 
0551 With -x, perf stat is able to output a not-quite-CSV format output
0552 Commas in the output are not put into "". To make it easy to parse
0553 it is recommended to use a different character like -x \;
0554 
0555 The fields are in this order:
0556 
0557         - optional usec time stamp in fractions of second (with -I xxx)
0558         - optional CPU, core, or socket identifier
0559         - optional number of logical CPUs aggregated
0560         - counter value
0561         - unit of the counter value or empty
0562         - event name
0563         - run time of counter
0564         - percentage of measurement time the counter was running
0565         - optional variance if multiple values are collected with -r
0566         - optional metric value
0567         - optional unit of metric
0568 
0569 Additional metrics may be printed with all earlier fields being empty.
0570 
0571 include::intel-hybrid.txt[]
0572 
0573 JSON FORMAT
0574 -----------
0575 
0576 With -j, perf stat is able to print out a JSON format output
0577 that can be used for parsing.
0578 
0579 - timestamp : optional usec time stamp in fractions of second (with -I)
0580 - optional aggregate options:
0581                 - core : core identifier (with --per-core)
0582                 - die : die identifier (with --per-die)
0583                 - socket : socket identifier (with --per-socket)
0584                 - node : node identifier (with --per-node)
0585                 - thread : thread identifier (with --per-thread)
0586 - counter-value : counter value
0587 - unit : unit of the counter value or empty
0588 - event : event name
0589 - variance : optional variance if multiple values are collected (with -r)
0590 - runtime : run time of counter
0591 - metric-value : optional metric value
0592 - metric-unit : optional unit of metric
0593 
0594 SEE ALSO
0595 --------
0596 linkperf:perf-top[1], linkperf:perf-list[1]