From 02f409a71f5231bf9b8803e771bdfa1056da23cc Mon Sep 17 00:00:00 2001 From: Dominic Hamon Date: Mon, 2 May 2016 12:04:16 -0700 Subject: [PATCH] Only output optional fields if they're set --- src/benchmark.cc | 10 +++++----- src/console_reporter.cc | 20 ++++++++++++++++---- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/benchmark.cc b/src/benchmark.cc index cb55f969..35b5e2d4 100644 --- a/src/benchmark.cc +++ b/src/benchmark.cc @@ -64,9 +64,9 @@ DEFINE_int32(benchmark_repetitions, 1, "The number of runs of each benchmark. If greater than 1, the " "mean and standard deviation of the runs will be reported."); -DEFINE_string(benchmark_format, "tabular", +DEFINE_string(benchmark_format, "console", "The format to use for console output. Valid values are " - "'tabular', 'json', or 'csv'."); + "'console', 'json', or 'csv'."); DEFINE_bool(color_print, true, "Enables colorized logging."); @@ -828,7 +828,7 @@ void RunMatchingBenchmarks(const std::string& spec, std::unique_ptr GetDefaultReporter() { typedef std::unique_ptr PtrType; - if (FLAGS_benchmark_format == "tabular") { + if (FLAGS_benchmark_format == "console") { return PtrType(new ConsoleReporter); } else if (FLAGS_benchmark_format == "json") { return PtrType(new JSONReporter); @@ -874,7 +874,7 @@ void PrintUsageAndExit() { " [--benchmark_filter=]\n" " [--benchmark_min_time=]\n" " [--benchmark_repetitions=]\n" - " [--benchmark_format=]\n" + " [--benchmark_format=]\n" " [--color_print={true|false}]\n" " [--v=]\n"); exit(0); @@ -906,7 +906,7 @@ void ParseCommandLineFlags(int* argc, char** argv) { } } - if (FLAGS_benchmark_format != "tabular" && + if (FLAGS_benchmark_format != "console" && FLAGS_benchmark_format != "json" && FLAGS_benchmark_format != "csv") { PrintUsageAndExit(); diff --git a/src/console_reporter.cc b/src/console_reporter.cc index 375e8610..56bd3ced 100644 --- a/src/console_reporter.cc +++ b/src/console_reporter.cc @@ -99,6 +99,7 @@ void ConsoleReporter::PrintRunData(const Run& result) { ColorPrintf(COLOR_GREEN, "%-*s ", name_field_width_, result.benchmark_name.c_str()); + if (result.iterations == 0) { ColorPrintf(COLOR_YELLOW, "%10.0f %s %10.0f %s ", result.real_accumulated_time * multiplier, @@ -114,11 +115,22 @@ void ConsoleReporter::PrintRunData(const Run& result) { (static_cast(result.iterations)), timeLabel); } + ColorPrintf(COLOR_CYAN, "%10lld", result.iterations); - ColorPrintf(COLOR_DEFAULT, "%*s %*s %s\n", - 13, rate.c_str(), - 18, items.c_str(), - result.report_label.c_str()); + + if (!rate.empty()) { + ColorPrintf(COLOR_DEFAULT, " %*s", 13, rate.c_str()); + } + + if (!items.empty()) { + ColorPrintf(COLOR_DEFAULT, " %*s", 18, items.c_str()); + } + + if (!result.report_label.empty()) { + ColorPrintf(COLOR_DEFAULT, " %s", result.report_label.c_str()); + } + + ColorPrintf(COLOR_DEFAULT, "\n"); } } // end namespace benchmark