Unverified Commit 99010118 by Alexander Enaldiev Committed by GitHub

JSONReporter: don't report on scaling if we didn't get it (#1005) (#1008)

* JSONReporter: don't report on scaling if we didn't get it (#1005) * JSONReporter: fix due to review (std::pair<bool, bool> -> enum) * JSONReporter: scaling: fix the algo (due to review discussion) * benchmark.h: revert to old-fashioned enum's (C++03 compatibility); rreporter_output_test: let's skip scaling
parent 37177a84
...@@ -176,6 +176,7 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond); ...@@ -176,6 +176,7 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
#include <map> #include <map>
#include <set> #include <set>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
#if defined(BENCHMARK_HAS_CXX11) #if defined(BENCHMARK_HAS_CXX11)
...@@ -1294,10 +1295,16 @@ struct CPUInfo { ...@@ -1294,10 +1295,16 @@ struct CPUInfo {
int num_sharing; int num_sharing;
}; };
enum Scaling {
UNKNOWN,
ENABLED,
DISABLED
};
int num_cpus; int num_cpus;
double cycles_per_second; double cycles_per_second;
std::vector<CacheInfo> caches; std::vector<CacheInfo> caches;
bool scaling_enabled; Scaling scaling;
std::vector<double> load_avg; std::vector<double> load_avg;
static const CPUInfo& Get(); static const CPUInfo& Get();
......
...@@ -122,8 +122,10 @@ bool JSONReporter::ReportContext(const Context& context) { ...@@ -122,8 +122,10 @@ bool JSONReporter::ReportContext(const Context& context) {
<< FormatKV("mhz_per_cpu", << FormatKV("mhz_per_cpu",
RoundDouble(info.cycles_per_second / 1000000.0)) RoundDouble(info.cycles_per_second / 1000000.0))
<< ",\n"; << ",\n";
out << indent << FormatKV("cpu_scaling_enabled", info.scaling_enabled) if (CPUInfo::Scaling::UNKNOWN != info.scaling) {
<< ",\n"; out << indent << FormatKV("cpu_scaling_enabled", info.scaling == CPUInfo::Scaling::ENABLED ? true : false)
<< ",\n";
}
out << indent << "\"caches\": [\n"; out << indent << "\"caches\": [\n";
indent = std::string(6, ' '); indent = std::string(6, ' ');
......
...@@ -64,7 +64,7 @@ void BenchmarkReporter::PrintBasicContext(std::ostream *out, ...@@ -64,7 +64,7 @@ void BenchmarkReporter::PrintBasicContext(std::ostream *out,
Out << "\n"; Out << "\n";
} }
if (info.scaling_enabled) { if (CPUInfo::Scaling::ENABLED == info.scaling) {
Out << "***WARNING*** CPU scaling is enabled, the benchmark " Out << "***WARNING*** CPU scaling is enabled, the benchmark "
"real time measurements may be noisy and will incur extra " "real time measurements may be noisy and will incur extra "
"overhead.\n"; "overhead.\n";
......
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
#include <memory> #include <memory>
#include <sstream> #include <sstream>
#include <locale> #include <locale>
#include <utility>
#include "check.h" #include "check.h"
#include "cycleclock.h" #include "cycleclock.h"
...@@ -209,11 +210,11 @@ bool ReadFromFile(std::string const& fname, ArgT* arg) { ...@@ -209,11 +210,11 @@ bool ReadFromFile(std::string const& fname, ArgT* arg) {
return f.good(); return f.good();
} }
bool CpuScalingEnabled(int num_cpus) { CPUInfo::Scaling CpuScaling(int num_cpus) {
// We don't have a valid CPU count, so don't even bother. // We don't have a valid CPU count, so don't even bother.
if (num_cpus <= 0) return false; if (num_cpus <= 0) return CPUInfo::Scaling::UNKNOWN;
#ifdef BENCHMARK_OS_QNX #ifdef BENCHMARK_OS_QNX
return false; return CPUInfo::Scaling::UNKNOWN;
#endif #endif
#ifndef BENCHMARK_OS_WINDOWS #ifndef BENCHMARK_OS_WINDOWS
// On Linux, the CPUfreq subsystem exposes CPU information as files on the // On Linux, the CPUfreq subsystem exposes CPU information as files on the
...@@ -223,10 +224,11 @@ bool CpuScalingEnabled(int num_cpus) { ...@@ -223,10 +224,11 @@ bool CpuScalingEnabled(int num_cpus) {
for (int cpu = 0; cpu < num_cpus; ++cpu) { for (int cpu = 0; cpu < num_cpus; ++cpu) {
std::string governor_file = std::string governor_file =
StrCat("/sys/devices/system/cpu/cpu", cpu, "/cpufreq/scaling_governor"); StrCat("/sys/devices/system/cpu/cpu", cpu, "/cpufreq/scaling_governor");
if (ReadFromFile(governor_file, &res) && res != "performance") return true; if (ReadFromFile(governor_file, &res) && res != "performance") return CPUInfo::Scaling::ENABLED;
} }
return CPUInfo::Scaling::DISABLED;
#endif #endif
return false; return CPUInfo::Scaling::UNKNOWN;
} }
int CountSetBitsInCPUMap(std::string Val) { int CountSetBitsInCPUMap(std::string Val) {
...@@ -695,7 +697,7 @@ CPUInfo::CPUInfo() ...@@ -695,7 +697,7 @@ CPUInfo::CPUInfo()
: num_cpus(GetNumCPUs()), : num_cpus(GetNumCPUs()),
cycles_per_second(GetCPUCyclesPerSecond()), cycles_per_second(GetCPUCyclesPerSecond()),
caches(GetCacheSizes()), caches(GetCacheSizes()),
scaling_enabled(CpuScalingEnabled(num_cpus)), scaling(CpuScaling(num_cpus)),
load_avg(GetLoadAvg()) {} load_avg(GetLoadAvg()) {}
......
...@@ -28,8 +28,7 @@ static int AddContextCases() { ...@@ -28,8 +28,7 @@ static int AddContextCases() {
MR_Next}, MR_Next},
{"\"num_cpus\": %int,$", MR_Next}, {"\"num_cpus\": %int,$", MR_Next},
{"\"mhz_per_cpu\": %float,$", MR_Next}, {"\"mhz_per_cpu\": %float,$", MR_Next},
{"\"cpu_scaling_enabled\": ", MR_Next}, {"\"caches\": \\[$", MR_Default}});
{"\"caches\": \\[$", MR_Next}});
auto const& Info = benchmark::CPUInfo::Get(); auto const& Info = benchmark::CPUInfo::Get();
auto const& Caches = Info.caches; auto const& Caches = Info.caches;
if (!Caches.empty()) { if (!Caches.empty()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment