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

Introduce the possibility to customize the help printer function #1342

Merged
merged 4 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions include/benchmark/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
namespace benchmark {
class BenchmarkReporter;

BENCHMARK_EXPORT void Initialize(int* argc, char** argv);
BENCHMARK_EXPORT void Initialize(int* argc, char** argv,
void (*HelperPrinterf)() = NULL);
BENCHMARK_EXPORT void Shutdown();

// Report to stdout all arguments in 'argv' as unrecognized except the first.
Expand Down Expand Up @@ -1202,7 +1203,6 @@ class LambdaBenchmark : public Benchmark {
Lambda lambda_;
};
#endif

} // namespace internal

inline internal::Benchmark* RegisterBenchmark(const char* name,
Expand Down Expand Up @@ -1254,7 +1254,6 @@ class Fixture : public internal::Benchmark {
protected:
virtual void BenchmarkCase(State&) = 0;
};

} // namespace benchmark

// ------------------------------------------------------
Expand Down
42 changes: 24 additions & 18 deletions src/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -538,24 +538,29 @@ void AddCustomContext(const std::string& key, const std::string& value) {

namespace internal {

void (*HelperPrintf)();

void PrintUsageAndExit() {
fprintf(stdout,
"benchmark"
" [--benchmark_list_tests={true|false}]\n"
" [--benchmark_filter=<regex>]\n"
" [--benchmark_min_time=<min_time>]\n"
" [--benchmark_repetitions=<num_repetitions>]\n"
" [--benchmark_enable_random_interleaving={true|false}]\n"
" [--benchmark_report_aggregates_only={true|false}]\n"
" [--benchmark_display_aggregates_only={true|false}]\n"
" [--benchmark_format=<console|json|csv>]\n"
" [--benchmark_out=<filename>]\n"
" [--benchmark_out_format=<json|console|csv>]\n"
" [--benchmark_color={auto|true|false}]\n"
" [--benchmark_counters_tabular={true|false}]\n"
" [--benchmark_perf_counters=<counter>,...]\n"
" [--benchmark_context=<key>=<value>,...]\n"
" [--v=<verbosity>]\n");
if (HelperPrintf) {
HelperPrintf();
} else {
fprintf(stdout,
"benchmark"
" [--benchmark_list_tests={true|false}]\n"
" [--benchmark_filter=<regex>]\n"
" [--benchmark_min_time=<min_time>]\n"
" [--benchmark_repetitions=<num_repetitions>]\n"
" [--benchmark_enable_random_interleaving={true|false}]\n"
" [--benchmark_report_aggregates_only={true|false}]\n"
" [--benchmark_display_aggregates_only={true|false}]\n"
" [--benchmark_format=<console|json|csv>]\n"
" [--benchmark_out=<filename>]\n"
" [--benchmark_out_format=<json|console|csv>]\n"
" [--benchmark_color={auto|true|false}]\n"
" [--benchmark_counters_tabular={true|false}]\n"
" [--benchmark_context=<key>=<value>,...]\n"
" [--v=<verbosity>]\n");
}
exit(0);
}

Expand Down Expand Up @@ -618,9 +623,10 @@ int InitializeStreams() {

} // end namespace internal

void Initialize(int* argc, char** argv) {
void Initialize(int* argc, char** argv, void (*HelperPrintf)()) {
internal::ParseCommandLineFlags(argc, argv);
internal::LogLevel() = FLAGS_v;
internal::HelperPrintf = HelperPrintf;
}

void Shutdown() { delete internal::global_context; }
Expand Down