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