diff options
Diffstat (limited to 'lib/libcxx/utils/google-benchmark/src/console_reporter.cc')
-rw-r--r-- | lib/libcxx/utils/google-benchmark/src/console_reporter.cc | 55 |
1 files changed, 41 insertions, 14 deletions
diff --git a/lib/libcxx/utils/google-benchmark/src/console_reporter.cc b/lib/libcxx/utils/google-benchmark/src/console_reporter.cc index 3f3de02945a..48920ca7829 100644 --- a/lib/libcxx/utils/google-benchmark/src/console_reporter.cc +++ b/lib/libcxx/utils/google-benchmark/src/console_reporter.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "benchmark/reporter.h" +#include "benchmark/benchmark.h" #include "complexity.h" #include "counter.h" @@ -36,15 +36,16 @@ namespace benchmark { bool ConsoleReporter::ReportContext(const Context& context) { name_field_width_ = context.name_field_width; printed_header_ = false; + prev_counters_.clear(); PrintBasicContext(&GetErrorStream(), context); #ifdef BENCHMARK_OS_WINDOWS - if (color_output_ && &std::cout != &GetOutputStream()) { + if ((output_options_ & OO_Color) && &std::cout != &GetOutputStream()) { GetErrorStream() << "Color printing is only supported for stdout on windows." " Disabling color printing\n"; - color_output_ = false; + output_options_ = static_cast< OutputOptions >(output_options_ & ~OO_Color); } #endif @@ -52,25 +53,39 @@ bool ConsoleReporter::ReportContext(const Context& context) { } void ConsoleReporter::PrintHeader(const Run& run) { - std::string str = - FormatString("%-*s %13s %13s %10s\n", static_cast<int>(name_field_width_), - "Benchmark", "Time", "CPU", "Iterations"); + std::string str = FormatString("%-*s %13s %13s %10s", static_cast<int>(name_field_width_), + "Benchmark", "Time", "CPU", "Iterations"); if(!run.counters.empty()) { - str += " UserCounters..."; + if(output_options_ & OO_Tabular) { + for(auto const& c : run.counters) { + str += FormatString(" %10s", c.first.c_str()); + } + } else { + str += " UserCounters..."; + } } + str += "\n"; std::string line = std::string(str.length(), '-'); GetOutputStream() << line << "\n" << str << line << "\n"; } void ConsoleReporter::ReportRuns(const std::vector<Run>& reports) { for (const auto& run : reports) { - // print the header if none was printed yet - if (!printed_header_) { + // print the header: + // --- if none was printed yet + bool print_header = !printed_header_; + // --- or if the format is tabular and this run + // has different fields from the prev header + print_header |= (output_options_ & OO_Tabular) && + (!internal::SameNames(run.counters, prev_counters_)); + if (print_header) { printed_header_ = true; + prev_counters_ = run.counters; PrintHeader(run); } // As an alternative to printing the headers like this, we could sort - // the benchmarks by header and then print like that. + // the benchmarks by header and then print. But this would require + // waiting for the full results before printing, or printing twice. PrintRunData(run); } } @@ -86,8 +101,8 @@ static void IgnoreColorPrint(std::ostream& out, LogColor, const char* fmt, void ConsoleReporter::PrintRunData(const Run& result) { typedef void(PrinterFn)(std::ostream&, LogColor, const char*, ...); auto& Out = GetOutputStream(); - PrinterFn* printer = - color_output_ ? (PrinterFn*)ColorPrintf : IgnoreColorPrint; + PrinterFn* printer = (output_options_ & OO_Color) ? + (PrinterFn*)ColorPrintf : IgnoreColorPrint; auto name_color = (result.report_big_o || result.report_rms) ? COLOR_BLUE : COLOR_GREEN; printer(Out, name_color, "%-*s ", name_field_width_, @@ -133,8 +148,20 @@ void ConsoleReporter::PrintRunData(const Run& result) { } for (auto& c : result.counters) { - auto const& s = HumanReadableNumber(c.second.value); - printer(Out, COLOR_DEFAULT, " %s=%s", c.first.c_str(), s.c_str()); + const std::size_t cNameLen = std::max(std::string::size_type(10), + c.first.length()); + auto const& s = HumanReadableNumber(c.second.value, 1000); + if (output_options_ & OO_Tabular) { + if (c.second.flags & Counter::kIsRate) { + printer(Out, COLOR_DEFAULT, " %*s/s", cNameLen - 2, s.c_str()); + } else { + printer(Out, COLOR_DEFAULT, " %*s", cNameLen, s.c_str()); + } + } else { + const char* unit = (c.second.flags & Counter::kIsRate) ? "/s" : ""; + printer(Out, COLOR_DEFAULT, " %s=%s%s", c.first.c_str(), s.c_str(), + unit); + } } if (!rate.empty()) { |