2021-04-28 08:25:29 +00:00
|
|
|
<a name="perf-counters" />
|
|
|
|
|
|
|
|
# User-Requested Performance Counters
|
|
|
|
|
|
|
|
When running benchmarks, the user may choose to request collection of
|
|
|
|
performance counters. This may be useful in investigation scenarios - narrowing
|
|
|
|
down the cause of a regression; or verifying that the underlying cause of a
|
|
|
|
performance improvement matches expectations.
|
|
|
|
|
|
|
|
This feature is available if:
|
|
|
|
|
|
|
|
* The benchmark is run on an architecture featuring a Performance Monitoring
|
|
|
|
Unit (PMU),
|
|
|
|
* The benchmark is compiled with support for collecting counters. Currently,
|
2022-10-31 11:03:59 +00:00
|
|
|
this requires [libpfm](http://perfmon2.sourceforge.net/), which is built as a
|
|
|
|
dependency via Bazel.
|
2021-04-28 08:25:29 +00:00
|
|
|
|
|
|
|
The feature does not require modifying benchmark code. Counter collection is
|
|
|
|
handled at the boundaries where timer collection is also handled.
|
|
|
|
|
|
|
|
To opt-in:
|
2023-01-10 12:25:32 +00:00
|
|
|
* If using a Bazel build, add `--define pfm=1` to your build flags
|
2022-10-31 11:03:59 +00:00
|
|
|
* If using CMake:
|
|
|
|
* Install `libpfm4-dev`, e.g. `apt-get install libpfm4-dev`.
|
|
|
|
* Enable the CMake flag `BENCHMARK_ENABLE_LIBPFM` in `CMakeLists.txt`.
|
2021-04-28 08:25:29 +00:00
|
|
|
|
|
|
|
To use, pass a comma-separated list of counter names through the
|
|
|
|
`--benchmark_perf_counters` flag. The names are decoded through libpfm - meaning,
|
|
|
|
they are platform specific, but some (e.g. `CYCLES` or `INSTRUCTIONS`) are
|
|
|
|
mapped by libpfm to platform-specifics - see libpfm
|
|
|
|
[documentation](http://perfmon2.sourceforge.net/docs.html) for more details.
|
|
|
|
|
|
|
|
The counter values are reported back through the [User Counters](../README.md#custom-counters)
|
|
|
|
mechanism, meaning, they are available in all the formats (e.g. JSON) supported
|
2022-10-31 11:03:59 +00:00
|
|
|
by User Counters.
|