Skip to content

Commit 5c9a54f

Browse files
committed
review notes
1 parent 0b2b11e commit 5c9a54f

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

include/benchmark/benchmark.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ class Benchmark {
875875
Benchmark* DisplayAggregatesOnly(bool value = true);
876876

877877
// By default, the CPU time is measured only for the main thread, which may
878-
// be unrepresentable if the benchmark uses threads internally. If called,
878+
// be unrepresentative if the benchmark uses threads internally. If called,
879879
// the total CPU time spent by all the threads will be measured instead.
880880
// By default, the only the main thread CPU time will be measured.
881881
Benchmark* MeasureProcessCPUTime();

src/benchmark_runner.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ BenchmarkReporter::Run CreateRunReport(
111111
// Adds the stats collected for the thread into *total.
112112
void RunInThread(const BenchmarkInstance* b, size_t iters, int thread_id,
113113
ThreadManager* manager) {
114-
internal::ThreadTimer timer(b->measure_process_cpu_time);
114+
internal::ThreadTimer timer(
115+
b->measure_process_cpu_time
116+
? internal::ThreadTimer::CreateProcessCpuTime()
117+
: internal::ThreadTimer::Create());
115118
State st = b->Run(iters, thread_id, &timer, manager);
116119
CHECK(st.iterations() >= st.max_iterations)
117120
<< "Benchmark returned before State::KeepRunning() returned false!";

src/thread_timer.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@ namespace benchmark {
88
namespace internal {
99

1010
class ThreadTimer {
11-
public:
12-
ThreadTimer(bool measure_process_cpu_time_)
11+
explicit ThreadTimer(bool measure_process_cpu_time_)
1312
: measure_process_cpu_time(measure_process_cpu_time_) {}
1413

14+
public:
15+
static ThreadTimer Create() {
16+
return ThreadTimer(/*measure_process_cpu_time_=*/false);
17+
}
18+
static ThreadTimer CreateProcessCpuTime() {
19+
return ThreadTimer(/*measure_process_cpu_time_=*/true);
20+
}
21+
1522
// Called by each thread
1623
void StartTimer() {
1724
running_ = true;

0 commit comments

Comments
 (0)