Pass benchmark State to ProfilerManager hooks via GetState() accessor#2253
Open
devtejasx wants to merge 1 commit into
Open
Pass benchmark State to ProfilerManager hooks via GetState() accessor#2253devtejasx wants to merge 1 commit into
devtejasx wants to merge 1 commit into
Conversation
Custom profilers doing regional profiling need information about the benchmark being profiled, e.g. its name to register a named region. Add AfterSetupStart(const State&) and BeforeTeardownStop(const State&) overloads to ProfilerManager and call them with the State of the profiling run. The default implementations forward to the existing parameterless hooks, which are no longer pure virtual, so existing ProfilerManager implementations keep working unchanged. Fixes google#2234
dmah42
reviewed
Jul 16, 2026
| virtual void BeforeTeardownStop() = 0; | ||
|
|
||
| protected: | ||
| // The State of the benchmark run being profiled, giving access to e.g. the |
Member
There was a problem hiding this comment.
what happens if it's called outside of those methods? how can we enforce that? maybe return a pointer instead and allow it to be null?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #2249, which could not be reopened after its branch was force-pushed to address review feedback.
Profilers that do regional profiling need information about the benchmark being profiled, e.g. its name to register a named profiling region. This exposes the running benchmark's
Stateto theProfilerManagerhooks.Instead of overloading
AfterSetupStart()/BeforeTeardownStop()withState-taking variants (which hide the base methods and force existing subclasses to addusingdeclarations under-Woverloaded-virtual), the existing pure-virtual hooks are left unchanged and a protectedProfilerManager::GetState()accessor is added. The library sets the activeStateimmediately before invoking each hook; the profiling run is single-threaded, so no synchronization is needed. ExistingProfilerManagerimplementations compile unchanged.Fixes #2234
Testing:
AI disclosure (per AGENTS.md): this change was developed with AI assistance (Anthropic's Claude).