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.
5 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
10 #include "base/command_line.h"
12 #include "base/metrics/histogram.h"
13 #include "base/metrics/sparse_histogram.h"
14 #include "base/sys_info.h"
15 #include "base/threading/sequenced_worker_pool.h"
16 #include "base/time/time.h"
17 #include "chrome/browser/about_flags.h"
18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chrome_browser_main.h"
20 #include "chrome/browser/mac/bluetooth_utility.h"
21 #include "chrome/browser/pref_service_flags_storage.h"
22 #include "chrome/browser/shell_integration.h"
23 #include "content/public/browser/browser_thread.h"
24 #include "ui/base/touch/touch_device.h"
25 #include "ui/base/ui_base_switches.h"
26 #include "ui/events/event_switches.h"
28 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
29 #include <gnu/libc-version.h>
31 #include "base/version.h"
33 #include "ui/base/x/x11_util.h"
35 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS)
38 #include "chrome/installer/util/google_update_settings.h"
39 #endif // defined(OS_WIN)
43 enum UMALinuxGlibcVersion
{
44 UMA_LINUX_GLIBC_NOT_PARSEABLE
,
45 UMA_LINUX_GLIBC_UNKNOWN
,
47 UMA_LINUX_GLIBC_2_19
= UMA_LINUX_GLIBC_2_11
+ 8,
48 // NOTE: Add new version above this line and update the enum list in
49 // tools/metrics/histograms/histograms.xml accordingly.
50 UMA_LINUX_GLIBC_VERSION_COUNT
53 enum UMALinuxWindowManager
{
54 UMA_LINUX_WINDOW_MANAGER_OTHER
,
55 UMA_LINUX_WINDOW_MANAGER_BLACKBOX
,
56 UMA_LINUX_WINDOW_MANAGER_CHROME_OS
, // Deprecated.
57 UMA_LINUX_WINDOW_MANAGER_COMPIZ
,
58 UMA_LINUX_WINDOW_MANAGER_ENLIGHTENMENT
,
59 UMA_LINUX_WINDOW_MANAGER_ICE_WM
,
60 UMA_LINUX_WINDOW_MANAGER_KWIN
,
61 UMA_LINUX_WINDOW_MANAGER_METACITY
,
62 UMA_LINUX_WINDOW_MANAGER_MUFFIN
,
63 UMA_LINUX_WINDOW_MANAGER_MUTTER
,
64 UMA_LINUX_WINDOW_MANAGER_OPENBOX
,
65 UMA_LINUX_WINDOW_MANAGER_XFWM4
,
66 UMA_LINUX_WINDOW_MANAGER_AWESOME
,
67 UMA_LINUX_WINDOW_MANAGER_I3
,
68 UMA_LINUX_WINDOW_MANAGER_ION3
,
69 UMA_LINUX_WINDOW_MANAGER_MATCHBOX
,
70 UMA_LINUX_WINDOW_MANAGER_NOTION
,
71 UMA_LINUX_WINDOW_MANAGER_QTILE
,
72 UMA_LINUX_WINDOW_MANAGER_RATPOISON
,
73 UMA_LINUX_WINDOW_MANAGER_STUMPWM
,
74 UMA_LINUX_WINDOW_MANAGER_WMII
,
75 // NOTE: Append new window managers to the list above this line (i.e. don't
76 // renumber) and update LinuxWindowManagerName in
77 // tools/metrics/histograms/histograms.xml accordingly.
78 UMA_LINUX_WINDOW_MANAGER_COUNT
81 enum UMATouchEventsState
{
82 UMA_TOUCH_EVENTS_ENABLED
,
83 UMA_TOUCH_EVENTS_AUTO_ENABLED
,
84 UMA_TOUCH_EVENTS_AUTO_DISABLED
,
85 UMA_TOUCH_EVENTS_DISABLED
,
86 // NOTE: Add states only immediately above this line. Make sure to
87 // update the enum list in tools/metrics/histograms/histograms.xml
89 UMA_TOUCH_EVENTS_STATE_COUNT
92 void RecordMicroArchitectureStats() {
93 #if defined(ARCH_CPU_X86_FAMILY)
95 base::CPU::IntelMicroArchitecture arch
= cpu
.GetIntelMicroArchitecture();
96 UMA_HISTOGRAM_ENUMERATION("Platform.IntelMaxMicroArchitecture", arch
,
97 base::CPU::MAX_INTEL_MICRO_ARCHITECTURE
);
98 #endif // defined(ARCH_CPU_X86_FAMILY)
99 UMA_HISTOGRAM_SPARSE_SLOWLY("Platform.LogicalCpuCount",
100 base::SysInfo::NumberOfProcessors());
103 // Called on the blocking pool some time after startup to avoid slowing down
104 // startup with metrics that aren't trivial to compute.
105 void RecordStartupMetricsOnBlockingPool() {
107 GoogleUpdateSettings::RecordChromeUpdatePolicyHistograms();
108 #endif // defined(OS_WIN)
110 #if defined(OS_MACOSX) && !defined(OS_IOS)
111 bluetooth_utility::BluetoothAvailability availability
=
112 bluetooth_utility::GetBluetoothAvailability();
113 UMA_HISTOGRAM_ENUMERATION("OSX.BluetoothAvailability",
115 bluetooth_utility::BLUETOOTH_AVAILABILITY_COUNT
);
116 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
119 void RecordLinuxGlibcVersion() {
120 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
121 Version
version(gnu_get_libc_version());
123 UMALinuxGlibcVersion glibc_version_result
= UMA_LINUX_GLIBC_NOT_PARSEABLE
;
124 if (version
.IsValid() && version
.components().size() == 2) {
125 glibc_version_result
= UMA_LINUX_GLIBC_UNKNOWN
;
126 int glibc_major_version
= version
.components()[0];
127 int glibc_minor_version
= version
.components()[1];
128 if (glibc_major_version
== 2) {
129 // A constant to translate glibc 2.x minor versions to their
130 // equivalent UMALinuxGlibcVersion values.
131 const int kGlibcMinorVersionTranslationOffset
= 11 - UMA_LINUX_GLIBC_2_11
;
132 int translated_glibc_minor_version
=
133 glibc_minor_version
- kGlibcMinorVersionTranslationOffset
;
134 if (translated_glibc_minor_version
>= UMA_LINUX_GLIBC_2_11
&&
135 translated_glibc_minor_version
<= UMA_LINUX_GLIBC_2_19
) {
136 glibc_version_result
=
137 static_cast<UMALinuxGlibcVersion
>(translated_glibc_minor_version
);
141 UMA_HISTOGRAM_ENUMERATION("Linux.GlibcVersion", glibc_version_result
,
142 UMA_LINUX_GLIBC_VERSION_COUNT
);
146 #if defined(USE_X11) && !defined(OS_CHROMEOS)
147 UMALinuxWindowManager
GetLinuxWindowManager() {
148 switch (ui::GuessWindowManager()) {
150 return UMA_LINUX_WINDOW_MANAGER_OTHER
;
152 return UMA_LINUX_WINDOW_MANAGER_AWESOME
;
153 case ui::WM_BLACKBOX
:
154 return UMA_LINUX_WINDOW_MANAGER_BLACKBOX
;
156 return UMA_LINUX_WINDOW_MANAGER_COMPIZ
;
157 case ui::WM_ENLIGHTENMENT
:
158 return UMA_LINUX_WINDOW_MANAGER_ENLIGHTENMENT
;
160 return UMA_LINUX_WINDOW_MANAGER_I3
;
162 return UMA_LINUX_WINDOW_MANAGER_ICE_WM
;
164 return UMA_LINUX_WINDOW_MANAGER_ION3
;
166 return UMA_LINUX_WINDOW_MANAGER_KWIN
;
167 case ui::WM_MATCHBOX
:
168 return UMA_LINUX_WINDOW_MANAGER_MATCHBOX
;
169 case ui::WM_METACITY
:
170 return UMA_LINUX_WINDOW_MANAGER_METACITY
;
172 return UMA_LINUX_WINDOW_MANAGER_MUFFIN
;
174 return UMA_LINUX_WINDOW_MANAGER_MUTTER
;
176 return UMA_LINUX_WINDOW_MANAGER_NOTION
;
178 return UMA_LINUX_WINDOW_MANAGER_OPENBOX
;
180 return UMA_LINUX_WINDOW_MANAGER_QTILE
;
181 case ui::WM_RATPOISON
:
182 return UMA_LINUX_WINDOW_MANAGER_RATPOISON
;
184 return UMA_LINUX_WINDOW_MANAGER_STUMPWM
;
186 return UMA_LINUX_WINDOW_MANAGER_WMII
;
188 return UMA_LINUX_WINDOW_MANAGER_XFWM4
;
190 return UMA_LINUX_WINDOW_MANAGER_OTHER
;
194 void RecordTouchEventState() {
195 const CommandLine
& command_line
= *CommandLine::ForCurrentProcess();
196 const std::string touch_enabled_switch
=
197 command_line
.HasSwitch(switches::kTouchEvents
) ?
198 command_line
.GetSwitchValueASCII(switches::kTouchEvents
) :
199 switches::kTouchEventsAuto
;
201 UMATouchEventsState state
;
202 if (touch_enabled_switch
.empty() ||
203 touch_enabled_switch
== switches::kTouchEventsEnabled
) {
204 state
= UMA_TOUCH_EVENTS_ENABLED
;
205 } else if (touch_enabled_switch
== switches::kTouchEventsAuto
) {
206 state
= ui::IsTouchDevicePresent() ?
207 UMA_TOUCH_EVENTS_AUTO_ENABLED
: UMA_TOUCH_EVENTS_AUTO_DISABLED
;
208 } else if (touch_enabled_switch
== switches::kTouchEventsDisabled
) {
209 state
= UMA_TOUCH_EVENTS_DISABLED
;
215 UMA_HISTOGRAM_ENUMERATION("Touchscreen.TouchEventsEnabled", state
,
216 UMA_TOUCH_EVENTS_STATE_COUNT
);
221 ChromeBrowserMainExtraPartsMetrics::ChromeBrowserMainExtraPartsMetrics() {
224 ChromeBrowserMainExtraPartsMetrics::~ChromeBrowserMainExtraPartsMetrics() {
227 void ChromeBrowserMainExtraPartsMetrics::PreProfileInit() {
228 RecordMicroArchitectureStats();
231 void ChromeBrowserMainExtraPartsMetrics::PreBrowserStart() {
232 about_flags::PrefServiceFlagsStorage
flags_storage_(
233 g_browser_process
->local_state());
234 about_flags::RecordUMAStatistics(&flags_storage_
);
237 void ChromeBrowserMainExtraPartsMetrics::PostBrowserStart() {
238 RecordLinuxGlibcVersion();
239 #if defined(USE_X11) && !defined(OS_CHROMEOS)
240 UMA_HISTOGRAM_ENUMERATION("Linux.WindowManager",
241 GetLinuxWindowManager(),
242 UMA_LINUX_WINDOW_MANAGER_COUNT
);
244 RecordTouchEventState();
246 const int kStartupMetricsGatheringDelaySeconds
= 45;
247 content::BrowserThread::GetBlockingPool()->PostDelayedTask(
249 base::Bind(&RecordStartupMetricsOnBlockingPool
),
250 base::TimeDelta::FromSeconds(kStartupMetricsGatheringDelaySeconds
));
255 void AddMetricsExtraParts(ChromeBrowserMainParts
* main_parts
) {
256 main_parts
->AddParts(new ChromeBrowserMainExtraPartsMetrics());
259 } // namespace chrome