Skip to content

Commit ce9c997

Browse files
committed
Ensure CPU sampling is happening always.
We weren't actually sampling at all when "short output" was enabled.
1 parent 369d3d6 commit ce9c997

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/apib_main.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ static void waitAndReport(const apib::ThreadList &threads, int duration,
257257
}
258258

259259
sleep(toSleep);
260-
if (!ShortOutput) {
260+
if (ShortOutput) {
261+
apib::SampleCPU();
262+
} else {
261263
ReportInterval(std::cout, threads, duration, warmup);
262264
}
263265
durationLeft -= toSleep;

src/apib_reporting.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ void RecordStart(bool startReporting, const ThreadList& threads) {
226226
}
227227

228228
void RecordStop(const ThreadList& threads) {
229+
SampleCPU();
229230
clientMem = cpu_GetMemoryUsage();
230-
231231
if (remoteCpuSocket != 0) {
232232
remoteMem = getRemoteStat(kMemCmd, &remoteCpuSocket);
233233
}
@@ -275,6 +275,19 @@ BenchmarkIntervalResults ReportIntervalResults(const ThreadList& threads) {
275275
return r;
276276
}
277277

278+
void SampleCPU() {
279+
if (remoteCpuSocket != 0) {
280+
const double remoteCpu = getRemoteStat(kCPUCmd, &remoteCpuSocket);
281+
remoteSamples.push_back(remoteCpu);
282+
}
283+
if (remote2CpuSocket != 0) {
284+
const double remote2Cpu = getRemoteStat(kCPUCmd, &remote2CpuSocket);
285+
remote2Samples.push_back(remote2Cpu);
286+
}
287+
const double cpu = cpu_GetInterval(&cpuUsage);
288+
clientSamples.push_back(cpu);
289+
}
290+
278291
void ReportInterval(std::ostream& out, const ThreadList& threads,
279292
int totalDuration, bool warmup) {
280293
double cpu = 0.0;

src/apib_reporting.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ extern void PrintFullResults(std::ostream& out);
103103
// Call ReportIntervalResults and print to a file
104104
extern void ReportInterval(std::ostream& out, const ThreadList& threads,
105105
int totalDuration, bool warmup);
106+
// If ReportInterval is not being called, call this instead to ensure
107+
// that the CPU samples are happening regularly so
108+
// that we get a good average.
109+
extern void SampleCPU();
106110
// Print a CSV header for the "short" reporting format
107111
extern void PrintReportingHeader(std::ostream& out);
108112

0 commit comments

Comments
 (0)