mirror of
https://github.com/google/benchmark.git
synced 2025-01-14 22:00:33 +08:00
Ignore the CPU time consumed when timing is paused.
Conflicts: src/benchmark.cc
This commit is contained in:
parent
e5a431998d
commit
ec1e09f939
@ -276,8 +276,10 @@ class State {
|
||||
double start_time_;
|
||||
int64_t stop_time_micros_;
|
||||
|
||||
double start_pause_;
|
||||
double pause_time_;
|
||||
double start_pause_cpu_;
|
||||
double pause_cpu_time_;
|
||||
double start_pause_real_;
|
||||
double pause_real_time_;
|
||||
|
||||
// Total number of iterations for all finished runs.
|
||||
int64_t total_iterations_;
|
||||
|
@ -940,8 +940,10 @@ State::State(FastClock* clock, SharedState* s, int t)
|
||||
start_cpu_(0.0),
|
||||
start_time_(0.0),
|
||||
stop_time_micros_(0.0),
|
||||
start_pause_(0.0),
|
||||
pause_time_(0.0),
|
||||
start_pause_cpu_(0.0),
|
||||
pause_cpu_time_(0.0),
|
||||
start_pause_real_(0.0),
|
||||
pause_real_time_(0.0),
|
||||
total_iterations_(0),
|
||||
interval_micros_(static_cast<int64_t>(kNumMicrosPerSecond *
|
||||
FLAGS_benchmark_min_time /
|
||||
@ -955,7 +957,7 @@ State::State(FastClock* clock, SharedState* s, int t)
|
||||
bool State::KeepRunning() {
|
||||
// Fast path
|
||||
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_;
|
||||
return true;
|
||||
@ -999,9 +1001,15 @@ bool State::KeepRunning() {
|
||||
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) {
|
||||
CHECK_EQ(STATE_STOPPED, state_);
|
||||
@ -1078,7 +1086,8 @@ void State::NewInterval() {
|
||||
<< "\n";
|
||||
#endif
|
||||
iterations_ = 0;
|
||||
pause_time_ = 0;
|
||||
pause_cpu_time_ = 0;
|
||||
pause_real_time_ = 0;
|
||||
start_cpu_ = MyCPUUsage() + ChildrenCPUUsage();
|
||||
start_time_ = walltime::Now();
|
||||
} else {
|
||||
@ -1110,11 +1119,12 @@ bool State::FinishInterval() {
|
||||
|
||||
const double accumulated_time = walltime::Now() - start_time_;
|
||||
const double total_overhead = overhead * iterations_;
|
||||
CHECK_LT(pause_time_, accumulated_time);
|
||||
CHECK_LT(pause_time_ + total_overhead, accumulated_time);
|
||||
CHECK_LT(pause_real_time_, accumulated_time);
|
||||
CHECK_LT(pause_real_time_ + total_overhead, accumulated_time);
|
||||
data.real_accumulated_time =
|
||||
accumulated_time - (pause_time_ + total_overhead);
|
||||
data.cpu_accumulated_time = (MyCPUUsage() + ChildrenCPUUsage()) - start_cpu_;
|
||||
accumulated_time - (pause_real_time_ + total_overhead);
|
||||
data.cpu_accumulated_time = (MyCPUUsage() + ChildrenCPUUsage()) -
|
||||
(pause_cpu_time_ + start_cpu_);
|
||||
total_iterations_ += iterations_;
|
||||
|
||||
bool keep_going = false;
|
||||
|
Loading…
Reference in New Issue
Block a user