[FR] Ability to register flags for custom Reporters

未关闭
#1,885 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
30/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
cpp
领域
cli, devtools

调研方向

首先阅读现有的入口点 benchmark::Initialize、benchmark::RunSpecifiedBenchmarks 和 BenchmarkReporter,以及命令行标志如何选择内置 reporter。定义已注册的自定义 reporter 如何存储、选择和构造,然后验证无需将自定义 reporter 显式传递给 RunSpecifiedBenchmarks,即可通过标志选择它。

由索引模型根据 Issue 内容生成。

描述

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.
主要语言
C++
星标
10.5k
派生
1.8k
平均合并
1 天 15 小时
30 天内合并 PR
28

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

google/benchmark 的其他 Issue

查看 google/benchmark 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。