OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/debug/lap_timer.h" | 5 #include "cc/debug/lap_timer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace cc { | 9 namespace cc { |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 base::TimeTicks Now() { | 13 base::TimeDelta Now() { |
14 return base::TimeTicks::IsThreadNowSupported() ? base::TimeTicks::ThreadNow() | 14 return base::ThreadTicks::IsSupported() |
15 : base::TimeTicks::Now(); | 15 ? base::ThreadTicks::Now() - base::ThreadTicks() |
| 16 : base::TimeTicks::Now() - base::TimeTicks(); |
16 } | 17 } |
17 | 18 |
18 } // namespace | 19 } // namespace |
19 | 20 |
20 LapTimer::LapTimer(int warmup_laps, | 21 LapTimer::LapTimer(int warmup_laps, |
21 base::TimeDelta time_limit, | 22 base::TimeDelta time_limit, |
22 int check_interval) | 23 int check_interval) |
23 : warmup_laps_(warmup_laps), | 24 : warmup_laps_(warmup_laps), |
24 remaining_warmups_(0), | 25 remaining_warmups_(0), |
25 remaining_no_check_laps_(0), | 26 remaining_no_check_laps_(0), |
(...skipping 21 matching lines...) Expand all Loading... |
47 if (!IsWarmedUp()) { | 48 if (!IsWarmedUp()) { |
48 --remaining_warmups_; | 49 --remaining_warmups_; |
49 if (IsWarmedUp()) { | 50 if (IsWarmedUp()) { |
50 Start(); | 51 Start(); |
51 } | 52 } |
52 return; | 53 return; |
53 } | 54 } |
54 ++num_laps_; | 55 ++num_laps_; |
55 --remaining_no_check_laps_; | 56 --remaining_no_check_laps_; |
56 if (!remaining_no_check_laps_) { | 57 if (!remaining_no_check_laps_) { |
57 base::TimeTicks now = Now(); | 58 base::TimeDelta now = Now(); |
58 accumulator_ += now - start_time_; | 59 accumulator_ += now - start_time_; |
59 start_time_ = now; | 60 start_time_ = now; |
60 remaining_no_check_laps_ = check_interval_; | 61 remaining_no_check_laps_ = check_interval_; |
61 } | 62 } |
62 } | 63 } |
63 | 64 |
64 bool LapTimer::HasTimeLimitExpired() { return accumulator_ >= time_limit_; } | 65 bool LapTimer::HasTimeLimitExpired() { return accumulator_ >= time_limit_; } |
65 | 66 |
66 bool LapTimer::HasTimedAllLaps() { return !(num_laps_ % check_interval_); } | 67 bool LapTimer::HasTimedAllLaps() { return !(num_laps_ % check_interval_); } |
67 | 68 |
68 float LapTimer::MsPerLap() { | 69 float LapTimer::MsPerLap() { |
69 DCHECK(HasTimedAllLaps()); | 70 DCHECK(HasTimedAllLaps()); |
70 return accumulator_.InMillisecondsF() / num_laps_; | 71 return accumulator_.InMillisecondsF() / num_laps_; |
71 } | 72 } |
72 | 73 |
73 float LapTimer::LapsPerSecond() { | 74 float LapTimer::LapsPerSecond() { |
74 DCHECK(HasTimedAllLaps()); | 75 DCHECK(HasTimedAllLaps()); |
75 return num_laps_ / accumulator_.InSecondsF(); | 76 return num_laps_ / accumulator_.InSecondsF(); |
76 } | 77 } |
77 | 78 |
78 int LapTimer::NumLaps() { return num_laps_; } | 79 int LapTimer::NumLaps() { return num_laps_; } |
79 | 80 |
80 } // namespace cc | 81 } // namespace cc |
OLD | NEW |