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

Side by Side 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: Try to force a core change Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/metrics/time_ticks_field_trial_win.h"
6
7 #if defined(OS_WIN)
8
9 #include "base/cpu.h"
10 #include "base/metrics/field_trial.h"
jar (doing other things) 2013/04/12 02:14:54 Is this actually a field trial? I don't think you
James Simonsen 2013/04/12 02:29:46 Good point. No it's not a field trial in the sense
11 #include "base/metrics/histogram.h"
12 #include "base/win/windows_version.h"
13
14 #include <windows.h>
15
16 namespace chrome_browser_metrics {
17
18 namespace {
19
20 const int kNumIterations = 1000;
21
22 } // anonymous namespace
23
24 void CollectTimeTicksStats() {
25 // This bit is supposed to indicate that rdtsc is safe across cores. If so, we
26 // can use QPC as long as it uses rdtsc.
27 // TODO(simonjam): We should look for other signals that QPC might be safe and
28 // test them out here.
29 base::CPU cpu;
30 UMA_HISTOGRAM_BOOLEAN("WinTimeTicks.NonStopTsc",
31 cpu.has_non_stop_time_stamp_counter());
32 if (!cpu.has_non_stop_time_stamp_counter()) {
33 return;
34 }
35
36 SYSTEM_INFO sys_info;
37 GetSystemInfo(&sys_info);
38 DWORD num_cores = sys_info.dwNumberOfProcessors;
39 DWORD current_core = GetCurrentProcessorNumber();
40
41 base::win::OSInfo* info = base::win::OSInfo::GetInstance();
42 UMA_HISTOGRAM_ENUMERATION("WinTimeTicks.VersionTotal", info->version(),
43 base::win::VERSION_WIN_LAST);
44
45 DWORD starting_core = GetCurrentProcessorNumber();
46 bool did_change_cores = false;
47
48 LARGE_INTEGER qpc_frequency;
49 QueryPerformanceFrequency(&qpc_frequency);
50
51 int min_delta = 1e9;
52 LARGE_INTEGER qpc_last;
53 QueryPerformanceCounter(&qpc_last);
54 for (int i = 0; i < kNumIterations; ++i) {
55 LARGE_INTEGER qpc_now;
56 QueryPerformanceCounter(&qpc_now);
57 int delta = static_cast<int>(qpc_now.QuadPart - qpc_last.QuadPart);
58 if (delta != 0) {
59 min_delta = std::min(min_delta, delta);
60 }
61 qpc_last = qpc_now;
62
63 if (num_cores > 1 && (i % 100) == 0) {
64 ++current_core;
65 if (current_core > num_cores) {
66 current_core = 0;
67 }
68 SetThreadAffinityMask(GetCurrentThread(), 1 << current_core);
69 if (!did_change_cores &&
70 GetCurrentProcessorNumber() != starting_core) {
71 did_change_cores = true;
72 }
73 }
74 }
75
76 if (did_change_cores) {
77 UMA_HISTOGRAM_ENUMERATION("WinTimeTicks.ChangedCores", info->version(),
78 base::win::VERSION_WIN_LAST);
79 }
80
81 if (min_delta >= 0) {
82 UMA_HISTOGRAM_ENUMERATION("WinTimeTicks.NonDecreasing", info->version(),
83 base::win::VERSION_WIN_LAST);
84 } else {
85 return;
86 }
87
88 int min_delta_ns = static_cast<int>(
89 min_delta * (1e9 / qpc_frequency.QuadPart));
90 UMA_HISTOGRAM_CUSTOM_COUNTS("WinTimeTicks.MinResolutionNanoseconds",
91 min_delta_ns, 1, 1000000, 50);
92
93 bool success = min_delta_ns <= 1000;
94 if (success) {
95 UMA_HISTOGRAM_ENUMERATION("WinTimeTicks.VersionSuccessful",
96 info->version(), base::win::VERSION_WIN_LAST);
97 }
98 }
99
100 } // namespace chrome_browser_net
101
102 #endif // defined(OS_WIN)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698