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

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

Issue 1450203002: Revert of Several Tick counter improvements. (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
61 // Returns a TickTime that is ticks later than the passed TickTime. 59 // Returns a TickTime that is ticks later than the passed TickTime.
62 friend TickTime operator+(const TickTime lhs, const int64_t ticks); 60 friend TickTime operator+(const TickTime lhs, const int64_t ticks);
63 TickTime& operator+=(const int64_t& ticks); 61 TickTime& operator+=(const int64_t& ticks);
64 62
65 // Returns a TickInterval that is the difference in ticks beween rhs and lhs. 63 // Returns a TickInterval that is the difference in ticks beween rhs and lhs.
66 friend TickInterval operator-(const TickTime& lhs, const TickTime& rhs); 64 friend TickInterval operator-(const TickTime& lhs, const TickTime& rhs);
67 65
68 // Call to engage the fake clock. This is useful for tests since relying on 66 // Call to engage the fake clock. This is useful for tests since relying on
69 // a real clock often makes the test flaky. 67 // a real clock often makes the test flaky.
70 static void UseFakeClock(int64_t start_millisecond); 68 static void UseFakeClock(int64_t start_millisecond);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 private: 105 private:
108 explicit TickInterval(int64_t interval); 106 explicit TickInterval(int64_t interval);
109 107
110 friend class TickTime; 108 friend class TickTime;
111 friend TickInterval operator-(const TickTime& lhs, const TickTime& rhs); 109 friend TickInterval operator-(const TickTime& lhs, const TickTime& rhs);
112 110
113 private: 111 private:
114 int64_t interval_; 112 int64_t interval_;
115 }; 113 };
116 114
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
125 inline TickInterval operator+(const TickInterval& lhs, 115 inline TickInterval operator+(const TickInterval& lhs,
126 const TickInterval& rhs) { 116 const TickInterval& rhs) {
127 return TickInterval(lhs.interval_ + rhs.interval_); 117 return TickInterval(lhs.interval_ + rhs.interval_);
128 } 118 }
129 119
130 inline TickInterval operator-(const TickInterval& lhs, 120 inline TickInterval operator-(const TickInterval& lhs,
131 const TickInterval& rhs) { 121 const TickInterval& rhs) {
132 return TickInterval(lhs.interval_ - rhs.interval_); 122 return TickInterval(lhs.interval_ - rhs.interval_);
133 } 123 }
134 124
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 : ticks_(ticks) { 156 : ticks_(ticks) {
167 } 157 }
168 158
169 inline TickTime TickTime::Now() { 159 inline TickTime TickTime::Now() {
170 if (use_fake_clock_) 160 if (use_fake_clock_)
171 return TickTime(fake_ticks_); 161 return TickTime(fake_ticks_);
172 else 162 else
173 return TickTime(QueryOsForTicks()); 163 return TickTime(QueryOsForTicks());
174 } 164 }
175 165
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
176 inline int64_t TickTime::Ticks() const { 200 inline int64_t TickTime::Ticks() const {
177 return ticks_; 201 return ticks_;
178 } 202 }
179 203
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
180 inline TickTime& TickTime::operator+=(const int64_t& ticks) { 236 inline TickTime& TickTime::operator+=(const int64_t& ticks) {
181 ticks_ += ticks; 237 ticks_ += ticks;
182 return *this; 238 return *this;
183 } 239 }
184 240
185 inline TickInterval::TickInterval() : interval_(0) { 241 inline TickInterval::TickInterval() : interval_(0) {
186 } 242 }
187 243
188 inline TickInterval::TickInterval(const int64_t interval) 244 inline TickInterval::TickInterval(const int64_t interval)
189 : interval_(interval) { 245 : interval_(interval) {
190 } 246 }
191 247
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
192 inline TickInterval& TickInterval::operator+=(const TickInterval& rhs) { 286 inline TickInterval& TickInterval::operator+=(const TickInterval& rhs) {
193 interval_ += rhs.interval_; 287 interval_ += rhs.interval_;
194 return *this; 288 return *this;
195 } 289 }
196 290
197 inline TickInterval& TickInterval::operator-=(const TickInterval& rhs) { 291 inline TickInterval& TickInterval::operator-=(const TickInterval& rhs) {
198 interval_ -= rhs.interval_; 292 interval_ -= rhs.interval_;
199 return *this; 293 return *this;
200 } 294 }
201 295
202 } // namespace webrtc 296 } // namespace webrtc
203 297
204 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_TICK_UTIL_H_ 298 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_TICK_UTIL_H_
OLDNEW
« no previous file with comments | « webrtc/modules/utility/source/process_thread_impl_unittest.cc ('k') | webrtc/system_wrappers/source/tick_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698