[BUG] --benchmark_perf_counters only counts user events

Đang mở
#1,601 1 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@be0hhh đang làm issue này rồi.

Từ ngày 30/7/2026.

  • #2273 của @be0hhh — đã đóng, không merge
  • #2285 của @jlaportebot — đã đóng, không merge

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
cpp
Lĩnh vực
performance

Hướng nghiên cứu

Bắt đầu trong src/perf_counters.cc tại PerfCounters::Create() quanh dòng 141 và định nghĩa kCounterMode quanh dòng 85. Tái hiện vấn đề bằng --benchmark_perf_counters=INSTRUCTIONS:u,INSTRUCTIONS:k,INSTRUCTIONS; hoàn tất khi các bộ đếm chỉ người dùng, chỉ kernel và chưa sửa đổi phản ánh đúng phạm vi sự kiện tương ứng của chúng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
C++
Star
10.5k
Fork
1.8k
Merge trung bình
1 ngày 15 giờ
Pull request đã merge (30 ngày)
28

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của google/benchmark

Tất cả issue của google/benchmark

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.