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 // Returns the offset from the origin from the ThreadTicks time source. |
14 return base::TimeTicks::IsThreadNowSupported() ? base::TimeTicks::ThreadNow() | 14 // TimeTicks is used as a fallback if ThreadTicks is not available on the |
15 : base::TimeTicks::Now(); | 15 // current platform. |
| 16 base::TimeDelta Now() { |
| 17 return base::ThreadTicks::IsSupported() |
| 18 ? base::ThreadTicks::Now() - base::ThreadTicks() |
| 19 : base::TimeTicks::Now() - base::TimeTicks(); |
16 } | 20 } |
17 | 21 |
18 // Default values. | 22 // Default values. |
19 static const int kTimeLimitMillis = 3000; | 23 static const int kTimeLimitMillis = 3000; |
20 static const int kWarmupRuns = 5; | 24 static const int kWarmupRuns = 5; |
21 static const int kTimeCheckInterval = 10; | 25 static const int kTimeCheckInterval = 10; |
22 | 26 |
23 } // namespace | 27 } // namespace |
24 | 28 |
25 LapTimer::LapTimer(int warmup_laps, | 29 LapTimer::LapTimer(int warmup_laps, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 if (!IsWarmedUp()) { | 62 if (!IsWarmedUp()) { |
59 --remaining_warmups_; | 63 --remaining_warmups_; |
60 if (IsWarmedUp()) { | 64 if (IsWarmedUp()) { |
61 Start(); | 65 Start(); |
62 } | 66 } |
63 return; | 67 return; |
64 } | 68 } |
65 ++num_laps_; | 69 ++num_laps_; |
66 --remaining_no_check_laps_; | 70 --remaining_no_check_laps_; |
67 if (!remaining_no_check_laps_) { | 71 if (!remaining_no_check_laps_) { |
68 base::TimeTicks now = Now(); | 72 base::TimeDelta now = Now(); |
69 accumulator_ += now - start_time_; | 73 accumulator_ += now - start_time_; |
70 start_time_ = now; | 74 start_time_ = now; |
71 remaining_no_check_laps_ = check_interval_; | 75 remaining_no_check_laps_ = check_interval_; |
72 } | 76 } |
73 } | 77 } |
74 | 78 |
75 bool LapTimer::HasTimeLimitExpired() { return accumulator_ >= time_limit_; } | 79 bool LapTimer::HasTimeLimitExpired() { return accumulator_ >= time_limit_; } |
76 | 80 |
77 bool LapTimer::HasTimedAllLaps() { return !(num_laps_ % check_interval_); } | 81 bool LapTimer::HasTimedAllLaps() { return !(num_laps_ % check_interval_); } |
78 | 82 |
79 float LapTimer::MsPerLap() { | 83 float LapTimer::MsPerLap() { |
80 DCHECK(HasTimedAllLaps()); | 84 DCHECK(HasTimedAllLaps()); |
81 return accumulator_.InMillisecondsF() / num_laps_; | 85 return accumulator_.InMillisecondsF() / num_laps_; |
82 } | 86 } |
83 | 87 |
84 float LapTimer::LapsPerSecond() { | 88 float LapTimer::LapsPerSecond() { |
85 DCHECK(HasTimedAllLaps()); | 89 DCHECK(HasTimedAllLaps()); |
86 return num_laps_ / accumulator_.InSecondsF(); | 90 return num_laps_ / accumulator_.InSecondsF(); |
87 } | 91 } |
88 | 92 |
89 int LapTimer::NumLaps() { return num_laps_; } | 93 int LapTimer::NumLaps() { return num_laps_; } |
90 | 94 |
91 } // namespace cc | 95 } // namespace cc |
OLD | NEW |