Skip to content

feat: Add opt-in cross-thread statistics for multithreaded counters#2182

Open
shreejaykurhade wants to merge 3 commits intogoogle:mainfrom
shreejaykurhade:issue-thread-fairness-statistics
Open

feat: Add opt-in cross-thread statistics for multithreaded counters#2182
shreejaykurhade wants to merge 3 commits intogoogle:mainfrom
shreejaykurhade:issue-thread-fairness-statistics

Conversation

@shreejaykurhade
Copy link
Copy Markdown
Contributor

@shreejaykurhade shreejaykurhade commented Apr 27, 2026

Summary

This PR addresses #1902 by enabling visibility into cross-thread imbalance in multithreaded counters.

Currently, only aggregated (summed) counter values are reported, which makes it difficult to assess fairness across benchmark-created threads. This change introduces an opt-in mechanism to compute and report distribution statistics across threads.

When enabled, benchmark-created thread counter values are retained long enough to compute the benchmark’s configured statistics across threads. The existing summed counter row remains unchanged, and additional aggregate rows:

  • _thread_mean
  • _thread_median
  • _thread_stddev
  • _thread_cv

For example, if three benchmark threads report work values 1, 2, and 3, the normal row still reports work=6, while the opt-in thread-stat rows report mean 2, median 2, stddev 1, and cv 50%.

Testing

  • cmake --build build
  • cmake --build build --config Debug
  • ctest --test-dir build --output-on-failure

All 74 CTest tests pass.

@shreejaykurhade
Copy link
Copy Markdown
Contributor Author

@dmah42 please review

@dmah42
Copy link
Copy Markdown
Member

dmah42 commented Apr 27, 2026

is anyone asking for this? i'm beginning to think you've pointed an agent at the codebase and asked it to come up with "improvements".

@shreejaykurhade
Copy link
Copy Markdown
Contributor Author

shreejaykurhade commented Apr 27, 2026

Yes, this is intended to address #1902, which asks for cross-thread statistics to inspect fairness/imbalance in multithreaded counters.

I do use Codex to understand parts of the codebase (e.g., structure and JSON fields), but the design and implementation here are deliberate.

The change is opt-in and doesn’t affect existing behavior.

Happy to adjust if needed.

@shreejaykurhade
Copy link
Copy Markdown
Contributor Author

@dmah42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants