We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents bb15a4e + b5082bb commit b171791Copy full SHA for b171791
AUTHORS
@@ -36,6 +36,7 @@ Maxim Vafin <maxvafin@gmail.com>
36
MongoDB Inc.
37
Nick Hutchinson <nshutchinson@gmail.com>
38
Oleksandr Sochka <sasha.sochka@gmail.com>
39
+Ori Livneh <ori.livneh@gmail.com>
40
Paul Redmond <paul.redmond@gmail.com>
41
Radoslav Yovchev <radoslav.tm@gmail.com>
42
Roman Lebedev <lebedev.ri@gmail.com>
CONTRIBUTORS
@@ -50,6 +50,7 @@ Matt Clarkson <mattyclarkson@gmail.com>
50
Maxim Vafin <maxvafin@gmail.com>
51
52
53
54
Pascal Leroy <phl@google.com>
55
56
Pierre Phaneuf <pphaneuf@google.com>
include/benchmark/benchmark.h
@@ -1284,6 +1284,7 @@ struct CPUInfo {
1284
double cycles_per_second;
1285
std::vector<CacheInfo> caches;
1286
bool scaling_enabled;
1287
+ std::vector<double> load_avg;
1288
1289
static const CPUInfo& Get();
1290
src/json_reporter.cc
@@ -116,6 +116,12 @@ bool JSONReporter::ReportContext(const Context& context) {
116
}
117
indent = std::string(4, ' ');
118
out << indent << "],\n";
119
+ out << indent << "\"load_avg\": [";
120
+ for (auto it = info.load_avg.begin(); it != info.load_avg.end();) {
121
+ out << *it++;
122
+ if (it != info.load_avg.end()) out << ",";
123
+ }
124
+ out << "],\n";
125
126
#if defined(NDEBUG)
127
const char build_type[] = "release";
src/reporter.cc
@@ -22,6 +22,7 @@
22
#include <vector>
23
24
#include "check.h"
25
+#include "string_util.h"
26
27
namespace benchmark {
28
@@ -54,6 +55,14 @@ void BenchmarkReporter::PrintBasicContext(std::ostream *out,
Out << "\n";
57
58
+ if (!info.load_avg.empty()) {
59
+ Out << "Load Average: ";
60
+ for (auto It = info.load_avg.begin(); It != info.load_avg.end();) {
61
+ Out << StrFormat("%.2f", *It++);
62
+ if (It != info.load_avg.end()) Out << ", ";
63
64
+ Out << "\n";
65
66
67
if (info.scaling_enabled) {
68
Out << "***WARNING*** CPU scaling is enabled, the benchmark "
src/sysinfo.cc
@@ -577,6 +577,24 @@ double GetCPUCyclesPerSecond() {
577
return static_cast<double>(cycleclock::Now() - start_ticks);
578
579
580
+std::vector<double> GetLoadAvg() {
581
+#if defined BENCHMARK_OS_FREEBSD || defined(BENCHMARK_OS_LINUX) || \
582
+ defined BENCHMARK_OS_MACOSX || defined BENCHMARK_OS_NETBSD || \
583
+ defined BENCHMARK_OS_OPENBSD
584
+ constexpr int kMaxSamples = 3;
585
+ std::vector<double> res(kMaxSamples, 0.0);
586
+ const int nelem = getloadavg(res.data(), kMaxSamples);
587
+ if (nelem < 1) {
588
+ res.clear();
589
+ } else {
590
+ res.resize(nelem);
591
592
+ return res;
593
+#else
594
+ return {};
595
+#endif
596
+}
597
+
598
} // end namespace
599
600
const CPUInfo& CPUInfo::Get() {
@@ -588,6 +606,7 @@ CPUInfo::CPUInfo()
606
: num_cpus(GetNumCPUs()),
607
cycles_per_second(GetCPUCyclesPerSecond()),
608
caches(GetCacheSizes()),
- scaling_enabled(CpuScalingEnabled(num_cpus)) {}
609
+ scaling_enabled(CpuScalingEnabled(num_cpus)),
610
+ load_avg(GetLoadAvg()) {}
611
612
} // end namespace benchmark
test/reporter_output_test.cc
@@ -29,7 +29,8 @@ static int AddContextCases() {
29
{"\"mhz_per_cpu\": %float,$", MR_Next},
30
{"\"cpu_scaling_enabled\": ", MR_Next},
31
{"\"caches\": \\[$", MR_Next}});
32
- auto const& Caches = benchmark::CPUInfo::Get().caches;
+ auto const& Info = benchmark::CPUInfo::Get();
33
+ auto const& Caches = Info.caches;
34
if (!Caches.empty()) {
35
AddCases(TC_ConsoleErr, {{"CPU Caches:$", MR_Next}});
@@ -46,8 +47,13 @@ static int AddContextCases() {
46
47
{"\"num_sharing\": %int$", MR_Next},
48
{"}[,]{0,1}$", MR_Next}});
49
-
AddCases(TC_JSONOut, {{"],$"}});
+ auto const& LoadAvg = Info.load_avg;
+ if (!LoadAvg.empty()) {
+ AddCases(TC_ConsoleErr,
+ {{"Load Average: (%float, ){0,2}%float$", MR_Next}});
+ AddCases(TC_JSONOut, {{"\"load_avg\": \\[(%float,?){0,3}],$", MR_Next}});
return 0;
int dummy_register = AddContextCases();
0 commit comments