perf-stat.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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 (eventsel+umask) in the form of rNNN where NNN is a
  30. hexadecimal event descriptor.
  31. - a symbolically formed event like 'pmu/param1=0x3,param2/' where
  32. param1 and param2 are defined as formats for the PMU in
  33. /sys/bus/event_source/devices/<pmu>/format/*
  34. - a symbolically formed event like 'pmu/config=M,config1=N,config2=K/'
  35. where M, N, K are numbers (in decimal, hex, octal format).
  36. Acceptable values for each of 'config', 'config1' and 'config2'
  37. parameters are defined by corresponding entries in
  38. /sys/bus/event_source/devices/<pmu>/format/*
  39. Note that the last two syntaxes support prefix and glob matching in
  40. the PMU name to simplify creation of events accross multiple instances
  41. of the same type of PMU in large systems (e.g. memory controller PMUs).
  42. Multiple PMU instances are typical for uncore PMUs, so the prefix
  43. 'uncore_' is also ignored when performing this match.
  44. -i::
  45. --no-inherit::
  46. child tasks do not inherit counters
  47. -p::
  48. --pid=<pid>::
  49. stat events on existing process id (comma separated list)
  50. -t::
  51. --tid=<tid>::
  52. stat events on existing thread id (comma separated list)
  53. -a::
  54. --all-cpus::
  55. system-wide collection from all CPUs (default if no target is specified)
  56. -c::
  57. --scale::
  58. scale/normalize counter values
  59. -d::
  60. --detailed::
  61. print more detailed statistics, can be specified up to 3 times
  62. -d: detailed events, L1 and LLC data cache
  63. -d -d: more detailed events, dTLB and iTLB events
  64. -d -d -d: very detailed events, adding prefetch events
  65. -r::
  66. --repeat=<n>::
  67. repeat command and print average + stddev (max: 100). 0 means forever.
  68. -B::
  69. --big-num::
  70. print large numbers with thousands' separators according to locale
  71. -C::
  72. --cpu=::
  73. Count only on the list of CPUs provided. Multiple CPUs can be provided as a
  74. comma-separated list with no space: 0,1. Ranges of CPUs are specified with -: 0-2.
  75. In per-thread mode, this option is ignored. The -a option is still necessary
  76. to activate system-wide monitoring. Default is to count on all CPUs.
  77. -A::
  78. --no-aggr::
  79. Do not aggregate counts across all monitored CPUs.
  80. -n::
  81. --null::
  82. null run - don't start any counters
  83. -v::
  84. --verbose::
  85. be more verbose (show counter open errors, etc)
  86. -x SEP::
  87. --field-separator SEP::
  88. print counts using a CSV-style output to make it easy to import directly into
  89. spreadsheets. Columns are separated by the string specified in SEP.
  90. --table:: Display time for each run (-r option), in a table format, e.g.:
  91. $ perf stat --null -r 5 --table perf bench sched pipe
  92. Performance counter stats for 'perf bench sched pipe' (5 runs):
  93. # Table of individual measurements:
  94. 5.189 (-0.293) #
  95. 5.189 (-0.294) #
  96. 5.186 (-0.296) #
  97. 5.663 (+0.181) ##
  98. 6.186 (+0.703) ####
  99. # Final result:
  100. 5.483 +- 0.198 seconds time elapsed ( +- 3.62% )
  101. -G name::
  102. --cgroup name::
  103. monitor only in the container (cgroup) called "name". This option is available only
  104. in per-cpu mode. The cgroup filesystem must be mounted. All threads belonging to
  105. container "name" are monitored when they run on the monitored CPUs. Multiple cgroups
  106. can be provided. Each cgroup is applied to the corresponding event, i.e., first cgroup
  107. to first event, second cgroup to second event and so on. It is possible to provide
  108. an empty cgroup (monitor all the time) using, e.g., -G foo,,bar. Cgroups must have
  109. corresponding events, i.e., they always refer to events defined earlier on the command
  110. line. If the user wants to track multiple events for a specific cgroup, the user can
  111. use '-e e1 -e e2 -G foo,foo' or just use '-e e1 -e e2 -G foo'.
  112. If wanting to monitor, say, 'cycles' for a cgroup and also for system wide, this
  113. command line can be used: 'perf stat -e cycles -G cgroup_name -a -e cycles'.
  114. -o file::
  115. --output file::
  116. Print the output into the designated file.
  117. --append::
  118. Append to the output file designated with the -o option. Ignored if -o is not specified.
  119. --log-fd::
  120. Log output to fd, instead of stderr. Complementary to --output, and mutually exclusive
  121. with it. --append may be used here. Examples:
  122. 3>results perf stat --log-fd 3 -- $cmd
  123. 3>>results perf stat --log-fd 3 --append -- $cmd
  124. --pre::
  125. --post::
  126. Pre and post measurement hooks, e.g.:
  127. perf stat --repeat 10 --null --sync --pre 'make -s O=defconfig-build/clean' -- make -s -j64 O=defconfig-build/ bzImage
  128. -I msecs::
  129. --interval-print msecs::
  130. Print count deltas every N milliseconds (minimum: 1ms)
  131. The overhead percentage could be high in some cases, for instance with small, sub 100ms intervals. Use with caution.
  132. example: 'perf stat -I 1000 -e cycles -a sleep 5'
  133. --interval-count times::
  134. Print count deltas for fixed number of times.
  135. This option should be used together with "-I" option.
  136. example: 'perf stat -I 1000 --interval-count 2 -e cycles -a'
  137. --interval-clear::
  138. Clear the screen before next interval.
  139. --timeout msecs::
  140. Stop the 'perf stat' session and print count deltas after N milliseconds (minimum: 10 ms).
  141. This option is not supported with the "-I" option.
  142. example: 'perf stat --time 2000 -e cycles -a'
  143. --metric-only::
  144. Only print computed metrics. Print them in a single line.
  145. Don't show any raw values. Not supported with --per-thread.
  146. --per-socket::
  147. Aggregate counts per processor socket for system-wide mode measurements. This
  148. is a useful mode to detect imbalance between sockets. To enable this mode,
  149. use --per-socket in addition to -a. (system-wide). The output includes the
  150. socket number and the number of online processors on that socket. This is
  151. useful to gauge the amount of aggregation.
  152. --per-core::
  153. Aggregate counts per physical processor for system-wide mode measurements. This
  154. is a useful mode to detect imbalance between physical cores. To enable this mode,
  155. use --per-core in addition to -a. (system-wide). The output includes the
  156. core number and the number of online logical processors on that physical processor.
  157. --per-thread::
  158. Aggregate counts per monitored threads, when monitoring threads (-t option)
  159. or processes (-p option).
  160. -D msecs::
  161. --delay msecs::
  162. After starting the program, wait msecs before measuring. This is useful to
  163. filter out the startup phase of the program, which is often very different.
  164. -T::
  165. --transaction::
  166. Print statistics of transactional execution if supported.
  167. STAT RECORD
  168. -----------
  169. Stores stat data into perf data file.
  170. -o file::
  171. --output file::
  172. Output file name.
  173. STAT REPORT
  174. -----------
  175. Reads and reports stat data from perf data file.
  176. -i file::
  177. --input file::
  178. Input file name.
  179. --per-socket::
  180. Aggregate counts per processor socket for system-wide mode measurements.
  181. --per-core::
  182. Aggregate counts per physical processor for system-wide mode measurements.
  183. -M::
  184. --metrics::
  185. Print metrics or metricgroups specified in a comma separated list.
  186. For a group all metrics from the group are added.
  187. The events from the metrics are automatically measured.
  188. See perf list output for the possble metrics and metricgroups.
  189. -A::
  190. --no-aggr::
  191. Do not aggregate counts across all monitored CPUs.
  192. --topdown::
  193. Print top down level 1 metrics if supported by the CPU. This allows to
  194. determine bottle necks in the CPU pipeline for CPU bound workloads,
  195. by breaking the cycles consumed down into frontend bound, backend bound,
  196. bad speculation and retiring.
  197. Frontend bound means that the CPU cannot fetch and decode instructions fast
  198. enough. Backend bound means that computation or memory access is the bottle
  199. neck. Bad Speculation means that the CPU wasted cycles due to branch
  200. mispredictions and similar issues. Retiring means that the CPU computed without
  201. an apparently bottleneck. The bottleneck is only the real bottleneck
  202. if the workload is actually bound by the CPU and not by something else.
  203. For best results it is usually a good idea to use it with interval
  204. mode like -I 1000, as the bottleneck of workloads can change often.
  205. The top down metrics are collected per core instead of per
  206. CPU thread. Per core mode is automatically enabled
  207. and -a (global monitoring) is needed, requiring root rights or
  208. perf.perf_event_paranoid=-1.
  209. Topdown uses the full Performance Monitoring Unit, and needs
  210. disabling of the NMI watchdog (as root):
  211. echo 0 > /proc/sys/kernel/nmi_watchdog
  212. for best results. Otherwise the bottlenecks may be inconsistent
  213. on workload with changing phases.
  214. This enables --metric-only, unless overriden with --no-metric-only.
  215. To interpret the results it is usually needed to know on which
  216. CPUs the workload runs on. If needed the CPUs can be forced using
  217. taskset.
  218. --no-merge::
  219. Do not merge results from same PMUs.
  220. When multiple events are created from a single event specification,
  221. stat will, by default, aggregate the event counts and show the result
  222. in a single row. This option disables that behavior and shows
  223. the individual events and counts.
  224. Multiple events are created from a single event specification when:
  225. 1. Prefix or glob matching is used for the PMU name.
  226. 2. Aliases, which are listed immediately after the Kernel PMU events
  227. by perf list, are used.
  228. --smi-cost::
  229. Measure SMI cost if msr/aperf/ and msr/smi/ events are supported.
  230. During the measurement, the /sys/device/cpu/freeze_on_smi will be set to
  231. freeze core counters on SMI.
  232. The aperf counter will not be effected by the setting.
  233. The cost of SMI can be measured by (aperf - unhalted core cycles).
  234. In practice, the percentages of SMI cycles is very useful for performance
  235. oriented analysis. --metric_only will be applied by default.
  236. The output is SMI cycles%, equals to (aperf - unhalted core cycles) / aperf
  237. Users who wants to get the actual value can apply --no-metric-only.
  238. EXAMPLES
  239. --------
  240. $ perf stat -- make
  241. Performance counter stats for 'make':
  242. 83723.452481 task-clock:u (msec) # 1.004 CPUs utilized
  243. 0 context-switches:u # 0.000 K/sec
  244. 0 cpu-migrations:u # 0.000 K/sec
  245. 3,228,188 page-faults:u # 0.039 M/sec
  246. 229,570,665,834 cycles:u # 2.742 GHz
  247. 313,163,853,778 instructions:u # 1.36 insn per cycle
  248. 69,704,684,856 branches:u # 832.559 M/sec
  249. 2,078,861,393 branch-misses:u # 2.98% of all branches
  250. 83.409183620 seconds time elapsed
  251. 74.684747000 seconds user
  252. 8.739217000 seconds sys
  253. TIMINGS
  254. -------
  255. As displayed in the example above we can display 3 types of timings.
  256. We always display the time the counters were enabled/alive:
  257. 83.409183620 seconds time elapsed
  258. For workload sessions we also display time the workloads spent in
  259. user/system lands:
  260. 74.684747000 seconds user
  261. 8.739217000 seconds sys
  262. Those times are the very same as displayed by the 'time' tool.
  263. CSV FORMAT
  264. ----------
  265. With -x, perf stat is able to output a not-quite-CSV format output
  266. Commas in the output are not put into "". To make it easy to parse
  267. it is recommended to use a different character like -x \;
  268. The fields are in this order:
  269. - optional usec time stamp in fractions of second (with -I xxx)
  270. - optional CPU, core, or socket identifier
  271. - optional number of logical CPUs aggregated
  272. - counter value
  273. - unit of the counter value or empty
  274. - event name
  275. - run time of counter
  276. - percentage of measurement time the counter was running
  277. - optional variance if multiple values are collected with -r
  278. - optional metric value
  279. - optional unit of metric
  280. Additional metrics may be printed with all earlier fields being empty.
  281. SEE ALSO
  282. --------
  283. linkperf:perf-top[1], linkperf:perf-list[1]