Skip to content

Pass benchmark State to ProfilerManager hooks via GetState() accessor#2253

Open
devtejasx wants to merge 1 commit into
google:mainfrom
devtejasx:profiler-manager-state
Open

Pass benchmark State to ProfilerManager hooks via GetState() accessor#2253
devtejasx wants to merge 1 commit into
google:mainfrom
devtejasx:profiler-manager-state

Conversation

@devtejasx

Copy link
Copy Markdown
Contributor

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 State to the ProfilerManager hooks.

Instead of overloading AfterSetupStart()/BeforeTeardownStop() with State-taking variants (which hide the base methods and force existing subclasses to add using declarations under -Woverloaded-virtual), the existing pure-virtual hooks are left unchanged and a protected ProfilerManager::GetState() accessor is added. The library sets the active State immediately before invoking each hook; the profiling run is single-threaded, so no synchronization is needed. Existing ProfilerManager implementations compile unchanged.

Fixes #2234

Testing:

  • Added coverage in profiler_manager_test that reads the benchmark name through GetState() from within AfterSetupStart().
  • Release build/tests and Debug build/tests pass (profiler_manager tests plus the full suite).
  • Builds remain -Werror clean.

AI disclosure (per AGENTS.md): this change was developed with AI assistance (Anthropic's Claude).

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
virtual void BeforeTeardownStop() = 0;

protected:
// The State of the benchmark run being profiled, giving access to e.g. the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

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.

[FR] Pass State into the ProfilerManager

2 participants