OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CC_DEBUG_LAP_TIMER_H_ | |
6 #define CC_DEBUG_LAP_TIMER_H_ | |
7 | |
8 #include "base/time/time.h" | |
9 | |
10 namespace cc { | |
11 | |
12 // LapTimer is used to calculate average times per "Lap" in perf tests. | |
13 // Current() reports the time since the last call to Start(). | |
14 // Store() adds the time since the last call to Start() to the accumulator, and | |
15 // resets the start time to now. Stored() returns the accumulated time. | |
16 // NextLap increments the lap counter, used in counting the per lap averages. | |
17 // If you initialize the LapTimer with a non zero warmup_laps, it will ignore | |
18 // the times for that many laps at the start. | |
19 // If you set the time_limit then you can use HasTimeLimitExpired() to see if | |
20 // the current accumulated time has crossed that threshold, with an optimization | |
21 // that it only tests this every check_interval laps. | |
22 class LapTimer { | |
23 public: | |
24 LapTimer(int warmup_laps, base::TimeDelta time_limit, int check_interval); | |
25 // Resets the timer back to it's starting state. | |
26 void Reset(); | |
27 // Sets the start point to now. | |
28 void Start(); | |
29 // Returns true if there are no more warmup laps to do. | |
30 bool IsWarmedUp(); | |
31 // Advance the lap counter and update the accumulated time. | |
32 // The accumulated time is only updated every check_interval laps. | |
33 // If accumulating then the start point will also be updated. | |
34 void NextLap(); | |
35 // Returns true if the stored time has exceeded the time limit specified. | |
36 // May cause a call to Store(). | |
37 bool HasTimeLimitExpired(); | |
38 // Returns true if all lap times have been timed. Only true every n'th | |
39 // lap, where n = check_interval. | |
40 bool HasTimedAllLaps(); | |
41 // The average milliseconds per lap. | |
42 float MsPerLap(); | |
43 // The number of laps per second. | |
44 float LapsPerSecond(); | |
45 // The number of laps recorded. | |
46 int NumLaps(); | |
47 | |
48 private: | |
49 base::TimeDelta start_time_; | |
50 base::TimeDelta accumulator_; | |
51 int num_laps_; | |
52 int warmup_laps_; | |
53 int remaining_warmups_; | |
54 int remaining_no_check_laps_; | |
55 base::TimeDelta time_limit_; | |
56 int check_interval_; | |
57 | |
58 DISALLOW_COPY_AND_ASSIGN(LapTimer); | |
59 }; | |
60 | |
61 } // namespace cc | |
62 | |
63 #endif // CC_DEBUG_LAP_TIMER_H_ | |
OLD | NEW |