perf-stat.txt 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. perf-stat(1)
  2. ============
  3. NAME
  4. ----
  5. perf-stat - Run a command and gather performance counter statistics
  6. SYNOPSIS
  7. --------
  8. [verse]
  9. 'perf stat' [-e <EVENT> | --event=EVENT] [-a] <command>
  10. 'perf stat' [-e <EVENT> | --event=EVENT] [-a] \-- <command> [<options>]
  11. 'perf stat' [-e <EVENT> | --event=EVENT] [-a] record [-o file] \-- <command> [<options>]
  12. 'perf stat' report [-i file]
  13. DESCRIPTION
  14. -----------
  15. This command runs a command and gathers performance counter statistics
  16. from it.
  17. OPTIONS
  18. -------
  19. <command>...::
  20. Any command you can specify in a shell.
  21. record::
  22. See STAT RECORD.
  23. report::
  24. See STAT REPORT.
  25. -e::
  26. --event=::
  27. Select the PMU event. Selection can be:
  28. - a symbolic event name (use 'perf list' to list all events)
  29. - a raw PMU event in the form of rN where N is a hexadecimal value
  30. that represents the raw register encoding with the layout of the
  31. event control registers as described by entries in
  32. /sys/bus/event_source/devices/cpu/format/*.
  33. - a symbolic or raw PMU event followed by an optional colon
  34. and a list of event modifiers, e.g., cpu-cycles:p. See the
  35. linkperf:perf-list[1] man page for details on event modifiers.
  36. - a symbolically formed event like 'pmu/param1=0x3,param2/' where
  37. param1 and param2 are defined as formats for the PMU in
  38. /sys/bus/event_source/devices/<pmu>/format/*
  39. 'percore' is a event qualifier that sums up the event counts for both
  40. hardware threads in a core. For example:
  41. perf stat -A -a -e cpu/event,percore=1/,otherevent ...
  42. - a symbolically formed event like 'pmu/config=M,config1=N,config2=K/'
  43. where M, N, K are numbers (in decimal, hex, octal format).
  44. Acceptable values for each of 'config', 'config1' and 'config2'
  45. parameters are defined by corresponding entries in
  46. /sys/bus/event_source/devices/<pmu>/format/*
  47. Note that the last two syntaxes support prefix and glob matching in
  48. the PMU name to simplify creation of events across multiple instances
  49. of the same type of PMU in large systems (e.g. memory controller PMUs).
  50. Multiple PMU instances are typical for uncore PMUs, so the prefix
  51. 'uncore_' is also ignored when performing this match.
  52. -i::
  53. --no-inherit::
  54. child tasks do not inherit counters
  55. -p::
  56. --pid=<pid>::
  57. stat events on existing process id (comma separated list)
  58. -t::
  59. --tid=<tid>::
  60. stat events on existing thread id (comma separated list)
  61. -b::
  62. --bpf-prog::
  63. stat events on existing bpf program id (comma separated list),
  64. requiring root rights. bpftool-prog could be used to find program
  65. id all bpf programs in the system. For example:
  66. # bpftool prog | head -n 1
  67. 17247: tracepoint name sys_enter tag 192d548b9d754067 gpl
  68. # perf stat -e cycles,instructions --bpf-prog 17247 --timeout 1000
  69. Performance counter stats for 'BPF program(s) 17247':
  70. 85,967 cycles
  71. 28,982 instructions # 0.34 insn per cycle
  72. 1.102235068 seconds time elapsed
  73. --bpf-counters::
  74. Use BPF programs to aggregate readings from perf_events. This
  75. allows multiple perf-stat sessions that are counting the same metric (cycles,
  76. instructions, etc.) to share hardware counters.
  77. To use BPF programs on common events by default, use
  78. "perf config stat.bpf-counter-events=<list_of_events>".
  79. --bpf-attr-map::
  80. With option "--bpf-counters", different perf-stat sessions share
  81. information about shared BPF programs and maps via a pinned hashmap.
  82. Use "--bpf-attr-map" to specify the path of this pinned hashmap.
  83. The default path is /sys/fs/bpf/perf_attr_map.
  84. ifdef::HAVE_LIBPFM[]
  85. --pfm-events events::
  86. Select a PMU event using libpfm4 syntax (see http://perfmon2.sf.net)
  87. including support for event filters. For example '--pfm-events
  88. inst_retired:any_p:u:c=1:i'. More than one event can be passed to the
  89. option using the comma separator. Hardware events and generic hardware
  90. events cannot be mixed together. The latter must be used with the -e
  91. option. The -e option and this one can be mixed and matched. Events
  92. can be grouped using the {} notation.
  93. endif::HAVE_LIBPFM[]
  94. -a::
  95. --all-cpus::
  96. system-wide collection from all CPUs (default if no target is specified)
  97. --no-scale::
  98. Don't scale/normalize counter values
  99. -d::
  100. --detailed::
  101. print more detailed statistics, can be specified up to 3 times
  102. -d: detailed events, L1 and LLC data cache
  103. -d -d: more detailed events, dTLB and iTLB events
  104. -d -d -d: very detailed events, adding prefetch events
  105. -r::
  106. --repeat=<n>::
  107. repeat command and print average + stddev (max: 100). 0 means forever.
  108. -B::
  109. --big-num::
  110. print large numbers with thousands' separators according to locale.
  111. Enabled by default. Use "--no-big-num" to disable.
  112. Default setting can be changed with "perf config stat.big-num=false".
  113. -C::
  114. --cpu=::
  115. Count only on the list of CPUs provided. Multiple CPUs can be provided as a
  116. comma-separated list with no space: 0,1. Ranges of CPUs are specified with -: 0-2.
  117. In per-thread mode, this option is ignored. The -a option is still necessary
  118. to activate system-wide monitoring. Default is to count on all CPUs.
  119. -A::
  120. --no-aggr::
  121. Do not aggregate counts across all monitored CPUs.
  122. -n::
  123. --null::
  124. null run - Don't start any counters.
  125. This can be useful to measure just elapsed wall-clock time - or to assess the
  126. raw overhead of perf stat itself, without running any counters.
  127. -v::
  128. --verbose::
  129. be more verbose (show counter open errors, etc)
  130. -x SEP::
  131. --field-separator SEP::
  132. print counts using a CSV-style output to make it easy to import directly into
  133. spreadsheets. Columns are separated by the string specified in SEP.
  134. --table:: Display time for each run (-r option), in a table format, e.g.:
  135. $ perf stat --null -r 5 --table perf bench sched pipe
  136. Performance counter stats for 'perf bench sched pipe' (5 runs):
  137. # Table of individual measurements:
  138. 5.189 (-0.293) #
  139. 5.189 (-0.294) #
  140. 5.186 (-0.296) #
  141. 5.663 (+0.181) ##
  142. 6.186 (+0.703) ####
  143. # Final result:
  144. 5.483 +- 0.198 seconds time elapsed ( +- 3.62% )
  145. -G name::
  146. --cgroup name::
  147. monitor only in the container (cgroup) called "name". This option is available only
  148. in per-cpu mode. The cgroup filesystem must be mounted. All threads belonging to
  149. container "name" are monitored when they run on the monitored CPUs. Multiple cgroups
  150. can be provided. Each cgroup is applied to the corresponding event, i.e., first cgroup
  151. to first event, second cgroup to second event and so on. It is possible to provide
  152. an empty cgroup (monitor all the time) using, e.g., -G foo,,bar. Cgroups must have
  153. corresponding events, i.e., they always refer to events defined earlier on the command
  154. line. If the user wants to track multiple events for a specific cgroup, the user can
  155. use '-e e1 -e e2 -G foo,foo' or just use '-e e1 -e e2 -G foo'.
  156. If wanting to monitor, say, 'cycles' for a cgroup and also for system wide, this
  157. command line can be used: 'perf stat -e cycles -G cgroup_name -a -e cycles'.
  158. --for-each-cgroup name::
  159. Expand event list for each cgroup in "name" (allow multiple cgroups separated
  160. by comma). It also support regex patterns to match multiple groups. This has same
  161. effect that repeating -e option and -G option for each event x name. This option
  162. cannot be used with -G/--cgroup option.
  163. -o file::
  164. --output file::
  165. Print the output into the designated file.
  166. --append::
  167. Append to the output file designated with the -o option. Ignored if -o is not specified.
  168. --log-fd::
  169. Log output to fd, instead of stderr. Complementary to --output, and mutually exclusive
  170. with it. --append may be used here. Examples:
  171. 3>results perf stat --log-fd 3 \-- $cmd
  172. 3>>results perf stat --log-fd 3 --append \-- $cmd
  173. --control=fifo:ctl-fifo[,ack-fifo]::
  174. --control=fd:ctl-fd[,ack-fd]::
  175. ctl-fifo / ack-fifo are opened and used as ctl-fd / ack-fd as follows.
  176. Listen on ctl-fd descriptor for command to control measurement ('enable': enable events,
  177. 'disable': disable events). Measurements can be started with events disabled using
  178. --delay=-1 option. Optionally send control command completion ('ack\n') to ack-fd descriptor
  179. to synchronize with the controlling process. Example of bash shell script to enable and
  180. disable events during measurements:
  181. #!/bin/bash
  182. ctl_dir=/tmp/
  183. ctl_fifo=${ctl_dir}perf_ctl.fifo
  184. test -p ${ctl_fifo} && unlink ${ctl_fifo}
  185. mkfifo ${ctl_fifo}
  186. exec {ctl_fd}<>${ctl_fifo}
  187. ctl_ack_fifo=${ctl_dir}perf_ctl_ack.fifo
  188. test -p ${ctl_ack_fifo} && unlink ${ctl_ack_fifo}
  189. mkfifo ${ctl_ack_fifo}
  190. exec {ctl_fd_ack}<>${ctl_ack_fifo}
  191. perf stat -D -1 -e cpu-cycles -a -I 1000 \
  192. --control fd:${ctl_fd},${ctl_fd_ack} \
  193. \-- sleep 30 &
  194. perf_pid=$!
  195. sleep 5 && echo 'enable' >&${ctl_fd} && read -u ${ctl_fd_ack} e1 && echo "enabled(${e1})"
  196. sleep 10 && echo 'disable' >&${ctl_fd} && read -u ${ctl_fd_ack} d1 && echo "disabled(${d1})"
  197. exec {ctl_fd_ack}>&-
  198. unlink ${ctl_ack_fifo}
  199. exec {ctl_fd}>&-
  200. unlink ${ctl_fifo}
  201. wait -n ${perf_pid}
  202. exit $?
  203. --pre::
  204. --post::
  205. Pre and post measurement hooks, e.g.:
  206. perf stat --repeat 10 --null --sync --pre 'make -s O=defconfig-build/clean' \-- make -s -j64 O=defconfig-build/ bzImage
  207. -I msecs::
  208. --interval-print msecs::
  209. Print count deltas every N milliseconds (minimum: 1ms)
  210. The overhead percentage could be high in some cases, for instance with small, sub 100ms intervals. Use with caution.
  211. example: 'perf stat -I 1000 -e cycles -a sleep 5'
  212. If the metric exists, it is calculated by the counts generated in this interval and the metric is printed after #.
  213. --interval-count times::
  214. Print count deltas for fixed number of times.
  215. This option should be used together with "-I" option.
  216. example: 'perf stat -I 1000 --interval-count 2 -e cycles -a'
  217. --interval-clear::
  218. Clear the screen before next interval.
  219. --timeout msecs::
  220. Stop the 'perf stat' session and print count deltas after N milliseconds (minimum: 10 ms).
  221. This option is not supported with the "-I" option.
  222. example: 'perf stat --time 2000 -e cycles -a'
  223. --metric-only::
  224. Only print computed metrics. Print them in a single line.
  225. Don't show any raw values. Not supported with --per-thread.
  226. --per-socket::
  227. Aggregate counts per processor socket for system-wide mode measurements. This
  228. is a useful mode to detect imbalance between sockets. To enable this mode,
  229. use --per-socket in addition to -a. (system-wide). The output includes the
  230. socket number and the number of online processors on that socket. This is
  231. useful to gauge the amount of aggregation.
  232. --per-die::
  233. Aggregate counts per processor die for system-wide mode measurements. This
  234. is a useful mode to detect imbalance between dies. To enable this mode,
  235. use --per-die in addition to -a. (system-wide). The output includes the
  236. die number and the number of online processors on that die. This is
  237. useful to gauge the amount of aggregation.
  238. --per-core::
  239. Aggregate counts per physical processor for system-wide mode measurements. This
  240. is a useful mode to detect imbalance between physical cores. To enable this mode,
  241. use --per-core in addition to -a. (system-wide). The output includes the
  242. core number and the number of online logical processors on that physical processor.
  243. --per-thread::
  244. Aggregate counts per monitored threads, when monitoring threads (-t option)
  245. or processes (-p option).
  246. --per-node::
  247. Aggregate counts per NUMA nodes for system-wide mode measurements. This
  248. is a useful mode to detect imbalance between NUMA nodes. To enable this
  249. mode, use --per-node in addition to -a. (system-wide).
  250. -D msecs::
  251. --delay msecs::
  252. After starting the program, wait msecs before measuring (-1: start with events
  253. disabled). This is useful to filter out the startup phase of the program,
  254. which is often very different.
  255. -T::
  256. --transaction::
  257. Print statistics of transactional execution if supported.
  258. --metric-no-group::
  259. By default, events to compute a metric are placed in weak groups. The
  260. group tries to enforce scheduling all or none of the events. The
  261. --metric-no-group option places events outside of groups and may
  262. increase the chance of the event being scheduled - leading to more
  263. accuracy. However, as events may not be scheduled together accuracy
  264. for metrics like instructions per cycle can be lower - as both metrics
  265. may no longer be being measured at the same time.
  266. --metric-no-merge::
  267. By default metric events in different weak groups can be shared if one
  268. group contains all the events needed by another. In such cases one
  269. group will be eliminated reducing event multiplexing and making it so
  270. that certain groups of metrics sum to 100%. A downside to sharing a
  271. group is that the group may require multiplexing and so accuracy for a
  272. small group that need not have multiplexing is lowered. This option
  273. forbids the event merging logic from sharing events between groups and
  274. may be used to increase accuracy in this case.
  275. --quiet::
  276. Don't print output, warnings or messages. This is useful with perf stat
  277. record below to only write data to the perf.data file.
  278. STAT RECORD
  279. -----------
  280. Stores stat data into perf data file.
  281. -o file::
  282. --output file::
  283. Output file name.
  284. STAT REPORT
  285. -----------
  286. Reads and reports stat data from perf data file.
  287. -i file::
  288. --input file::
  289. Input file name.
  290. --per-socket::
  291. Aggregate counts per processor socket for system-wide mode measurements.
  292. --per-die::
  293. Aggregate counts per processor die for system-wide mode measurements.
  294. --per-core::
  295. Aggregate counts per physical processor for system-wide mode measurements.
  296. -M::
  297. --metrics::
  298. Print metrics or metricgroups specified in a comma separated list.
  299. For a group all metrics from the group are added.
  300. The events from the metrics are automatically measured.
  301. See perf list output for the possible metrics and metricgroups.
  302. -A::
  303. --no-aggr::
  304. Do not aggregate counts across all monitored CPUs.
  305. --topdown::
  306. Print complete top-down metrics supported by the CPU. This allows to
  307. determine bottle necks in the CPU pipeline for CPU bound workloads,
  308. by breaking the cycles consumed down into frontend bound, backend bound,
  309. bad speculation and retiring.
  310. Frontend bound means that the CPU cannot fetch and decode instructions fast
  311. enough. Backend bound means that computation or memory access is the bottle
  312. neck. Bad Speculation means that the CPU wasted cycles due to branch
  313. mispredictions and similar issues. Retiring means that the CPU computed without
  314. an apparently bottleneck. The bottleneck is only the real bottleneck
  315. if the workload is actually bound by the CPU and not by something else.
  316. For best results it is usually a good idea to use it with interval
  317. mode like -I 1000, as the bottleneck of workloads can change often.
  318. This enables --metric-only, unless overridden with --no-metric-only.
  319. The following restrictions only apply to older Intel CPUs and Atom,
  320. on newer CPUs (IceLake and later) TopDown can be collected for any thread:
  321. The top down metrics are collected per core instead of per
  322. CPU thread. Per core mode is automatically enabled
  323. and -a (global monitoring) is needed, requiring root rights or
  324. perf.perf_event_paranoid=-1.
  325. Topdown uses the full Performance Monitoring Unit, and needs
  326. disabling of the NMI watchdog (as root):
  327. echo 0 > /proc/sys/kernel/nmi_watchdog
  328. for best results. Otherwise the bottlenecks may be inconsistent
  329. on workload with changing phases.
  330. To interpret the results it is usually needed to know on which
  331. CPUs the workload runs on. If needed the CPUs can be forced using
  332. taskset.
  333. --td-level::
  334. Print the top-down statistics that equal to or lower than the input level.
  335. It allows users to print the interested top-down metrics level instead of
  336. the complete top-down metrics.
  337. The availability of the top-down metrics level depends on the hardware. For
  338. example, Ice Lake only supports L1 top-down metrics. The Sapphire Rapids
  339. supports both L1 and L2 top-down metrics.
  340. Default: 0 means the max level that the current hardware support.
  341. Error out if the input is higher than the supported max level.
  342. --no-merge::
  343. Do not merge results from same PMUs.
  344. When multiple events are created from a single event specification,
  345. stat will, by default, aggregate the event counts and show the result
  346. in a single row. This option disables that behavior and shows
  347. the individual events and counts.
  348. Multiple events are created from a single event specification when:
  349. 1. Prefix or glob matching is used for the PMU name.
  350. 2. Aliases, which are listed immediately after the Kernel PMU events
  351. by perf list, are used.
  352. --hybrid-merge::
  353. Merge the hybrid event counts from all PMUs.
  354. For hybrid events, by default, the stat aggregates and reports the event
  355. counts per PMU. But sometimes, it's also useful to aggregate event counts
  356. from all PMUs. This option enables that behavior and reports the counts
  357. without PMUs.
  358. For non-hybrid events, it should be no effect.
  359. --smi-cost::
  360. Measure SMI cost if msr/aperf/ and msr/smi/ events are supported.
  361. During the measurement, the /sys/device/cpu/freeze_on_smi will be set to
  362. freeze core counters on SMI.
  363. The aperf counter will not be effected by the setting.
  364. The cost of SMI can be measured by (aperf - unhalted core cycles).
  365. In practice, the percentages of SMI cycles is very useful for performance
  366. oriented analysis. --metric_only will be applied by default.
  367. The output is SMI cycles%, equals to (aperf - unhalted core cycles) / aperf
  368. Users who wants to get the actual value can apply --no-metric-only.
  369. --all-kernel::
  370. Configure all used events to run in kernel space.
  371. --all-user::
  372. Configure all used events to run in user space.
  373. --percore-show-thread::
  374. The event modifier "percore" has supported to sum up the event counts
  375. for all hardware threads in a core and show the counts per core.
  376. This option with event modifier "percore" enabled also sums up the event
  377. counts for all hardware threads in a core but show the sum counts per
  378. hardware thread. This is essentially a replacement for the any bit and
  379. convenient for post processing.
  380. --summary::
  381. Print summary for interval mode (-I).
  382. --no-csv-summary::
  383. Don't print 'summary' at the first column for CVS summary output.
  384. This option must be used with -x and --summary.
  385. This option can be enabled in perf config by setting the variable
  386. 'stat.no-csv-summary'.
  387. $ perf config stat.no-csv-summary=true
  388. --cputype::
  389. Only enable events on applying cpu with this type for hybrid platform
  390. (e.g. core or atom)"
  391. EXAMPLES
  392. --------
  393. $ perf stat \-- make
  394. Performance counter stats for 'make':
  395. 83723.452481 task-clock:u (msec) # 1.004 CPUs utilized
  396. 0 context-switches:u # 0.000 K/sec
  397. 0 cpu-migrations:u # 0.000 K/sec
  398. 3,228,188 page-faults:u # 0.039 M/sec
  399. 229,570,665,834 cycles:u # 2.742 GHz
  400. 313,163,853,778 instructions:u # 1.36 insn per cycle
  401. 69,704,684,856 branches:u # 832.559 M/sec
  402. 2,078,861,393 branch-misses:u # 2.98% of all branches
  403. 83.409183620 seconds time elapsed
  404. 74.684747000 seconds user
  405. 8.739217000 seconds sys
  406. TIMINGS
  407. -------
  408. As displayed in the example above we can display 3 types of timings.
  409. We always display the time the counters were enabled/alive:
  410. 83.409183620 seconds time elapsed
  411. For workload sessions we also display time the workloads spent in
  412. user/system lands:
  413. 74.684747000 seconds user
  414. 8.739217000 seconds sys
  415. Those times are the very same as displayed by the 'time' tool.
  416. CSV FORMAT
  417. ----------
  418. With -x, perf stat is able to output a not-quite-CSV format output
  419. Commas in the output are not put into "". To make it easy to parse
  420. it is recommended to use a different character like -x \;
  421. The fields are in this order:
  422. - optional usec time stamp in fractions of second (with -I xxx)
  423. - optional CPU, core, or socket identifier
  424. - optional number of logical CPUs aggregated
  425. - counter value
  426. - unit of the counter value or empty
  427. - event name
  428. - run time of counter
  429. - percentage of measurement time the counter was running
  430. - optional variance if multiple values are collected with -r
  431. - optional metric value
  432. - optional unit of metric
  433. Additional metrics may be printed with all earlier fields being empty.
  434. include::intel-hybrid.txt[]
  435. JSON FORMAT
  436. -----------
  437. With -j, perf stat is able to print out a JSON format output
  438. that can be used for parsing.
  439. - timestamp : optional usec time stamp in fractions of second (with -I)
  440. - optional aggregate options:
  441. - core : core identifier (with --per-core)
  442. - die : die identifier (with --per-die)
  443. - socket : socket identifier (with --per-socket)
  444. - node : node identifier (with --per-node)
  445. - thread : thread identifier (with --per-thread)
  446. - counter-value : counter value
  447. - unit : unit of the counter value or empty
  448. - event : event name
  449. - variance : optional variance if multiple values are collected (with -r)
  450. - runtime : run time of counter
  451. - metric-value : optional metric value
  452. - metric-unit : optional unit of metric
  453. SEE ALSO
  454. --------
  455. linkperf:perf-top[1], linkperf:perf-list[1]