25 #include "benchmark/benchmark.h"
39 tmp.reserve(
s.size());
83 value ?
"true" :
"false");
88 ss <<
'"' << StrEscape(
key) <<
"\": " <<
value;
94 ss <<
'"' << StrEscape(
key) <<
"\": " <<
value;
100 ss <<
'"' << StrEscape(
key) <<
"\": ";
103 ss << (
value < 0 ?
"-" :
"") <<
"NaN";
105 ss << (
value < 0 ?
"-" :
"") <<
"Infinity";
107 const auto max_digits10 =
108 std::numeric_limits<decltype(
value)>::max_digits10;
109 const auto max_fractional_digits10 = max_digits10 - 1;
110 ss << std::scientific << std::setprecision(max_fractional_digits10)
116 int64_t RoundDouble(
double v) {
return std::lround(
v); }
127 out << inner_indent <<
"\"context\": {\n";
131 out <<
indent << FormatKV(
"date", walltime_value) <<
",\n";
143 << FormatKV(
"mhz_per_cpu",
146 if (CPUInfo::Scaling::UNKNOWN != info.
scaling) {
148 << FormatKV(
"cpu_scaling_enabled",
149 info.
scaling == CPUInfo::Scaling::ENABLED ?
true :
false)
156 for (
size_t i = 0;
i < info.
caches.size(); ++
i) {
159 out << cache_indent << FormatKV(
"type", CI.type) <<
",\n";
160 out << cache_indent << FormatKV(
"level",
static_cast<int64_t>(CI.level))
162 out << cache_indent << FormatKV(
"size",
static_cast<int64_t>(CI.size))
165 << FormatKV(
"num_sharing",
static_cast<int64_t>(CI.num_sharing))
181 const char build_type[] =
"release";
183 const char build_type[] =
"debug";
185 out <<
indent << FormatKV(
"library_build_type", build_type);
190 out <<
indent << FormatKV(kv.first, kv.second);
196 out << inner_indent <<
"},\n";
197 out << inner_indent <<
"\"benchmarks\": [\n";
202 if (reports.empty()) {
212 for (
auto it = reports.begin();
it != reports.end(); ++
it) {
217 if (++it_cp != reports.end()) {
231 out <<
indent << FormatKV(
"name",
run.benchmark_name()) <<
",\n";
232 out <<
indent << FormatKV(
"family_index",
run.family_index) <<
",\n";
234 << FormatKV(
"per_family_instance_index",
run.per_family_instance_index)
236 out <<
indent << FormatKV(
"run_name",
run.run_name.str()) <<
",\n";
237 out <<
indent << FormatKV(
"run_type", [&
run]() ->
const char* {
238 switch (
run.run_type) {
239 case BenchmarkReporter::Run::RT_Iteration:
241 case BenchmarkReporter::Run::RT_Aggregate:
246 out <<
indent << FormatKV(
"repetitions",
run.repetitions) <<
",\n";
248 out <<
indent << FormatKV(
"repetition_index",
run.repetition_index)
251 out <<
indent << FormatKV(
"threads",
run.threads) <<
",\n";
253 out <<
indent << FormatKV(
"aggregate_name",
run.aggregate_name) <<
",\n";
254 out <<
indent << FormatKV(
"aggregate_unit", [&
run]() ->
const char* {
255 switch (
run.aggregate_unit) {
256 case StatisticUnit::kTime:
258 case StatisticUnit::kPercentage:
264 if (
run.error_occurred) {
265 out <<
indent << FormatKV(
"error_occurred",
run.error_occurred) <<
",\n";
266 out <<
indent << FormatKV(
"error_message",
run.error_message) <<
",\n";
268 if (!
run.report_big_o && !
run.report_rms) {
269 out <<
indent << FormatKV(
"iterations",
run.iterations) <<
",\n";
272 out <<
indent << FormatKV(
"real_time",
run.GetAdjustedRealTime())
274 out <<
indent << FormatKV(
"cpu_time",
run.GetAdjustedCPUTime());
277 out <<
indent << FormatKV(
"real_time",
run.real_accumulated_time)
279 out <<
indent << FormatKV(
"cpu_time",
run.cpu_accumulated_time);
283 }
else if (
run.report_big_o) {
284 out <<
indent << FormatKV(
"cpu_coefficient",
run.GetAdjustedCPUTime())
286 out <<
indent << FormatKV(
"real_coefficient",
run.GetAdjustedRealTime())
290 }
else if (
run.report_rms) {
291 out <<
indent << FormatKV(
"rms",
run.GetAdjustedCPUTime());
294 for (
auto& c :
run.counters) {
295 out <<
",\n" <<
indent << FormatKV(c.first, c.second);
298 if (
run.has_memory_result) {
299 out <<
",\n" <<
indent << FormatKV(
"allocs_per_iter",
run.allocs_per_iter);
300 out <<
",\n" <<
indent << FormatKV(
"max_bytes_used",
run.max_bytes_used);
303 if (!
run.report_label.empty()) {
304 out <<
",\n" <<
indent << FormatKV(
"label",
run.report_label);