Skip to content

Commit

Permalink
[FR] Provide public accessors to benchmark name and arguments #1551 (#…
Browse files Browse the repository at this point in the history
…1563)

* [FR] Provide public accessors to benchmark name and arguments #1551

* Update AUTHORS and CONTRIBUTORS

* Update benchmark_register.cc

* Fix lint formatting
  • Loading branch information
Mike Apodaca authored Mar 10, 2023
1 parent 060d762 commit f32748c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Lei Xu <[email protected]>
Marcel Jacobse <[email protected]>
Matt Clarkson <[email protected]>
Maxim Vafin <[email protected]>
Mike Apodaca <[email protected]>
MongoDB Inc.
Nick Hutchinson <[email protected]>
Norman Heino <[email protected]>
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Lei Xu <[email protected]>
Marcel Jacobse <[email protected]>
Matt Clarkson <[email protected]>
Maxim Vafin <[email protected]>
Mike Apodaca <[email protected]>
Nick Hutchinson <[email protected]>
Norman Heino <[email protected]>
Oleksandr Sochka <[email protected]>
Expand Down
3 changes: 3 additions & 0 deletions include/benchmark/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,10 @@ class BENCHMARK_EXPORT Benchmark {
explicit Benchmark(const char* name);
void SetName(const char* name);

public:
const char* GetName() const;
int ArgsCnt() const;
const char* GetArgName(int arg) const;

private:
friend class BenchmarkFamilies;
Expand Down
8 changes: 8 additions & 0 deletions src/benchmark_register.cc
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ Benchmark* Benchmark::ThreadPerCpu() {

void Benchmark::SetName(const char* name) { name_ = name; }

const char* Benchmark::GetName() const { return name_.c_str(); }

int Benchmark::ArgsCnt() const {
if (args_.empty()) {
if (arg_names_.empty()) return -1;
Expand All @@ -478,6 +480,12 @@ int Benchmark::ArgsCnt() const {
return static_cast<int>(args_.front().size());
}

const char* Benchmark::GetArgName(int arg) const {
BM_CHECK_GE(arg, 0);
BM_CHECK_LT(arg, static_cast<int>(arg_names_.size()));
return arg_names_[arg].c_str();
}

TimeUnit Benchmark::GetTimeUnit() const {
return use_default_time_unit_ ? GetDefaultTimeUnit() : time_unit_;
}
Expand Down

0 comments on commit f32748c

Please sign in to comment.