google / google/benchmark

[FR] Ability to register flags for custom Reporters

Open
#1,885 1 comment 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

**Is your feature request related to a problem? Please describe.**
If I create a custom BenchmarkReporter, I also have to instantiate it and pass it to the `RunSpecifiedBenchmarks` function.

```c
int main(int argc, char** argv) {
benchmark::Initialize(&argc, argv);

BenchmarkReporter* reporter = new FooReporter();
benchmark::RunSpecifiedBenchmarks(&reporter);
benchmark::Shutdown();
}
```

**Describe the solution you'd like**
I would like to be able to easily configure a flag for my reporter such as `--benchmark_format=foo`.

```c
int main(int argc, char** argv) {
benchmark::Initialize(&argc, argv);
benchmark::RegisterReporter("foo", [](){ return new FooReporter()})
benchmark::RunSpecifiedBenchmarks();
benchmark::Shutdown();
}
```

**Describe alternatives you've considered**
- I currently proxy to the default reporter while intercepting the Run results in my custom reporter, so mine always runs on top of the default behavior.
- have considered adding arg parsing to `main()` but that is more convoluted.

**Additional context**
- I am interested in adding a custom reporter that asserts that the run results fall within some target performance threshold. I want to be able to optionally select this reporter at runtime with a flag. Built in support for assertions on a given threshold would be a welcome alternative.
- side note: it would be great to have an overload for `::benchmark::BenchmarkReporter::Run::GetAdjustedRealTime()` that accepts a time unit.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.