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

Unified Diff: chrome/browser/metrics/time_ticks_field_trial_win.cc

Issue 13583007: Create a field trial to test if we can detect good QPC implementations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/metrics/time_ticks_field_trial_win.cc
diff --git a/chrome/browser/metrics/time_ticks_field_trial_win.cc b/chrome/browser/metrics/time_ticks_field_trial_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8e911a30be364597a41f02e6f0a7ec8af12a9745
--- /dev/null
+++ b/chrome/browser/metrics/time_ticks_field_trial_win.cc
@@ -0,0 +1,74 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/metrics/time_ticks_field_trial_win.h"
+
+#if defined(OS_WIN)
+
+#include "base/cpu.h"
+#include "base/metrics/field_trial.h"
+#include "base/metrics/histogram.h"
+#include "base/win/windows_version.h"
+
+#include <windows.h>
+
+namespace chrome_browser_metrics {
+
+namespace {
+
+const int kNumIterations = 1000;
+
+} // anonymous namespace
+
+void CollectTimeTicksStats() {
+ // This bit is supposed to indicate that rdtsc is safe across cores. If so, we
+ // can use QPC as long as it uses rdtsc.
+ // TODO(simonjam): We should look for other signals that QPC might be safe and
+ // test them out here.
+ base::CPU cpu;
+ UMA_HISTOGRAM_BOOLEAN("WinTimeTicks.NonStopTsc", cpu.has_nonstoptsc());
+ if (!cpu.has_nonstoptsc()) {
+ return;
+ }
+
+ base::win::OSInfo* info = base::win::OSInfo::GetInstance();
+ UMA_HISTOGRAM_ENUMERATION("WinTimeTicks.VersionTotal", info->version(),
+ base::win::VERSION_WIN_LAST);
+
+ LARGE_INTEGER qpc_frequency;
+ QueryPerformanceFrequency(&qpc_frequency);
+
+ int min_delta = 0;
+ LARGE_INTEGER qpc_last;
+ QueryPerformanceCounter(&qpc_last);
+ for (int i = 0; i < kNumIterations; ++i) {
+ LARGE_INTEGER qpc_now;
+ QueryPerformanceCounter(&qpc_now);
+ int delta = static_cast<int>(qpc_now.QuadPart - qpc_last.QuadPart);
+ if (delta != 0) {
+ min_delta = std::min(min_delta, delta);
+ }
+ qpc_last = qpc_now;
+ }
+
+ UMA_HISTOGRAM_BOOLEAN("WinTimeTicks.NonDecreasing", min_delta > 0);
+ if (min_delta < 0) {
+ return;
jar (doing other things) 2013/04/04 00:26:13 I'm surprised you don't want a histogram of how of
James Simonsen 2013/04/04 02:26:51 Good point. Done.
+ }
+
+ int min_delta_us = static_cast<int>(
+ min_delta * (1e6 / qpc_frequency.QuadPart));
+ UMA_HISTOGRAM_CUSTOM_COUNTS("WinTimeTicks.MinResolutionMicroseconds",
+ min_delta_us, 1, 1000, 50);
+
+ bool success = min_delta_us <= 100; // Our goal is 0.1ms resolution.
+ if (success) {
+ UMA_HISTOGRAM_ENUMERATION("WinTimeTicks.VersionSuccessful",
+ info->version(), base::win::VERSION_WIN_LAST);
+ }
+}
+
+} // namespace chrome_browser_net
+
+#endif // defined(OS_WIN)

Powered by Google App Engine
This is Rietveld 408576698