[FR] Provide public accessors to benchmark name and arguments #1551 (#1563)

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

* Update AUTHORS and CONTRIBUTORS

* Update benchmark_register.cc

* Fix lint formatting
This commit is contained in:
Mike Apodaca 2023-03-10 04:38:11 -08:00 committed by GitHub
parent 060d762d61
commit f32748c372
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 0 deletions

View File

@ -46,6 +46,7 @@ Lei Xu <eddyxu@gmail.com>
Marcel Jacobse <mjacobse@uni-bremen.de>
Matt Clarkson <mattyclarkson@gmail.com>
Maxim Vafin <maxvafin@gmail.com>
Mike Apodaca <gatorfax@gmail.com>
MongoDB Inc.
Nick Hutchinson <nshutchinson@gmail.com>
Norman Heino <norman.heino@gmail.com>

View File

@ -67,6 +67,7 @@ Lei Xu <eddyxu@gmail.com>
Marcel Jacobse <mjacobse@uni-bremen.de>
Matt Clarkson <mattyclarkson@gmail.com>
Maxim Vafin <maxvafin@gmail.com>
Mike Apodaca <gatorfax@gmail.com>
Nick Hutchinson <nshutchinson@gmail.com>
Norman Heino <norman.heino@gmail.com>
Oleksandr Sochka <sasha.sochka@gmail.com>

View File

@ -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;

View File

@ -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;
@ -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_;
}