benchmark/src/reporter.cc
Go to the documentation of this file.
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/benchmark.h"
16 #include "timers.h"
17 
18 #include <cstdlib>
19 
20 #include <iostream>
21 #include <map>
22 #include <string>
23 #include <tuple>
24 #include <vector>
25 
26 #include "check.h"
27 #include "string_util.h"
28 
29 namespace benchmark {
30 namespace internal {
31 extern std::map<std::string, std::string>* global_context;
32 }
33 
35  : output_stream_(&std::cout), error_stream_(&std::cerr) {}
36 
38 
40  Context const &context) {
41  BM_CHECK(out) << "cannot be null";
42  auto &Out = *out;
43 
44  Out << LocalDateTimeString() << "\n";
45 
46  if (context.executable_name)
47  Out << "Running " << context.executable_name << "\n";
48 
49  const CPUInfo &info = context.cpu_info;
50  Out << "Run on (" << info.num_cpus << " X "
51  << (info.cycles_per_second / 1000000.0) << " MHz CPU "
52  << ((info.num_cpus > 1) ? "s" : "") << ")\n";
53  if (info.caches.size() != 0) {
54  Out << "CPU Caches:\n";
55  for (auto &CInfo : info.caches) {
56  Out << " L" << CInfo.level << " " << CInfo.type << " "
57  << (CInfo.size / 1024) << " KiB";
58  if (CInfo.num_sharing != 0)
59  Out << " (x" << (info.num_cpus / CInfo.num_sharing) << ")";
60  Out << "\n";
61  }
62  }
63  if (!info.load_avg.empty()) {
64  Out << "Load Average: ";
65  for (auto It = info.load_avg.begin(); It != info.load_avg.end();) {
66  Out << StrFormat("%.2f", *It++);
67  if (It != info.load_avg.end()) Out << ", ";
68  }
69  Out << "\n";
70  }
71 
72  if (internal::global_context != nullptr) {
73  for (const auto& kv: *internal::global_context) {
74  Out << kv.first << ": " << kv.second << "\n";
75  }
76  }
77 
78  if (CPUInfo::Scaling::ENABLED == info.scaling) {
79  Out << "***WARNING*** CPU scaling is enabled, the benchmark "
80  "real time measurements may be noisy and will incur extra "
81  "overhead.\n";
82  }
83 
84 #ifndef NDEBUG
85  Out << "***WARNING*** Library was built as DEBUG. Timings may be "
86  "affected.\n";
87 #endif
88 }
89 
90 // No initializer because it's already initialized to NULL.
92 
94  : cpu_info(CPUInfo::Get()), sys_info(SystemInfo::Get()) {}
95 
97  std::string name = run_name.str();
98  if (run_type == RT_Aggregate) {
99  name += "_" + aggregate_name;
100  }
101  return name;
102 }
103 
105  double new_time = real_accumulated_time * GetTimeUnitMultiplier(time_unit);
106  if (iterations != 0) new_time /= static_cast<double>(iterations);
107  return new_time;
108 }
109 
111  double new_time = cpu_accumulated_time * GetTimeUnitMultiplier(time_unit);
112  if (iterations != 0) new_time /= static_cast<double>(iterations);
113  return new_time;
114 }
115 
116 } // end namespace benchmark
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
check.h
benchmark::CPUInfo::load_avg
std::vector< double > load_avg
Definition: benchmark/include/benchmark/benchmark.h:1371
benchmark
Definition: bm_alarm.cc:55
benchmark::CPUInfo::scaling
Scaling scaling
Definition: benchmark/include/benchmark/benchmark.h:1368
BM_CHECK
#define BM_CHECK(b)
Definition: benchmark/src/check.h:58
timers.h
benchmark::CPUInfo::cycles_per_second
double cycles_per_second
Definition: benchmark/include/benchmark/benchmark.h:1369
benchmark::BenchmarkReporter::BenchmarkReporter
BenchmarkReporter()
Definition: benchmark/src/reporter.cc:34
benchmark::BenchmarkReporter::~BenchmarkReporter
virtual ~BenchmarkReporter()
Definition: benchmark/src/reporter.cc:37
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
setup.name
name
Definition: setup.py:542
benchmark::BenchmarkReporter::Context::executable_name
static const char * executable_name
Definition: benchmark/include/benchmark/benchmark.h:1419
benchmark::BenchmarkReporter::Run::GetAdjustedCPUTime
double GetAdjustedCPUTime() const
Definition: benchmark/src/reporter.cc:110
benchmark::BenchmarkReporter::PrintBasicContext
static void PrintBasicContext(std::ostream *out, Context const &context)
Definition: benchmark/src/reporter.cc:39
absl::synchronization_internal::Get
static GraphId Get(const IdMap &id, int num)
Definition: abseil-cpp/absl/synchronization/internal/graphcycles_test.cc:44
benchmark::CPUInfo::num_cpus
int num_cpus
Definition: benchmark/include/benchmark/benchmark.h:1367
benchmark::SystemInfo
Definition: benchmark/include/benchmark/benchmark.h:1381
benchmark::BenchmarkReporter::Run::benchmark_name
std::string benchmark_name
Definition: bloaty/third_party/protobuf/third_party/benchmark/include/benchmark/benchmark.h:1034
benchmark::BenchmarkReporter::Context::Context
Context()
Definition: benchmark/src/reporter.cc:93
string_util.h
benchmark::StrFormat
std::string StrFormat(const char *format,...)
Definition: benchmark/src/string_util.cc:158
std
Definition: grpcpp/impl/codegen/async_unary_call.h:407
benchmark::BenchmarkReporter::Run::GetAdjustedRealTime
double GetAdjustedRealTime() const
Definition: benchmark/src/reporter.cc:104
benchmark::internal::global_context
std::map< std::string, std::string > * global_context
Definition: benchmark/src/benchmark.cc:129
internal
Definition: benchmark/test/output_test_helper.cc:20
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
benchmark::CPUInfo
Definition: benchmark/include/benchmark/benchmark.h:1353
benchmark::GetTimeUnitMultiplier
double GetTimeUnitMultiplier(TimeUnit unit)
Definition: benchmark/include/benchmark/benchmark.h:1664
benchmark::BenchmarkReporter::Context
Definition: benchmark/include/benchmark/benchmark.h:1414
benchmark::LocalDateTimeString
std::string LocalDateTimeString()
Definition: benchmark/src/timers.cc:182
benchmark::CPUInfo::caches
std::vector< CacheInfo > caches
Definition: benchmark/include/benchmark/benchmark.h:1370


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:04