Describe the bug
Perf counter events specified using --benchmark_perf_counters only count user events. Event modifiers, like "event:k" to count kernel-only events, or without a modifier, like "event" to count user+kernel, only count user events, i.e., as if it's always "event:u".
System
Which OS, compiler, and compiler version are you using:
OS: Ubuntu 22.04.2 LTS
Compiler and version: gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04)
To reproduce
Steps to reproduce the behavior:
Run a benchmark with --benchmark_perf_counters=INSTRUCTIONS:u,INSTRUCTIONS:k,INSTRUCTIONS
See that the event counts are the same for all three, even though the event modifiers should have it count only user events, kernel events, or total events, respectively, and should most likely be different. At the very least, INSTRUCTIONS:u + INSTRUCTIONS:k should total to INSTRUCTIONS.
Expected behavior
The :u modifier should count only user events. The :k modifier should count only kernel events. The event without a specified modifier should count both user and kernel events.
Additional context
The reason is that PerfCounters::Create() overrides the perf_event_attr attr to exclude kernel and hv events and thus only counts user events.
Describe the bug Perf counter events specified using --benchmark_perf_counters only count user events. Event modifiers, like "event:k" to count kernel-only events, or without a modifier, like "event" to count user+kernel, only count user events, i.e., as if it's always "event:u".
System Which OS, compiler, and compiler version are you using:
To reproduce Steps to reproduce the behavior:
Expected behavior The :u modifier should count only user events. The :k modifier should count only kernel events. The event without a specified modifier should count both user and kernel events.
Additional context The reason is that PerfCounters::Create() overrides the perf_event_attr attr to exclude kernel and hv events and thus only counts user events.
https://github.com/google/benchmark/blob/v1.8.0/src/perf_counters.cc#L141
If these three lines are commented out, event modifiers appear to work as expected.
However, giving just the event name without any modifiers still counts only user events because the default mode is user mode only.
https://github.com/google/benchmark/blob/v1.8.0/src/perf_counters.cc#L85
const int kCounterMode = PFM_PLM3; // user mode only
Nonetheless, if both user and kernel modifiers are given, i.e. "INSTRUCTIONS:k:u", then both will be counted.