Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h" | 5 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 11 #include "base/cpu.h" | 12 #include "base/cpu.h" |
| 12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 14 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "base/time.h" | 15 #include "base/time.h" |
| 15 #include "chrome/browser/about_flags.h" | 16 #include "chrome/browser/about_flags.h" |
| 16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/chrome_browser_main.h" | 18 #include "chrome/browser/chrome_browser_main.h" |
| 18 #include "chrome/browser/shell_integration.h" | 19 #include "chrome/browser/shell_integration.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "ui/base/touch/touch_device.h" | 21 #include "ui/base/touch/touch_device.h" |
| 21 #include "ui/base/ui_base_switches.h" | 22 #include "ui/base/ui_base_switches.h" |
| 22 | 23 |
| 24 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
| 25 #include <gnu/libc-version.h> | |
| 26 | |
| 27 #include "base/strings/string_number_conversions.h" | |
| 28 #include "base/strings/string_split.h" | |
| 29 #endif | |
| 30 | |
| 23 namespace { | 31 namespace { |
| 24 | 32 |
| 33 enum UMALinuxGlibcVersion { | |
| 34 UMA_LINUX_GLIBC_NOT_PARSEABLE, | |
| 35 UMA_LINUX_GLIBC_UNKNOWN, | |
| 36 UMA_LINUX_GLIBC_2_11, | |
| 37 UMA_LINUX_GLIBC_2_19 = UMA_LINUX_GLIBC_2_11 + 8, | |
| 38 // NOTE: Add new version above this line and update the enum list in | |
| 39 // tools/histograms/histograms.xml accordingly. | |
| 40 UMA_LINUX_GLIBC_VERSION_COUNT | |
| 41 }; | |
| 42 | |
| 43 // A constant to translate glibc 2.x minor versions to their | |
| 44 // equivalent UMALinuxGlibcVersion values. | |
| 45 const unsigned kGlibcMinorVersionTranslationOffset = 11 - UMA_LINUX_GLIBC_2_11; | |
| 46 | |
| 25 enum UMATouchEventsState { | 47 enum UMATouchEventsState { |
| 26 UMA_TOUCH_EVENTS_ENABLED, | 48 UMA_TOUCH_EVENTS_ENABLED, |
| 27 UMA_TOUCH_EVENTS_AUTO_ENABLED, | 49 UMA_TOUCH_EVENTS_AUTO_ENABLED, |
| 28 UMA_TOUCH_EVENTS_AUTO_DISABLED, | 50 UMA_TOUCH_EVENTS_AUTO_DISABLED, |
| 29 UMA_TOUCH_EVENTS_DISABLED, | 51 UMA_TOUCH_EVENTS_DISABLED, |
| 30 // NOTE: Add states only immediately above this line. Make sure to | 52 // NOTE: Add states only immediately above this line. Make sure to |
| 31 // update the enum list in tools/histograms/histograms.xml accordingly. | 53 // update the enum list in tools/histograms/histograms.xml accordingly. |
| 32 UMA_TOUCH_EVENTS_STATE_COUNT | 54 UMA_TOUCH_EVENTS_STATE_COUNT |
| 33 }; | 55 }; |
| 34 | 56 |
| 35 void LogIntelMicroArchitecture() { | 57 void RecordIntelMicroArchitecture() { |
| 36 #if defined(ARCH_CPU_X86_FAMILY) | 58 #if defined(ARCH_CPU_X86_FAMILY) |
| 37 base::CPU cpu; | 59 base::CPU cpu; |
| 38 base::CPU::IntelMicroArchitecture arch = cpu.GetIntelMicroArchitecture(); | 60 base::CPU::IntelMicroArchitecture arch = cpu.GetIntelMicroArchitecture(); |
| 39 UMA_HISTOGRAM_ENUMERATION("Platform.IntelMaxMicroArchitecture", arch, | 61 UMA_HISTOGRAM_ENUMERATION("Platform.IntelMaxMicroArchitecture", arch, |
| 40 base::CPU::MAX_INTEL_MICRO_ARCHITECTURE); | 62 base::CPU::MAX_INTEL_MICRO_ARCHITECTURE); |
| 41 #endif // defined(ARCH_CPU_X86_FAMILY) | 63 #endif // defined(ARCH_CPU_X86_FAMILY) |
| 42 } | 64 } |
| 43 | 65 |
| 44 void RecordDefaultBrowserUMAStat() { | 66 void RecordDefaultBrowserUMAStat() { |
| 45 // Record whether Chrome is the default browser or not. | 67 // Record whether Chrome is the default browser or not. |
| 46 ShellIntegration::DefaultWebClientState default_state = | 68 ShellIntegration::DefaultWebClientState default_state = |
| 47 ShellIntegration::GetDefaultBrowser(); | 69 ShellIntegration::GetDefaultBrowser(); |
| 48 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.State", default_state, | 70 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.State", default_state, |
| 49 ShellIntegration::NUM_DEFAULT_STATES); | 71 ShellIntegration::NUM_DEFAULT_STATES); |
| 50 } | 72 } |
| 51 | 73 |
| 74 void RecordLinuxGlibcVersion() { | |
| 75 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
| 76 std::string glibc_version_string(gnu_get_libc_version()); | |
| 77 std::vector<std::string> split_glibc_version; | |
| 78 base::SplitString(glibc_version_string, '.', &split_glibc_version); | |
| 79 | |
| 80 UMALinuxGlibcVersion glibc_version_result = UMA_LINUX_GLIBC_NOT_PARSEABLE; | |
| 81 unsigned glibc_major_version = 0; | |
| 82 unsigned glibc_minor_version = 0; | |
| 83 if (split_glibc_version.size() == 2 && | |
| 84 base::StringToUint(split_glibc_version[0], &glibc_major_version) && | |
| 85 base::StringToUint(split_glibc_version[1], &glibc_minor_version)) { | |
| 86 unsigned translated_glibc_minor_version = | |
| 87 glibc_minor_version - kGlibcMinorVersionTranslationOffset; | |
| 88 if (glibc_major_version == 2 && | |
|
jar (doing other things)
2013/04/16 03:31:14
nit: Don't do the translation in lines 86-87 until
| |
| 89 (translated_glibc_minor_version >= UMA_LINUX_GLIBC_2_11 && | |
| 90 translated_glibc_minor_version <= UMA_LINUX_GLIBC_2_19)) { | |
| 91 glibc_version_result = | |
| 92 static_cast<UMALinuxGlibcVersion>(translated_glibc_minor_version); | |
| 93 } else { | |
| 94 glibc_version_result = UMA_LINUX_GLIBC_UNKNOWN; | |
|
jar (doing other things)
2013/04/16 03:31:14
nit: I'm betting you made the if statement more co
| |
| 95 } | |
| 96 } | |
| 97 UMA_HISTOGRAM_ENUMERATION("Linux.GlibcVersion", glibc_version_result, | |
| 98 UMA_LINUX_GLIBC_VERSION_COUNT); | |
| 99 #endif | |
| 100 } | |
| 101 | |
| 52 void RecordTouchEventState() { | 102 void RecordTouchEventState() { |
| 53 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 103 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 54 const std::string touch_enabled_switch = | 104 const std::string touch_enabled_switch = |
| 55 command_line.HasSwitch(switches::kTouchEvents) ? | 105 command_line.HasSwitch(switches::kTouchEvents) ? |
| 56 command_line.GetSwitchValueASCII(switches::kTouchEvents) : | 106 command_line.GetSwitchValueASCII(switches::kTouchEvents) : |
| 57 switches::kTouchEventsAuto; | 107 switches::kTouchEventsAuto; |
| 58 | 108 |
| 59 UMATouchEventsState state; | 109 UMATouchEventsState state; |
| 60 if (touch_enabled_switch.empty() || | 110 if (touch_enabled_switch.empty() || |
| 61 touch_enabled_switch == switches::kTouchEventsEnabled) { | 111 touch_enabled_switch == switches::kTouchEventsEnabled) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 76 | 126 |
| 77 } // namespace | 127 } // namespace |
| 78 | 128 |
| 79 ChromeBrowserMainExtraPartsMetrics::ChromeBrowserMainExtraPartsMetrics() { | 129 ChromeBrowserMainExtraPartsMetrics::ChromeBrowserMainExtraPartsMetrics() { |
| 80 } | 130 } |
| 81 | 131 |
| 82 ChromeBrowserMainExtraPartsMetrics::~ChromeBrowserMainExtraPartsMetrics() { | 132 ChromeBrowserMainExtraPartsMetrics::~ChromeBrowserMainExtraPartsMetrics() { |
| 83 } | 133 } |
| 84 | 134 |
| 85 void ChromeBrowserMainExtraPartsMetrics::PreProfileInit() { | 135 void ChromeBrowserMainExtraPartsMetrics::PreProfileInit() { |
| 86 LogIntelMicroArchitecture(); | 136 RecordIntelMicroArchitecture(); |
| 87 } | 137 } |
| 88 | 138 |
| 89 void ChromeBrowserMainExtraPartsMetrics::PreBrowserStart() { | 139 void ChromeBrowserMainExtraPartsMetrics::PreBrowserStart() { |
| 90 about_flags::RecordUMAStatistics(g_browser_process->local_state()); | 140 about_flags::RecordUMAStatistics(g_browser_process->local_state()); |
| 91 | 141 |
| 92 // Querying the default browser state can be slow, do it in the background. | 142 // Querying the default browser state can be slow, do it in the background. |
| 93 content::BrowserThread::GetBlockingPool()->PostDelayedTask( | 143 content::BrowserThread::GetBlockingPool()->PostDelayedTask( |
| 94 FROM_HERE, | 144 FROM_HERE, |
| 95 base::Bind(&RecordDefaultBrowserUMAStat), | 145 base::Bind(&RecordDefaultBrowserUMAStat), |
| 96 base::TimeDelta::FromSeconds(45)); | 146 base::TimeDelta::FromSeconds(45)); |
| 97 } | 147 } |
| 98 | 148 |
| 99 void ChromeBrowserMainExtraPartsMetrics::PostBrowserStart() { | 149 void ChromeBrowserMainExtraPartsMetrics::PostBrowserStart() { |
| 150 RecordLinuxGlibcVersion(); | |
| 100 RecordTouchEventState(); | 151 RecordTouchEventState(); |
| 101 } | 152 } |
| 102 | 153 |
| 103 namespace chrome { | 154 namespace chrome { |
| 104 | 155 |
| 105 void AddMetricsExtraParts(ChromeBrowserMainParts* main_parts) { | 156 void AddMetricsExtraParts(ChromeBrowserMainParts* main_parts) { |
| 106 main_parts->AddParts(new ChromeBrowserMainExtraPartsMetrics()); | 157 main_parts->AddParts(new ChromeBrowserMainExtraPartsMetrics()); |
| 107 } | 158 } |
| 108 | 159 |
| 109 } // namespace chrome | 160 } // namespace chrome |
| OLD | NEW |