mirror of
https://github.com/google/benchmark.git
synced 2024-12-29 14:00:16 +08:00
Fix error-handling in reporters
This commit is contained in:
parent
924b8cee7a
commit
525858e687
@ -15,6 +15,7 @@
|
|||||||
#include "benchmark/reporter.h"
|
#include "benchmark/reporter.h"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
@ -53,8 +54,12 @@ void CSVReporter::ReportRuns(const std::vector<Run> & reports) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto error_count = std::count_if(
|
||||||
|
reports.begin(), reports.end(),
|
||||||
|
[](Run const& run) {return run.error_occurred;});
|
||||||
|
|
||||||
std::vector<Run> reports_cp = reports;
|
std::vector<Run> reports_cp = reports;
|
||||||
if (reports.size() >= 2) {
|
if (reports.size() - error_count >= 2) {
|
||||||
Run mean_data;
|
Run mean_data;
|
||||||
Run stddev_data;
|
Run stddev_data;
|
||||||
BenchmarkReporter::ComputeStats(reports, &mean_data, &stddev_data);
|
BenchmarkReporter::ComputeStats(reports, &mean_data, &stddev_data);
|
||||||
@ -82,6 +87,20 @@ void CSVReporter::ReportComplexity(const std::vector<Run>& complexity_reports) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CSVReporter::PrintRunData(const Run & run) {
|
void CSVReporter::PrintRunData(const Run & run) {
|
||||||
|
|
||||||
|
|
||||||
|
// Field with embedded double-quote characters must be doubled and the field
|
||||||
|
// delimited with double-quotes.
|
||||||
|
std::string name = run.benchmark_name;
|
||||||
|
ReplaceAll(&name, "\"", "\"\"");
|
||||||
|
std::cout << '"' << name << "\",";
|
||||||
|
if (run.error_occurred) {
|
||||||
|
std::cout << "error_occurred,";
|
||||||
|
std::string msg = run.error_message;
|
||||||
|
ReplaceAll(&msg, "\"", "\"\"");
|
||||||
|
std::cout << '"' << msg << "\",";
|
||||||
|
}
|
||||||
|
|
||||||
double multiplier;
|
double multiplier;
|
||||||
const char* timeLabel;
|
const char* timeLabel;
|
||||||
std::tie(timeLabel, multiplier) = GetTimeUnitAndMultiplier(run.time_unit);
|
std::tie(timeLabel, multiplier) = GetTimeUnitAndMultiplier(run.time_unit);
|
||||||
@ -93,12 +112,6 @@ void CSVReporter::PrintRunData(const Run & run) {
|
|||||||
cpu_time = cpu_time / static_cast<double>(run.iterations);
|
cpu_time = cpu_time / static_cast<double>(run.iterations);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Field with embedded double-quote characters must be doubled and the field
|
|
||||||
// delimited with double-quotes.
|
|
||||||
std::string name = run.benchmark_name;
|
|
||||||
ReplaceAll(&name, "\"", "\"\"");
|
|
||||||
std::cout << "\"" << name << "\",";
|
|
||||||
|
|
||||||
// Do not print iteration on bigO and RMS report
|
// Do not print iteration on bigO and RMS report
|
||||||
if(!run.report_big_o && !run.report_rms) {
|
if(!run.report_big_o && !run.report_rms) {
|
||||||
std::cout << run.iterations;
|
std::cout << run.iterations;
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "benchmark/reporter.h"
|
#include "benchmark/reporter.h"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
@ -96,8 +97,13 @@ void JSONReporter::ReportRuns(std::vector<Run> const& reports) {
|
|||||||
out << ",\n";
|
out << ",\n";
|
||||||
}
|
}
|
||||||
first_report_ = false;
|
first_report_ = false;
|
||||||
|
|
||||||
|
auto error_count = std::count_if(
|
||||||
|
reports.begin(), reports.end(),
|
||||||
|
[](Run const& run) {return run.error_occurred;});
|
||||||
|
|
||||||
std::vector<Run> reports_cp = reports;
|
std::vector<Run> reports_cp = reports;
|
||||||
if (reports.size() >= 2) {
|
if (reports.size() - error_count >= 2) {
|
||||||
Run mean_data;
|
Run mean_data;
|
||||||
Run stddev_data;
|
Run stddev_data;
|
||||||
BenchmarkReporter::ComputeStats(reports, &mean_data, &stddev_data);
|
BenchmarkReporter::ComputeStats(reports, &mean_data, &stddev_data);
|
||||||
|
Loading…
Reference in New Issue
Block a user