1 // Copyright 2015 Google Inc. All rights reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
22 #include "benchmark/benchmark.h"
24 #include "string_util.h"
29 BenchmarkReporter::BenchmarkReporter()
30 : output_stream_(&std::cout
), error_stream_(&std::cerr
) {}
32 BenchmarkReporter::~BenchmarkReporter() {}
34 void BenchmarkReporter::PrintBasicContext(std::ostream
*out
,
35 Context
const &context
) {
36 BM_CHECK(out
) << "cannot be null";
39 #ifndef BENCHMARK_OS_QURT
40 // Date/time information is not available on QuRT.
41 // Attempting to get it via this call cause the binary to crash.
42 Out
<< LocalDateTimeString() << "\n";
45 if (context
.executable_name
)
46 Out
<< "Running " << context
.executable_name
<< "\n";
48 const CPUInfo
&info
= context
.cpu_info
;
49 Out
<< "Run on (" << info
.num_cpus
<< " X "
50 << (info
.cycles_per_second
/ 1000000.0) << " MHz CPU "
51 << ((info
.num_cpus
> 1) ? "s" : "") << ")\n";
52 if (info
.caches
.size() != 0) {
53 Out
<< "CPU Caches:\n";
54 for (auto &CInfo
: info
.caches
) {
55 Out
<< " L" << CInfo
.level
<< " " << CInfo
.type
<< " "
56 << (CInfo
.size
/ 1024) << " KiB";
57 if (CInfo
.num_sharing
!= 0)
58 Out
<< " (x" << (info
.num_cpus
/ CInfo
.num_sharing
) << ")";
62 if (!info
.load_avg
.empty()) {
63 Out
<< "Load Average: ";
64 for (auto It
= info
.load_avg
.begin(); It
!= info
.load_avg
.end();) {
65 Out
<< StrFormat("%.2f", *It
++);
66 if (It
!= info
.load_avg
.end()) Out
<< ", ";
71 std::map
<std::string
, std::string
> *global_context
=
72 internal::GetGlobalContext();
74 if (global_context
!= nullptr) {
75 for (const auto &kv
: *global_context
) {
76 Out
<< kv
.first
<< ": " << kv
.second
<< "\n";
80 if (CPUInfo::Scaling::ENABLED
== info
.scaling
) {
81 Out
<< "***WARNING*** CPU scaling is enabled, the benchmark "
82 "real time measurements may be noisy and will incur extra "
87 Out
<< "***WARNING*** Library was built as DEBUG. Timings may be "
92 // No initializer because it's already initialized to NULL.
93 const char *BenchmarkReporter::Context::executable_name
;
95 BenchmarkReporter::Context::Context()
96 : cpu_info(CPUInfo::Get()), sys_info(SystemInfo::Get()) {}
98 std::string
BenchmarkReporter::Run::benchmark_name() const {
99 std::string name
= run_name
.str();
100 if (run_type
== RT_Aggregate
) {
101 name
+= "_" + aggregate_name
;
106 double BenchmarkReporter::Run::GetAdjustedRealTime() const {
107 double new_time
= real_accumulated_time
* GetTimeUnitMultiplier(time_unit
);
108 if (iterations
!= 0) new_time
/= static_cast<double>(iterations
);
112 double BenchmarkReporter::Run::GetAdjustedCPUTime() const {
113 double new_time
= cpu_accumulated_time
* GetTimeUnitMultiplier(time_unit
);
114 if (iterations
!= 0) new_time
/= static_cast<double>(iterations
);
118 } // end namespace benchmark