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

Side by Side Diff: webrtc/system_wrappers/include/tick_util.h

Issue 1452843003: Several Tick counter improvements try #2." (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // Now in the time domain in us. 49 // Now in the time domain in us.
50 static int64_t MicrosecondTimestamp(); 50 static int64_t MicrosecondTimestamp();
51 51
52 // Returns the number of ticks in the tick domain. 52 // Returns the number of ticks in the tick domain.
53 int64_t Ticks() const; 53 int64_t Ticks() const;
54 54
55 static int64_t MillisecondsToTicks(const int64_t ms); 55 static int64_t MillisecondsToTicks(const int64_t ms);
56 56
57 static int64_t TicksToMilliseconds(const int64_t ticks); 57 static int64_t TicksToMilliseconds(const int64_t ticks);
58 58
59 static int64_t TicksToMicroseconds(const int64_t ticks);
60
59 // Returns a TickTime that is ticks later than the passed TickTime. 61 // Returns a TickTime that is ticks later than the passed TickTime.
60 friend TickTime operator+(const TickTime lhs, const int64_t ticks); 62 friend TickTime operator+(const TickTime lhs, const int64_t ticks);
61 TickTime& operator+=(const int64_t& ticks); 63 TickTime& operator+=(const int64_t& ticks);
62 64
63 // Returns a TickInterval that is the difference in ticks beween rhs and lhs. 65 // Returns a TickInterval that is the difference in ticks beween rhs and lhs.
64 friend TickInterval operator-(const TickTime& lhs, const TickTime& rhs); 66 friend TickInterval operator-(const TickTime& lhs, const TickTime& rhs);
65 67
66 // Call to engage the fake clock. This is useful for tests since relying on 68 // Call to engage the fake clock. This is useful for tests since relying on
67 // a real clock often makes the test flaky. 69 // a real clock often makes the test flaky.
68 static void UseFakeClock(int64_t start_millisecond); 70 static void UseFakeClock(int64_t start_millisecond);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 private: 107 private:
106 explicit TickInterval(int64_t interval); 108 explicit TickInterval(int64_t interval);
107 109
108 friend class TickTime; 110 friend class TickTime;
109 friend TickInterval operator-(const TickTime& lhs, const TickTime& rhs); 111 friend TickInterval operator-(const TickTime& lhs, const TickTime& rhs);
110 112
111 private: 113 private:
112 int64_t interval_; 114 int64_t interval_;
113 }; 115 };
114 116
117 inline int64_t TickInterval::Milliseconds() const {
118 return TickTime::TicksToMilliseconds(interval_);
119 }
120
121 inline int64_t TickInterval::Microseconds() const {
122 return TickTime::TicksToMicroseconds(interval_);
123 }
124
115 inline TickInterval operator+(const TickInterval& lhs, 125 inline TickInterval operator+(const TickInterval& lhs,
116 const TickInterval& rhs) { 126 const TickInterval& rhs) {
117 return TickInterval(lhs.interval_ + rhs.interval_); 127 return TickInterval(lhs.interval_ + rhs.interval_);
118 } 128 }
119 129
120 inline TickInterval operator-(const TickInterval& lhs, 130 inline TickInterval operator-(const TickInterval& lhs,
121 const TickInterval& rhs) { 131 const TickInterval& rhs) {
122 return TickInterval(lhs.interval_ - rhs.interval_); 132 return TickInterval(lhs.interval_ - rhs.interval_);
123 } 133 }
124 134
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 : ticks_(ticks) { 166 : ticks_(ticks) {
157 } 167 }
158 168
159 inline TickTime TickTime::Now() { 169 inline TickTime TickTime::Now() {
160 if (use_fake_clock_) 170 if (use_fake_clock_)
161 return TickTime(fake_ticks_); 171 return TickTime(fake_ticks_);
162 else 172 else
163 return TickTime(QueryOsForTicks()); 173 return TickTime(QueryOsForTicks());
164 } 174 }
165 175
166 inline int64_t TickTime::MillisecondTimestamp() {
167 int64_t ticks = TickTime::Now().Ticks();
168 #if _WIN32
169 #ifdef USE_QUERY_PERFORMANCE_COUNTER
170 LARGE_INTEGER qpfreq;
171 QueryPerformanceFrequency(&qpfreq);
172 return (ticks * 1000) / qpfreq.QuadPart;
173 #else
174 return ticks;
175 #endif
176 #elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC)
177 return ticks / 1000000LL;
178 #else
179 return ticks / 1000LL;
180 #endif
181 }
182
183 inline int64_t TickTime::MicrosecondTimestamp() {
184 int64_t ticks = TickTime::Now().Ticks();
185 #if _WIN32
186 #ifdef USE_QUERY_PERFORMANCE_COUNTER
187 LARGE_INTEGER qpfreq;
188 QueryPerformanceFrequency(&qpfreq);
189 return (ticks * 1000) / (qpfreq.QuadPart / 1000);
190 #else
191 return ticks * 1000LL;
192 #endif
193 #elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC)
194 return ticks / 1000LL;
195 #else
196 return ticks;
197 #endif
198 }
199
200 inline int64_t TickTime::Ticks() const { 176 inline int64_t TickTime::Ticks() const {
201 return ticks_; 177 return ticks_;
202 } 178 }
203 179
204 inline int64_t TickTime::MillisecondsToTicks(const int64_t ms) {
205 #if _WIN32
206 #ifdef USE_QUERY_PERFORMANCE_COUNTER
207 LARGE_INTEGER qpfreq;
208 QueryPerformanceFrequency(&qpfreq);
209 return (qpfreq.QuadPart * ms) / 1000;
210 #else
211 return ms;
212 #endif
213 #elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC)
214 return ms * 1000000LL;
215 #else
216 return ms * 1000LL;
217 #endif
218 }
219
220 inline int64_t TickTime::TicksToMilliseconds(const int64_t ticks) {
221 #if _WIN32
222 #ifdef USE_QUERY_PERFORMANCE_COUNTER
223 LARGE_INTEGER qpfreq;
224 QueryPerformanceFrequency(&qpfreq);
225 return (ticks * 1000) / qpfreq.QuadPart;
226 #else
227 return ticks;
228 #endif
229 #elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC)
230 return ticks / 1000000LL;
231 #else
232 return ticks / 1000LL;
233 #endif
234 }
235
236 inline TickTime& TickTime::operator+=(const int64_t& ticks) { 180 inline TickTime& TickTime::operator+=(const int64_t& ticks) {
237 ticks_ += ticks; 181 ticks_ += ticks;
238 return *this; 182 return *this;
239 } 183 }
240 184
241 inline TickInterval::TickInterval() : interval_(0) { 185 inline TickInterval::TickInterval() : interval_(0) {
242 } 186 }
243 187
244 inline TickInterval::TickInterval(const int64_t interval) 188 inline TickInterval::TickInterval(const int64_t interval)
245 : interval_(interval) { 189 : interval_(interval) {
246 } 190 }
247 191
248 inline int64_t TickInterval::Milliseconds() const {
249 #if _WIN32
250 #ifdef USE_QUERY_PERFORMANCE_COUNTER
251 LARGE_INTEGER qpfreq;
252 QueryPerformanceFrequency(&qpfreq);
253 return (interval_ * 1000) / qpfreq.QuadPart;
254 #else
255 // interval_ is in ms
256 return interval_;
257 #endif
258 #elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC)
259 // interval_ is in ns
260 return interval_ / 1000000;
261 #else
262 // interval_ is usecs
263 return interval_ / 1000;
264 #endif
265 }
266
267 inline int64_t TickInterval::Microseconds() const {
268 #if _WIN32
269 #ifdef USE_QUERY_PERFORMANCE_COUNTER
270 LARGE_INTEGER qpfreq;
271 QueryPerformanceFrequency(&qpfreq);
272 return (interval_ * 1000000) / qpfreq.QuadPart;
273 #else
274 // interval_ is in ms
275 return interval_ * 1000LL;
276 #endif
277 #elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC)
278 // interval_ is in ns
279 return interval_ / 1000;
280 #else
281 // interval_ is usecs
282 return interval_;
283 #endif
284 }
285
286 inline TickInterval& TickInterval::operator+=(const TickInterval& rhs) { 192 inline TickInterval& TickInterval::operator+=(const TickInterval& rhs) {
287 interval_ += rhs.interval_; 193 interval_ += rhs.interval_;
288 return *this; 194 return *this;
289 } 195 }
290 196
291 inline TickInterval& TickInterval::operator-=(const TickInterval& rhs) { 197 inline TickInterval& TickInterval::operator-=(const TickInterval& rhs) {
292 interval_ -= rhs.interval_; 198 interval_ -= rhs.interval_;
293 return *this; 199 return *this;
294 } 200 }
295 201
296 } // namespace webrtc 202 } // namespace webrtc
297 203
298 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_TICK_UTIL_H_ 204 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_TICK_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698