OLD | NEW |
---|---|
(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" | |
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 | |
Sigurður Ásgeirsson
2013/04/04 12:35:14
On Windows XP, QPC is going to be a system call ev
| |
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 base::win::OSInfo* info = base::win::OSInfo::GetInstance(); | |
37 UMA_HISTOGRAM_ENUMERATION("WinTimeTicks.VersionTotal", info->version(), | |
38 base::win::VERSION_WIN_LAST); | |
Sigurður Ásgeirsson
2013/04/04 12:35:14
nit: wonky indent.
| |
39 | |
40 LARGE_INTEGER qpc_frequency; | |
41 QueryPerformanceFrequency(&qpc_frequency); | |
42 | |
43 int min_delta = 1e9; | |
44 LARGE_INTEGER qpc_last; | |
45 QueryPerformanceCounter(&qpc_last); | |
46 for (int i = 0; i < kNumIterations; ++i) { | |
47 LARGE_INTEGER qpc_now; | |
48 QueryPerformanceCounter(&qpc_now); | |
darin (slow to review)
2013/04/04 06:15:11
Perhaps it would make sense to insert some calls t
Sigurður Ásgeirsson
2013/04/04 12:35:14
You can also deliberately cycle the thread across
jar (doing other things)
2013/04/04 16:58:49
I was thinking about suggesting a sleep...
but de
| |
49 int delta = static_cast<int>(qpc_now.QuadPart - qpc_last.QuadPart); | |
Sigurður Ásgeirsson
2013/04/04 17:17:18
If the whole point of this is to identify when dif
| |
50 if (delta != 0) { | |
51 min_delta = std::min(min_delta, delta); | |
52 } | |
53 qpc_last = qpc_now; | |
54 } | |
55 | |
56 if (min_delta >= 0) { | |
57 UMA_HISTOGRAM_ENUMERATION("WinTimeTicks.NonDecreasing", info->version(), | |
58 base::win::VERSION_WIN_LAST); | |
59 } else { | |
60 return; | |
61 } | |
62 | |
63 int min_delta_us = static_cast<int>( | |
64 min_delta * (1e6 / qpc_frequency.QuadPart)); | |
65 UMA_HISTOGRAM_CUSTOM_COUNTS("WinTimeTicks.MinResolutionMicroseconds", | |
66 min_delta_us, 1, 1000, 50); | |
67 | |
68 bool success = min_delta_us <= 100; // Our goal is 0.1ms resolution. | |
69 if (success) { | |
70 UMA_HISTOGRAM_ENUMERATION("WinTimeTicks.VersionSuccessful", | |
71 info->version(), base::win::VERSION_WIN_LAST); | |
72 } | |
73 } | |
74 | |
75 } // namespace chrome_browser_net | |
76 | |
77 #endif // defined(OS_WIN) | |
OLD | NEW |