Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: src/base/platform/elapsed-timer.h

Issue 2511093002: [counters] RuntimeStats: fix wrong bookkeeping when dynamically changing counters. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/counters.h » ('j') | src/counters.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project 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 #ifndef V8_BASE_PLATFORM_ELAPSED_TIMER_H_ 5 #ifndef V8_BASE_PLATFORM_ELAPSED_TIMER_H_
6 #define V8_BASE_PLATFORM_ELAPSED_TIMER_H_ 6 #define V8_BASE_PLATFORM_ELAPSED_TIMER_H_
7 7
8 #include "src/base/logging.h" 8 #include "src/base/logging.h"
9 #include "src/base/platform/time.h" 9 #include "src/base/platform/time.h"
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 // Returns the time elapsed since the previous start. This method may only 65 // Returns the time elapsed since the previous start. This method may only
66 // be called on a previously started timer. 66 // be called on a previously started timer.
67 TimeDelta Elapsed() const { 67 TimeDelta Elapsed() const {
68 DCHECK(IsStarted()); 68 DCHECK(IsStarted());
69 TimeDelta elapsed = Now() - start_ticks_; 69 TimeDelta elapsed = Now() - start_ticks_;
70 DCHECK(elapsed.InMicroseconds() >= 0); 70 DCHECK(elapsed.InMicroseconds() >= 0);
71 return elapsed; 71 return elapsed;
72 } 72 }
73 73
74 // Move the start_ticks_ to adjust the current timer.
75 void AdjustBy(TimeDelta delta) {
76 DCHECK(IsStarted());
77 start_ticks_ += delta;
78 }
79
74 // Returns |true| if the specified |time_delta| has elapsed since the 80 // Returns |true| if the specified |time_delta| has elapsed since the
75 // previous start, or |false| if not. This method may only be called on 81 // previous start, or |false| if not. This method may only be called on
76 // a previously started timer. 82 // a previously started timer.
77 bool HasExpired(TimeDelta time_delta) const { 83 bool HasExpired(TimeDelta time_delta) const {
78 DCHECK(IsStarted()); 84 DCHECK(IsStarted());
79 return Elapsed() >= time_delta; 85 return Elapsed() >= time_delta;
80 } 86 }
81 87
82 private: 88 private:
83 static V8_INLINE TimeTicks Now() { 89 static V8_INLINE TimeTicks Now() {
84 TimeTicks now = TimeTicks::HighResolutionNow(); 90 TimeTicks now = TimeTicks::HighResolutionNow();
85 DCHECK(!now.IsNull()); 91 DCHECK(!now.IsNull());
86 return now; 92 return now;
87 } 93 }
88 94
89 TimeTicks start_ticks_; 95 TimeTicks start_ticks_;
90 #ifdef DEBUG 96 #ifdef DEBUG
91 bool started_; 97 bool started_;
92 #endif 98 #endif
93 }; 99 };
94 100
95 } // namespace base 101 } // namespace base
96 } // namespace v8 102 } // namespace v8
97 103
98 #endif // V8_BASE_PLATFORM_ELAPSED_TIMER_H_ 104 #endif // V8_BASE_PLATFORM_ELAPSED_TIMER_H_
OLDNEW
« no previous file with comments | « no previous file | src/counters.h » ('j') | src/counters.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698