GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / cc / debug / lap_timer.cc
blob10d26f94f4de514b0094b464efeec0dddf7a37f1
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/debug/lap_timer.h"
7 #include "base/logging.h"
9 namespace cc {
11 namespace {
13 base::TimeTicks Now() {
14 return base::TimeTicks::IsThreadNowSupported() ? base::TimeTicks::ThreadNow()
15 : base::TimeTicks::Now();
18 } // namespace
20 LapTimer::LapTimer(int warmup_laps,
21 base::TimeDelta time_limit,
22 int check_interval)
23 : warmup_laps_(warmup_laps),
24 remaining_warmups_(0),
25 remaining_no_check_laps_(0),
26 time_limit_(time_limit),
27 check_interval_(check_interval) {
28 DCHECK_GT(check_interval, 0);
29 Reset();
32 void LapTimer::Reset() {
33 accumulator_ = base::TimeDelta();
34 num_laps_ = 0;
35 remaining_warmups_ = warmup_laps_;
36 remaining_no_check_laps_ = check_interval_;
37 Start();
40 void LapTimer::Start() {
41 start_time_ = Now();
44 bool LapTimer::IsWarmedUp() { return remaining_warmups_ <= 0; }
46 void LapTimer::NextLap() {
47 if (!IsWarmedUp()) {
48 --remaining_warmups_;
49 if (IsWarmedUp()) {
50 Start();
52 return;
54 ++num_laps_;
55 --remaining_no_check_laps_;
56 if (!remaining_no_check_laps_) {
57 base::TimeTicks now = Now();
58 accumulator_ += now - start_time_;
59 start_time_ = now;
60 remaining_no_check_laps_ = check_interval_;
64 bool LapTimer::HasTimeLimitExpired() { return accumulator_ >= time_limit_; }
66 bool LapTimer::HasTimedAllLaps() { return !(num_laps_ % check_interval_); }
68 float LapTimer::MsPerLap() {
69 DCHECK(HasTimedAllLaps());
70 return accumulator_.InMillisecondsF() / num_laps_;
73 float LapTimer::LapsPerSecond() {
74 DCHECK(HasTimedAllLaps());
75 return num_laps_ / accumulator_.InSecondsF();
78 int LapTimer::NumLaps() { return num_laps_; }
80 } // namespace cc