Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] Ability to register flags for custom Reporters #1885

Open
RobertAlbus opened this issue Dec 8, 2024 · 1 comment
Open

[FR] Ability to register flags for custom Reporters #1885

RobertAlbus opened this issue Dec 8, 2024 · 1 comment

Comments

@RobertAlbus
Copy link

RobertAlbus commented Dec 8, 2024

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.

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.

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.
@dmah42
Copy link
Member

dmah42 commented Dec 9, 2024

adding arg parsing to main is the expected way this would work. that gives you full control over your binary. benchmark will only pull out the flags it needs and leave the rest behind.

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

No branches or pull requests

2 participants