google / google/benchmark

[FR] Pass State into the ProfilerManager

Open
#2,234 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
10.4k
Forks
1.8k
Avg merge
2d 4h
Merged PRs (30d)
8

Description

Hello

Some custom profilers for regional profiling require registering a region with a string name. It's convenient to use the name of the benchmark itself as this name. Therefore, I suggest adding a mechanism to the ProfilerManager that would get the benchmark name

One way to implement this is to pass State as an argument to the AfterSetupStart and BeforeTeardownStop methods. Then, the ProfilerManager will have access to the benchmark name via the name() method

To maintain backward compatibility with the current interface, I propose adding a new function overload and leaving the old one (you can mark it as deprecated if you prefer)

virtual void AfterSetupStart() {};
virtual void AfterSetupStart(const State&) { AfterSetupStart() };

And in benchmark.cc we pass *this into this methods

Currently, this is the only context for using this feature. However, I think CustomProfiler's ability to look into State could be useful for other tasks as well. This would allow more context to be passed to profilers. But if you think that passing the State is too much, we could add a lightweight method to pass only the name of the bench

Thank you

Contributor guide

Open the contributing guide

Research direction

Start by locating ProfilerManager's AfterSetupStart and BeforeTeardownStop hooks and their call sites in benchmark.cc. Review how the existing profiler interface is used, then preserve the current hooks while making benchmark State available to the new overloads; done means custom profilers can read the benchmark name without breaking existing implementations.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
performance
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.