OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 #include <windows.h> | 5 #include <windows.h> |
6 #include <mmsystem.h> | 6 #include <mmsystem.h> |
7 #include <process.h> | 7 #include <process.h> |
8 | 8 |
9 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 total_drift += drift_microseconds; | 234 total_drift += drift_microseconds; |
235 } | 235 } |
236 | 236 |
237 // Sanity check. We expect some time drift to occur, especially across | 237 // Sanity check. We expect some time drift to occur, especially across |
238 // the number of iterations we do. | 238 // the number of iterations we do. |
239 EXPECT_LT(0, total_drift); | 239 EXPECT_LT(0, total_drift); |
240 | 240 |
241 printf("average time drift in microseconds: %lld\n", | 241 printf("average time drift in microseconds: %lld\n", |
242 total_drift / kIterations); | 242 total_drift / kIterations); |
243 } | 243 } |
244 | |
245 int64 QPCValueToMicrosecondsSafely(LONGLONG qpc_value, | |
246 int64 ticks_per_second) { | |
247 int64 whole_seconds = qpc_value / ticks_per_second; | |
248 int64 leftover_ticks = qpc_value % ticks_per_second; | |
249 int64 microseconds = (whole_seconds * Time::kMicrosecondsPerSecond) + | |
250 ((leftover_ticks * Time::kMicrosecondsPerSecond) / | |
251 ticks_per_second); | |
252 return microseconds; | |
253 } | |
254 | |
255 TEST(TimeTicks, FromQPCValue) { | |
256 if (!TimeTicks::IsHighResClockWorking()) | |
257 return; | |
258 LARGE_INTEGER frequency; | |
259 QueryPerformanceFrequency(&frequency); | |
260 int64 ticks_per_second = frequency.QuadPart; | |
261 LONGLONG qpc_value = Time::kQPCOverflowThreshold; | |
262 TimeTicks expected_value = TimeTicks::FromInternalValue( | |
263 QPCValueToMicrosecondsSafely(qpc_value + 1, ticks_per_second)); | |
jar (doing other things)
2014/08/01 04:55:32
nit: please add one more test, for *exactly* qpc_v
fmeawad
2014/08/05 22:20:09
Done.
| |
264 EXPECT_EQ(expected_value, | |
265 TimeTicks::FromQPCValue(qpc_value + 1)); | |
266 expected_value = TimeTicks::FromInternalValue( | |
267 QPCValueToMicrosecondsSafely(qpc_value - 1, ticks_per_second)); | |
268 EXPECT_EQ(expected_value, | |
269 TimeTicks::FromQPCValue(qpc_value - 1)); | |
270 } | |
OLD | NEW |