Chromium Code Reviews| 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/histogram.h" | |
| 11 #include "base/win/windows_version.h" | |
| 12 | |
| 13 #include <windows.h> | |
| 14 | |
| 15 namespace chrome_browser_metrics { | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 const int kNumIterations = 1000; | |
| 20 | |
| 21 } // anonymous namespace | |
| 22 | |
| 23 void CollectTimeTicksStats() { | |
| 24 // This bit is supposed to indicate that rdtsc is safe across cores. If so, we | |
| 25 // can use QPC as long as it uses rdtsc. | |
| 26 // TODO(simonjam): We should look for other signals that QPC might be safe and | |
| 27 // test them out here. | |
| 28 base::CPU cpu; | |
| 29 UMA_HISTOGRAM_BOOLEAN("WinTimeTicks.NonStopTsc", | |
| 30 cpu.has_non_stop_time_stamp_counter()); | |
| 31 if (!cpu.has_non_stop_time_stamp_counter()) { | |
| 32 return; | |
| 33 } | |
| 34 | |
| 35 SYSTEM_INFO sys_info; | |
| 36 GetSystemInfo(&sys_info); | |
| 37 DWORD num_cores = sys_info.dwNumberOfProcessors; | |
| 38 DWORD current_core = GetCurrentProcessorNumber(); | |
| 39 | |
| 40 base::win::OSInfo* info = base::win::OSInfo::GetInstance(); | |
| 41 UMA_HISTOGRAM_ENUMERATION("WinTimeTicks.VersionTotal", info->version(), | |
| 42 base::win::VERSION_WIN_LAST); | |
| 43 | |
| 44 DWORD starting_core = GetCurrentProcessorNumber(); | |
| 45 bool did_change_cores = false; | |
| 46 | |
| 47 LARGE_INTEGER qpc_frequency; | |
| 48 QueryPerformanceFrequency(&qpc_frequency); | |
| 49 | |
| 50 int min_delta = 1e9; | |
| 51 LARGE_INTEGER qpc_last; | |
| 52 QueryPerformanceCounter(&qpc_last); | |
| 53 for (int i = 0; i < kNumIterations; ++i) { | |
| 54 LARGE_INTEGER qpc_now; | |
| 55 QueryPerformanceCounter(&qpc_now); | |
| 56 int delta = static_cast<int>(qpc_now.QuadPart - qpc_last.QuadPart); | |
| 57 if (delta != 0) { | |
| 58 min_delta = std::min(min_delta, delta); | |
| 59 } | |
| 60 qpc_last = qpc_now; | |
| 61 | |
| 62 if (num_cores > 1 && (i % 100) == 0) { | |
| 63 ++current_core; | |
| 64 if (current_core > num_cores) { | |
| 65 current_core = 0; | |
| 66 } | |
| 67 SetThreadAffinityMask(GetCurrentThread(), 1 << current_core); | |
| 68 if (!did_change_cores && | |
| 69 GetCurrentProcessorNumber() != starting_core) { | |
|
Sigurður Ásgeirsson
2013/04/12 13:34:02
This function is only documented available as of W
James Simonsen
2013/04/13 02:17:57
We don't have any XP try bots it seems. :(
I adde
| |
| 70 did_change_cores = true; | |
| 71 } | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 if (did_change_cores) { | |
| 76 UMA_HISTOGRAM_ENUMERATION("WinTimeTicks.ChangedCores", info->version(), | |
| 77 base::win::VERSION_WIN_LAST); | |
| 78 } | |
| 79 | |
| 80 if (min_delta >= 0) { | |
| 81 UMA_HISTOGRAM_ENUMERATION("WinTimeTicks.NonDecreasing", info->version(), | |
| 82 base::win::VERSION_WIN_LAST); | |
| 83 } else { | |
| 84 return; | |
| 85 } | |
| 86 | |
| 87 int min_delta_ns = static_cast<int>( | |
| 88 min_delta * (1e9 / qpc_frequency.QuadPart)); | |
| 89 UMA_HISTOGRAM_CUSTOM_COUNTS("WinTimeTicks.MinResolutionNanoseconds", | |
| 90 min_delta_ns, 1, 1000000, 50); | |
| 91 | |
| 92 bool success = min_delta_ns <= 1000; | |
| 93 if (success) { | |
| 94 UMA_HISTOGRAM_ENUMERATION("WinTimeTicks.VersionSuccessful", | |
| 95 info->version(), base::win::VERSION_WIN_LAST); | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 } // namespace chrome_browser_net | |
| 100 | |
| 101 #endif // defined(OS_WIN) | |
| OLD | NEW |