mirror of https://github.com/google/benchmark.git
* 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
This commit is contained in:
parent
37177a84b7
commit
9901011880
|
@ -176,6 +176,7 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
|
|||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#if defined(BENCHMARK_HAS_CXX11)
|
||||
|
@ -1294,10 +1295,16 @@ struct CPUInfo {
|
|||
int num_sharing;
|
||||
};
|
||||
|
||||
enum Scaling {
|
||||
UNKNOWN,
|
||||
ENABLED,
|
||||
DISABLED
|
||||
};
|
||||
|
||||
int num_cpus;
|
||||
double cycles_per_second;
|
||||
std::vector<CacheInfo> caches;
|
||||
bool scaling_enabled;
|
||||
Scaling scaling;
|
||||
std::vector<double> load_avg;
|
||||
|
||||
static const CPUInfo& Get();
|
||||
|
|
|
@ -122,8 +122,10 @@ bool JSONReporter::ReportContext(const Context& context) {
|
|||
<< FormatKV("mhz_per_cpu",
|
||||
RoundDouble(info.cycles_per_second / 1000000.0))
|
||||
<< ",\n";
|
||||
out << indent << FormatKV("cpu_scaling_enabled", info.scaling_enabled)
|
||||
<< ",\n";
|
||||
if (CPUInfo::Scaling::UNKNOWN != info.scaling) {
|
||||
out << indent << FormatKV("cpu_scaling_enabled", info.scaling == CPUInfo::Scaling::ENABLED ? true : false)
|
||||
<< ",\n";
|
||||
}
|
||||
|
||||
out << indent << "\"caches\": [\n";
|
||||
indent = std::string(6, ' ');
|
||||
|
|
|
@ -64,7 +64,7 @@ void BenchmarkReporter::PrintBasicContext(std::ostream *out,
|
|||
Out << "\n";
|
||||
}
|
||||
|
||||
if (info.scaling_enabled) {
|
||||
if (CPUInfo::Scaling::ENABLED == info.scaling) {
|
||||
Out << "***WARNING*** CPU scaling is enabled, the benchmark "
|
||||
"real time measurements may be noisy and will incur extra "
|
||||
"overhead.\n";
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <locale>
|
||||
#include <utility>
|
||||
|
||||
#include "check.h"
|
||||
#include "cycleclock.h"
|
||||
|
@ -209,11 +210,11 @@ bool ReadFromFile(std::string const& fname, ArgT* arg) {
|
|||
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.
|
||||
if (num_cpus <= 0) return false;
|
||||
if (num_cpus <= 0) return CPUInfo::Scaling::UNKNOWN;
|
||||
#ifdef BENCHMARK_OS_QNX
|
||||
return false;
|
||||
return CPUInfo::Scaling::UNKNOWN;
|
||||
#endif
|
||||
#ifndef BENCHMARK_OS_WINDOWS
|
||||
// On Linux, the CPUfreq subsystem exposes CPU information as files on the
|
||||
|
@ -223,10 +224,11 @@ bool CpuScalingEnabled(int num_cpus) {
|
|||
for (int cpu = 0; cpu < num_cpus; ++cpu) {
|
||||
std::string governor_file =
|
||||
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
|
||||
return false;
|
||||
return CPUInfo::Scaling::UNKNOWN;
|
||||
}
|
||||
|
||||
int CountSetBitsInCPUMap(std::string Val) {
|
||||
|
@ -695,7 +697,7 @@ CPUInfo::CPUInfo()
|
|||
: num_cpus(GetNumCPUs()),
|
||||
cycles_per_second(GetCPUCyclesPerSecond()),
|
||||
caches(GetCacheSizes()),
|
||||
scaling_enabled(CpuScalingEnabled(num_cpus)),
|
||||
scaling(CpuScaling(num_cpus)),
|
||||
load_avg(GetLoadAvg()) {}
|
||||
|
||||
|
||||
|
|
|
@ -28,8 +28,7 @@ static int AddContextCases() {
|
|||
MR_Next},
|
||||
{"\"num_cpus\": %int,$", MR_Next},
|
||||
{"\"mhz_per_cpu\": %float,$", MR_Next},
|
||||
{"\"cpu_scaling_enabled\": ", MR_Next},
|
||||
{"\"caches\": \\[$", MR_Next}});
|
||||
{"\"caches\": \\[$", MR_Default}});
|
||||
auto const& Info = benchmark::CPUInfo::Get();
|
||||
auto const& Caches = Info.caches;
|
||||
if (!Caches.empty()) {
|
||||
|
|
Loading…
Reference in New Issue