Skip to content

Let a benchmark identify the run it is part of (#1677) - #2279

Closed
devtejasx wants to merge 1 commit into
google:mainfrom
devtejasx:state-run-indices
Closed

devtejasx wants to merge 1 commit into
google:mainfrom
devtejasx:state-run-indices

Conversation

@devtejasx

Copy link
Copy Markdown
Contributor

A benchmark could only see its own function name, thread count and thread index. Which registration it came from, which instance of that registration it is, and which repetition is executing were known to the library -- they are in every reported Run -- but not reachable from the benchmark itself, so code that wants a location of its own to work in, or wants to act only on the first or last repetition, had nowhere to get that from.

Expose them on State as family_index(), per_family_instance_index(), repetition_index() and repetitions(), carrying the same values the reporters emit for that run. The repetition index and count come from the runner rather than the instance, since the total is the resolved one (--benchmark_repetitions when the registration does not set it). Setup/Teardown callbacks get them too; they already run once per repetition.

Adds state_indices_gtest, which registers two families -- one of them with two argument sets -- and checks that the values seen inside the benchmark and in the Setup/Teardown callbacks match those the reporter receives.

Note this grows State by four ints, so it is an ABI change for anyone linking the shared library.

A benchmark could only see its own function name, thread count and thread
index. Which registration it came from, which instance of that registration
it is, and which repetition is executing were known to the library -- they
are in every reported Run -- but not reachable from the benchmark itself, so
code that wants a location of its own to work in, or wants to act only on the
first or last repetition, had nowhere to get that from.

Expose them on State as family_index(), per_family_instance_index(),
repetition_index() and repetitions(), carrying the same values the reporters
emit for that run. The repetition index and count come from the runner rather
than the instance, since the total is the resolved one (--benchmark_repetitions
when the registration does not set it). Setup/Teardown callbacks get them too;
they already run once per repetition.

Adds state_indices_gtest, which registers two families -- one of them with two
argument sets -- and checks that the values seen inside the benchmark and in
the Setup/Teardown callbacks match those the reporter receives.

Note this grows State by four ints, so it is an ABI change for anyone linking
the shared library.
@dmah42 dmah42 closed this Aug 3, 2026
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