2015-03-18 01:46:16 +08:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2017-07-05 06:31:47 +08:00
|
|
|
#include "benchmark/benchmark.h"
|
2016-09-03 11:34:34 +08:00
|
|
|
#include "timers.h"
|
2015-03-18 01:46:16 +08:00
|
|
|
|
|
|
|
#include <cstdlib>
|
2016-05-28 03:34:37 +08:00
|
|
|
|
|
|
|
#include <iostream>
|
2016-05-21 14:55:43 +08:00
|
|
|
#include <tuple>
|
2016-10-08 02:35:03 +08:00
|
|
|
#include <vector>
|
2015-03-18 01:46:16 +08:00
|
|
|
|
|
|
|
#include "check.h"
|
2018-07-09 12:17:44 +08:00
|
|
|
#include "string_util.h"
|
2015-03-18 01:46:16 +08:00
|
|
|
|
|
|
|
namespace benchmark {
|
|
|
|
|
2016-05-28 03:34:37 +08:00
|
|
|
BenchmarkReporter::BenchmarkReporter()
|
2016-10-08 02:35:03 +08:00
|
|
|
: output_stream_(&std::cout), error_stream_(&std::cerr) {}
|
2016-05-28 03:34:37 +08:00
|
|
|
|
2016-10-08 02:35:03 +08:00
|
|
|
BenchmarkReporter::~BenchmarkReporter() {}
|
2015-03-18 01:46:16 +08:00
|
|
|
|
2017-07-14 00:33:43 +08:00
|
|
|
void BenchmarkReporter::PrintBasicContext(std::ostream *out,
|
2016-05-28 06:45:25 +08:00
|
|
|
Context const &context) {
|
2017-07-14 00:33:43 +08:00
|
|
|
CHECK(out) << "cannot be null";
|
|
|
|
auto &Out = *out;
|
2015-03-18 01:46:16 +08:00
|
|
|
|
2016-05-28 06:45:25 +08:00
|
|
|
Out << LocalDateTimeString() << "\n";
|
|
|
|
|
2018-02-22 00:43:57 +08:00
|
|
|
if (context.executable_name)
|
|
|
|
Out << "Running " << context.executable_name << "\n";
|
|
|
|
|
2017-11-23 00:33:52 +08:00
|
|
|
const CPUInfo &info = context.cpu_info;
|
|
|
|
Out << "Run on (" << info.num_cpus << " X "
|
|
|
|
<< (info.cycles_per_second / 1000000.0) << " MHz CPU "
|
|
|
|
<< ((info.num_cpus > 1) ? "s" : "") << ")\n";
|
|
|
|
if (info.caches.size() != 0) {
|
|
|
|
Out << "CPU Caches:\n";
|
|
|
|
for (auto &CInfo : info.caches) {
|
|
|
|
Out << " L" << CInfo.level << " " << CInfo.type << " "
|
2017-11-27 04:33:01 +08:00
|
|
|
<< (CInfo.size / 1000) << "K";
|
|
|
|
if (CInfo.num_sharing != 0)
|
|
|
|
Out << " (x" << (info.num_cpus / CInfo.num_sharing) << ")";
|
|
|
|
Out << "\n";
|
2017-11-23 00:33:52 +08:00
|
|
|
}
|
|
|
|
}
|
2018-07-09 12:17:44 +08:00
|
|
|
if (!info.load_avg.empty()) {
|
|
|
|
Out << "Load Average: ";
|
|
|
|
for (auto It = info.load_avg.begin(); It != info.load_avg.end();) {
|
|
|
|
Out << StrFormat("%.2f", *It++);
|
|
|
|
if (It != info.load_avg.end()) Out << ", ";
|
|
|
|
}
|
|
|
|
Out << "\n";
|
|
|
|
}
|
2017-11-23 00:33:52 +08:00
|
|
|
|
|
|
|
if (info.scaling_enabled) {
|
2016-05-28 06:45:25 +08:00
|
|
|
Out << "***WARNING*** CPU scaling is enabled, the benchmark "
|
2016-10-08 02:35:03 +08:00
|
|
|
"real time measurements may be noisy and will incur extra "
|
|
|
|
"overhead.\n";
|
2016-05-19 03:25:00 +08:00
|
|
|
}
|
2016-05-25 04:25:59 +08:00
|
|
|
|
2016-05-28 06:45:25 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
Out << "***WARNING*** Library was built as DEBUG. Timings may be "
|
2016-10-08 02:35:03 +08:00
|
|
|
"affected.\n";
|
2016-05-28 06:45:25 +08:00
|
|
|
#endif
|
2016-05-21 14:55:43 +08:00
|
|
|
}
|
|
|
|
|
2018-02-22 00:43:57 +08:00
|
|
|
// No initializer because it's already initialized to NULL.
|
2018-06-01 18:14:19 +08:00
|
|
|
const char *BenchmarkReporter::Context::executable_name;
|
2018-02-22 00:43:57 +08:00
|
|
|
|
2018-12-11 19:23:02 +08:00
|
|
|
BenchmarkReporter::Context::Context()
|
|
|
|
: cpu_info(CPUInfo::Get()), sys_info(SystemInfo::Get()) {}
|
2017-11-23 00:33:52 +08:00
|
|
|
|
Track two more details about runs - the aggregate name, and run name. (#675)
This is related to @BaaMeow's work in https://github.com/google/benchmark/pull/616 but is not based on it.
Two new fields are tracked, and dumped into JSON:
* If the run is an aggregate, the aggregate's name is stored.
It can be RMS, BigO, mean, median, stddev, or any custom stat name.
* The aggregate-name-less run name is additionally stored.
I.e. not some name of the benchmark function, but the actual
name, but without the 'aggregate name' suffix.
This way one can group/filter all the runs,
and filter by the particular aggregate type.
I *might* need this for further tooling improvement.
Or maybe not.
But this is certainly worthwhile for custom tooling.
2018-09-13 20:08:15 +08:00
|
|
|
std::string BenchmarkReporter::Run::benchmark_name() const {
|
2019-03-17 21:38:51 +08:00
|
|
|
std::string name = run_name.str();
|
Track two more details about runs - the aggregate name, and run name. (#675)
This is related to @BaaMeow's work in https://github.com/google/benchmark/pull/616 but is not based on it.
Two new fields are tracked, and dumped into JSON:
* If the run is an aggregate, the aggregate's name is stored.
It can be RMS, BigO, mean, median, stddev, or any custom stat name.
* The aggregate-name-less run name is additionally stored.
I.e. not some name of the benchmark function, but the actual
name, but without the 'aggregate name' suffix.
This way one can group/filter all the runs,
and filter by the particular aggregate type.
I *might* need this for further tooling improvement.
Or maybe not.
But this is certainly worthwhile for custom tooling.
2018-09-13 20:08:15 +08:00
|
|
|
if (run_type == RT_Aggregate) {
|
|
|
|
name += "_" + aggregate_name;
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2016-05-28 06:45:25 +08:00
|
|
|
double BenchmarkReporter::Run::GetAdjustedRealTime() const {
|
|
|
|
double new_time = real_accumulated_time * GetTimeUnitMultiplier(time_unit);
|
2016-10-08 02:35:03 +08:00
|
|
|
if (iterations != 0) new_time /= static_cast<double>(iterations);
|
2016-05-28 06:45:25 +08:00
|
|
|
return new_time;
|
2016-03-29 03:32:11 +08:00
|
|
|
}
|
|
|
|
|
2016-05-28 06:45:25 +08:00
|
|
|
double BenchmarkReporter::Run::GetAdjustedCPUTime() const {
|
|
|
|
double new_time = cpu_accumulated_time * GetTimeUnitMultiplier(time_unit);
|
2016-10-08 02:35:03 +08:00
|
|
|
if (iterations != 0) new_time /= static_cast<double>(iterations);
|
2016-05-28 06:45:25 +08:00
|
|
|
return new_time;
|
2015-03-18 04:16:36 +08:00
|
|
|
}
|
2015-03-18 01:46:16 +08:00
|
|
|
|
2016-10-08 02:35:03 +08:00
|
|
|
} // end namespace benchmark
|