Commit ec1e09f9 by pleroy

Ignore the CPU time consumed when timing is paused.

Conflicts: src/benchmark.cc
parent e5a43199
...@@ -276,8 +276,10 @@ class State { ...@@ -276,8 +276,10 @@ class State {
double start_time_; double start_time_;
int64_t stop_time_micros_; int64_t stop_time_micros_;
double start_pause_; double start_pause_cpu_;
double pause_time_; double pause_cpu_time_;
double start_pause_real_;
double pause_real_time_;
// Total number of iterations for all finished runs. // Total number of iterations for all finished runs.
int64_t total_iterations_; int64_t total_iterations_;
......
...@@ -940,8 +940,10 @@ State::State(FastClock* clock, SharedState* s, int t) ...@@ -940,8 +940,10 @@ State::State(FastClock* clock, SharedState* s, int t)
start_cpu_(0.0), start_cpu_(0.0),
start_time_(0.0), start_time_(0.0),
stop_time_micros_(0.0), stop_time_micros_(0.0),
start_pause_(0.0), start_pause_cpu_(0.0),
pause_time_(0.0), pause_cpu_time_(0.0),
start_pause_real_(0.0),
pause_real_time_(0.0),
total_iterations_(0), total_iterations_(0),
interval_micros_(static_cast<int64_t>(kNumMicrosPerSecond * interval_micros_(static_cast<int64_t>(kNumMicrosPerSecond *
FLAGS_benchmark_min_time / FLAGS_benchmark_min_time /
...@@ -955,7 +957,7 @@ State::State(FastClock* clock, SharedState* s, int t) ...@@ -955,7 +957,7 @@ State::State(FastClock* clock, SharedState* s, int t)
bool State::KeepRunning() { bool State::KeepRunning() {
// Fast path // Fast path
if ((FLAGS_benchmark_iterations == 0 && if ((FLAGS_benchmark_iterations == 0 &&
!clock_->HasReached(stop_time_micros_ + pause_time_)) || !clock_->HasReached(stop_time_micros_ + pause_real_time_)) ||
iterations_ < FLAGS_benchmark_iterations) { iterations_ < FLAGS_benchmark_iterations) {
++iterations_; ++iterations_;
return true; return true;
...@@ -999,9 +1001,15 @@ bool State::KeepRunning() { ...@@ -999,9 +1001,15 @@ bool State::KeepRunning() {
return ret; return ret;
} }
void State::PauseTiming() { start_pause_ = walltime::Now(); } void State::PauseTiming() {
start_pause_cpu_ = MyCPUUsage() + ChildrenCPUUsage();
start_pause_real_ = walltime::Now();
}
void State::ResumeTiming() { pause_time_ += walltime::Now() - start_pause_; } void State::ResumeTiming() {
pause_cpu_time_ += MyCPUUsage() + ChildrenCPUUsage() - start_pause_cpu_;
pause_real_time_ += walltime::Now() - start_pause_real_;
}
void State::SetBytesProcessed(int64_t bytes) { void State::SetBytesProcessed(int64_t bytes) {
CHECK_EQ(STATE_STOPPED, state_); CHECK_EQ(STATE_STOPPED, state_);
...@@ -1078,7 +1086,8 @@ void State::NewInterval() { ...@@ -1078,7 +1086,8 @@ void State::NewInterval() {
<< "\n"; << "\n";
#endif #endif
iterations_ = 0; iterations_ = 0;
pause_time_ = 0; pause_cpu_time_ = 0;
pause_real_time_ = 0;
start_cpu_ = MyCPUUsage() + ChildrenCPUUsage(); start_cpu_ = MyCPUUsage() + ChildrenCPUUsage();
start_time_ = walltime::Now(); start_time_ = walltime::Now();
} else { } else {
...@@ -1110,11 +1119,12 @@ bool State::FinishInterval() { ...@@ -1110,11 +1119,12 @@ bool State::FinishInterval() {
const double accumulated_time = walltime::Now() - start_time_; const double accumulated_time = walltime::Now() - start_time_;
const double total_overhead = overhead * iterations_; const double total_overhead = overhead * iterations_;
CHECK_LT(pause_time_, accumulated_time); CHECK_LT(pause_real_time_, accumulated_time);
CHECK_LT(pause_time_ + total_overhead, accumulated_time); CHECK_LT(pause_real_time_ + total_overhead, accumulated_time);
data.real_accumulated_time = data.real_accumulated_time =
accumulated_time - (pause_time_ + total_overhead); accumulated_time - (pause_real_time_ + total_overhead);
data.cpu_accumulated_time = (MyCPUUsage() + ChildrenCPUUsage()) - start_cpu_; data.cpu_accumulated_time = (MyCPUUsage() + ChildrenCPUUsage()) -
(pause_cpu_time_ + start_cpu_);
total_iterations_ += iterations_; total_iterations_ += iterations_;
bool keep_going = false; bool keep_going = false;
......
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