1 // Copyright 2015 Google Inc. All rights reserved.
2 //
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
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
14 
15 #include "benchmark/reporter.h"
16 #include "timers.h"
17 
18 #include <cstdlib>
19 
20 #include <iostream>
21 #include <vector>
22 #include <tuple>
23 
24 #include "check.h"
25 #include "stat.h"
26 
27 namespace benchmark {
28 
BenchmarkReporter()29 BenchmarkReporter::BenchmarkReporter()
30     : output_stream_(&std::cout), error_stream_(&std::cerr)
31 {
32 }
33 
~BenchmarkReporter()34 BenchmarkReporter::~BenchmarkReporter() {
35 }
36 
PrintBasicContext(std::ostream * out_ptr,Context const & context)37 void BenchmarkReporter::PrintBasicContext(std::ostream *out_ptr,
38                                           Context const &context) {
39   CHECK(out_ptr) << "cannot be null";
40   auto& Out = *out_ptr;
41 
42   Out << "Run on (" << context.num_cpus << " X " << context.mhz_per_cpu
43             << " MHz CPU " << ((context.num_cpus > 1) ? "s" : "") << ")\n";
44 
45   Out << LocalDateTimeString() << "\n";
46 
47   if (context.cpu_scaling_enabled) {
48     Out << "***WARNING*** CPU scaling is enabled, the benchmark "
49                  "real time measurements may be noisy and will incur extra "
50                  "overhead.\n";
51   }
52 
53 #ifndef NDEBUG
54   Out << "***WARNING*** Library was built as DEBUG. Timings may be "
55                "affected.\n";
56 #endif
57 }
58 
GetAdjustedRealTime() const59 double BenchmarkReporter::Run::GetAdjustedRealTime() const {
60   double new_time = real_accumulated_time * GetTimeUnitMultiplier(time_unit);
61   if (iterations != 0)
62     new_time /= static_cast<double>(iterations);
63   return new_time;
64 }
65 
GetAdjustedCPUTime() const66 double BenchmarkReporter::Run::GetAdjustedCPUTime() const {
67   double new_time = cpu_accumulated_time * GetTimeUnitMultiplier(time_unit);
68   if (iterations != 0)
69     new_time /= static_cast<double>(iterations);
70   return new_time;
71 }
72 
73 
74 
75 } // end namespace benchmark
76