From c5636440403c9790ee17d217ed511ce7467048e4 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Wed, 16 Feb 2022 10:23:54 +0100 Subject: [PATCH] Introduce the possibility to customize the help printer function (#1342) * introduce the possibility to customize the help printer function Signed-off-by: Vincenzo Palazzo * fixed naming convertion, and introduce the option function in the init method Signed-off-by: Vincenzo Palazzo * remove the macros to inject the helper function Signed-off-by: Vincenzo Palazzo * remove the default implementation, and introduce the nullprt Signed-off-by: Vincenzo Palazzo --- include/benchmark/benchmark.h | 5 ++--- src/benchmark.cc | 42 ++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/include/benchmark/benchmark.h b/include/benchmark/benchmark.h index 2478daea..79698f69 100644 --- a/include/benchmark/benchmark.h +++ b/include/benchmark/benchmark.h @@ -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. @@ -1202,7 +1203,6 @@ class LambdaBenchmark : public Benchmark { Lambda lambda_; }; #endif - } // namespace internal inline internal::Benchmark* RegisterBenchmark(const char* name, @@ -1254,7 +1254,6 @@ class Fixture : public internal::Benchmark { protected: virtual void BenchmarkCase(State&) = 0; }; - } // namespace benchmark // ------------------------------------------------------ diff --git a/src/benchmark.cc b/src/benchmark.cc index 3c06c85e..d9158432 100644 --- a/src/benchmark.cc +++ b/src/benchmark.cc @@ -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=]\n" - " [--benchmark_min_time=]\n" - " [--benchmark_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=]\n" - " [--benchmark_out=]\n" - " [--benchmark_out_format=]\n" - " [--benchmark_color={auto|true|false}]\n" - " [--benchmark_counters_tabular={true|false}]\n" - " [--benchmark_perf_counters=,...]\n" - " [--benchmark_context==,...]\n" - " [--v=]\n"); + if (HelperPrintf) { + HelperPrintf(); + } else { + fprintf(stdout, + "benchmark" + " [--benchmark_list_tests={true|false}]\n" + " [--benchmark_filter=]\n" + " [--benchmark_min_time=]\n" + " [--benchmark_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=]\n" + " [--benchmark_out=]\n" + " [--benchmark_out_format=]\n" + " [--benchmark_color={auto|true|false}]\n" + " [--benchmark_counters_tabular={true|false}]\n" + " [--benchmark_context==,...]\n" + " [--v=]\n"); + } exit(0); } @@ -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; }