[AMDGPU][True16][CodeGen] true16 codegen pattern for v_med3_u/i16 (#121850)
[llvm-project.git] / third-party / benchmark / src / reporter.cc
blob076bc31a2eccc2adf9a47764a5ca75fd2b0aa6a6
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.
15 #include <cstdlib>
16 #include <iostream>
17 #include <map>
18 #include <string>
19 #include <tuple>
20 #include <vector>
22 #include "benchmark/benchmark.h"
23 #include "check.h"
24 #include "string_util.h"
25 #include "timers.h"
27 namespace benchmark {
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";
37 auto &Out = *out;
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";
43 #endif
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) << ")";
59 Out << "\n";
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 << ", ";
68 Out << "\n";
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 "
83 "overhead.\n";
86 #ifndef NDEBUG
87 Out << "***WARNING*** Library was built as DEBUG. Timings may be "
88 "affected.\n";
89 #endif
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;
103 return 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);
109 return new_time;
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);
115 return new_time;
118 } // end namespace benchmark