Index: src/base/platform/elapsed-timer.h |
diff --git a/src/base/platform/elapsed-timer.h b/src/base/platform/elapsed-timer.h |
index f9a9ef43619c2650caf94bfdeefa71f969366db6..fc332d5a5a61fbfb2f3c4cf8eaf59c5d491d7f1a 100644 |
--- a/src/base/platform/elapsed-timer.h |
+++ b/src/base/platform/elapsed-timer.h |
@@ -20,9 +20,10 @@ class ElapsedTimer final { |
// Starts this timer. Once started a timer can be checked with |
// |Elapsed()| or |HasExpired()|, and may be restarted using |Restart()|. |
// This method must not be called on an already started timer. |
- void Start() { |
+ void Start() { Start(Now()); } |
+ void Start(TimeTicks now) { |
DCHECK(!IsStarted()); |
- start_ticks_ = Now(); |
+ start_ticks_ = now; |
#ifdef DEBUG |
started_ = true; |
#endif |
@@ -52,21 +53,23 @@ class ElapsedTimer final { |
// and then starting the timer again, but does so in one single operation, |
// avoiding the need to obtain the clock value twice. It may only be called |
// on a previously started timer. |
- TimeDelta Restart() { |
+ TimeDelta Restart() { return Restart(Now()); } |
+ |
+ TimeDelta Restart(TimeTicks now) { |
DCHECK(IsStarted()); |
- TimeTicks ticks = Now(); |
- TimeDelta elapsed = ticks - start_ticks_; |
+ TimeDelta elapsed = now - start_ticks_; |
DCHECK(elapsed.InMicroseconds() >= 0); |
- start_ticks_ = ticks; |
+ start_ticks_ = now; |
DCHECK(IsStarted()); |
return elapsed; |
} |
// Returns the time elapsed since the previous start. This method may only |
// be called on a previously started timer. |
- TimeDelta Elapsed() const { |
+ TimeDelta Elapsed() const { return Elapsed(Now()); } |
+ TimeDelta Elapsed(TimeTicks now) const { |
DCHECK(IsStarted()); |
- TimeDelta elapsed = Now() - start_ticks_; |
+ TimeDelta elapsed = now - start_ticks_; |
DCHECK(elapsed.InMicroseconds() >= 0); |
return elapsed; |
} |
@@ -79,13 +82,13 @@ class ElapsedTimer final { |
return Elapsed() >= time_delta; |
} |
- private: |
static V8_INLINE TimeTicks Now() { |
TimeTicks now = TimeTicks::HighResolutionNow(); |
DCHECK(!now.IsNull()); |
return now; |
} |
+ private: |
TimeTicks start_ticks_; |
#ifdef DEBUG |
bool started_; |