perf-stat.txt 12 KB

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