summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-04 22:17:18 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-04 22:17:18 +0000
commit0b2a2f4907087f36cd185bacbd685930eb7cbb31 (patch)
treefa5911a40aa50c3272b12d24ccabc98b1c4b9472
parentec707950fa24bcda70344b07f88f619117343a4f (diff)
downloadchromium_src-0b2a2f4907087f36cd185bacbd685930eb7cbb31.zip
chromium_src-0b2a2f4907087f36cd185bacbd685930eb7cbb31.tar.gz
chromium_src-0b2a2f4907087f36cd185bacbd685930eb7cbb31.tar.bz2
GTTF: Avoid assertion failures caused by clock drift.
Instead, we add a test dedicated to verifying the QPC time drift. Otherwise the assertion is being flakily hit in unrelated tests, which crashes the entire test binary. With a dedicated test, we still have necessary monitoring, but it's in one place. TEST=base_unittests, net_unittests (stop crashing) BUG=none Review URL: http://codereview.chromium.org/3082014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54978 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/time.h5
-rw-r--r--base/time_win.cc25
-rw-r--r--base/time_win_unittest.cc28
3 files changed, 47 insertions, 11 deletions
diff --git a/base/time.h b/base/time.h
index e885593..539cc14 100644
--- a/base/time.h
+++ b/base/time.h
@@ -459,6 +459,11 @@ class TimeTicks {
// SHOULD ONLY BE USED WHEN IT IS REALLY NEEDED.
static TimeTicks HighResNow();
+#if defined(OS_WIN)
+ // Get the absolute value of QPC time drift. For testing.
+ static int64 GetQPCDriftMicroseconds();
+#endif
+
// Returns true if this object has not been initialized.
bool is_null() const {
return ticks_ == 0;
diff --git a/base/time_win.cc b/base/time_win.cc
index e28835a..00868f6 100644
--- a/base/time_win.cc
+++ b/base/time_win.cc
@@ -331,22 +331,20 @@ class HighResNowSingleton {
}
TimeDelta Now() {
- // Our maximum tolerance for QPC drifting.
- const int kMaxTimeDriftMicroseconds = 60150;
-
- if (IsUsingHighResClock()) {
- int64 now = UnreliableNow();
-
- // Verify that QPC does not seem to drift.
- DCHECK_LT(abs((now - ReliableNow()) - skew_), kMaxTimeDriftMicroseconds);
-
- return TimeDelta::FromMicroseconds(now);
- }
+ if (IsUsingHighResClock())
+ return TimeDelta::FromMicroseconds(UnreliableNow());
// Just fallback to the slower clock.
return RolloverProtectedNow();
}
+ int64 GetQPCDriftMicroseconds() {
+ if (!IsUsingHighResClock())
+ return 0;
+
+ return abs((UnreliableNow() - ReliableNow()) - skew_);
+ }
+
private:
// Synchronize the QPC clock with GetSystemTimeAsFileTime.
void InitializeClock() {
@@ -398,3 +396,8 @@ TimeTicks TimeTicks::Now() {
TimeTicks TimeTicks::HighResNow() {
return TimeTicks() + Singleton<HighResNowSingleton>::get()->Now();
}
+
+// static
+int64 TimeTicks::GetQPCDriftMicroseconds() {
+ return Singleton<HighResNowSingleton>::get()->GetQPCDriftMicroseconds();
+} \ No newline at end of file
diff --git a/base/time_win_unittest.cc b/base/time_win_unittest.cc
index aa39478..26a9784 100644
--- a/base/time_win_unittest.cc
+++ b/base/time_win_unittest.cc
@@ -6,6 +6,7 @@
#include <mmsystem.h>
#include <process.h>
+#include "base/platform_thread.h"
#include "base/time.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -203,3 +204,30 @@ TEST(TimeTicks, TimerPerformance) {
test_case++;
}
}
+
+TEST(TimeTicks, Drift) {
+ const int kIterations = 100;
+ int64 total_drift = 0;
+
+ for (int i = 0; i < kIterations; ++i) {
+ int64 drift_microseconds = TimeTicks::GetQPCDriftMicroseconds();
+
+ // Make sure the drift never exceeds our limit.
+ EXPECT_LT(drift_microseconds, 50000);
+
+ // Sleep for a few milliseconds (note that it means 1000 microseconds).
+ // If we check the drift too frequently, it's going to increase
+ // monotonically, making our measurement less realistic.
+ PlatformThread::Sleep((i % 2 == 0) ? 1 : 2);
+
+ total_drift += drift_microseconds;
+ }
+
+ // Sanity check. We expect some time drift to occur, especially across
+ // the number of iterations we do. However, if the QPC is disabled, this
+ // is not measuring anything (drift is zero in that case).
+ EXPECT_LT(0, total_drift);
+
+ printf("average time drift in microseconds: %lld\n",
+ total_drift / kIterations);
+} \ No newline at end of file