[BUG] --benchmark_perf_counters only counts user events

Abierto
#1,601 1 comentario 1 reacción 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@be0hhh ya está trabajando en esto.

Desde el 30/7/2026.

  • #2273 de @be0hhh — cerrado sin fusionar
  • #2285 de @jlaportebot — cerrado sin fusionar

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
68/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Tranquilo
Stack tecnológico
cpp
Área
performance

Línea de trabajo

Empieza en src/perf_counters.cc, en PerfCounters::Create(), alrededor de la línea 141, y en la definición de kCounterMode, alrededor de la línea 85. Reproduce el problema con --benchmark_perf_counters=INSTRUCTIONS:u,INSTRUCTIONS:k,INSTRUCTIONS; se considera terminado cuando los contadores de solo usuario, solo kernel y sin modificar reflejen sus respectivos ámbitos de eventos.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug help wanted

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:

  1. Run a benchmark with --benchmark_perf_counters=INSTRUCTIONS:u,INSTRUCTIONS:k,INSTRUCTIONS
  2. 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.

https://github.com/google/benchmark/blob/v1.8.0/src/perf_counters.cc#L141

    attr.exclude_kernel = true;
    attr.exclude_user = false;
    attr.exclude_hv = true;

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.

Lenguaje dominante
C++
Estrellas
10.5k
Forks
1.8k
Merge medio
1 d 15 h
PR fusionados (30 d)
28

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de google/benchmark

Todos los issues de google/benchmark

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.