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/pref_service_flags_storage.h"
21 #include "chrome/browser/shell_integration.h"
22 #include "content/public/browser/browser_thread.h"
23 #include "ui/base/touch/touch_device.h"
24 #include "ui/base/ui_base_switches.h"
25 #include "ui/events/event_switches.h"
27 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
28 #include <gnu/libc-version.h>
30 #include "base/version.h"
31 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS)
34 #include "chrome/installer/util/google_update_settings.h"
35 #endif // defined(OS_WIN)
39 enum UMALinuxGlibcVersion
{
40 UMA_LINUX_GLIBC_NOT_PARSEABLE
,
41 UMA_LINUX_GLIBC_UNKNOWN
,
43 UMA_LINUX_GLIBC_2_19
= UMA_LINUX_GLIBC_2_11
+ 8,
44 // NOTE: Add new version above this line and update the enum list in
45 // tools/histograms/histograms.xml accordingly.
46 UMA_LINUX_GLIBC_VERSION_COUNT
49 enum UMATouchEventsState
{
50 UMA_TOUCH_EVENTS_ENABLED
,
51 UMA_TOUCH_EVENTS_AUTO_ENABLED
,
52 UMA_TOUCH_EVENTS_AUTO_DISABLED
,
53 UMA_TOUCH_EVENTS_DISABLED
,
54 // NOTE: Add states only immediately above this line. Make sure to
55 // update the enum list in tools/histograms/histograms.xml accordingly.
56 UMA_TOUCH_EVENTS_STATE_COUNT
59 void RecordMicroArchitectureStats() {
60 #if defined(ARCH_CPU_X86_FAMILY)
62 base::CPU::IntelMicroArchitecture arch
= cpu
.GetIntelMicroArchitecture();
63 UMA_HISTOGRAM_ENUMERATION("Platform.IntelMaxMicroArchitecture", arch
,
64 base::CPU::MAX_INTEL_MICRO_ARCHITECTURE
);
65 #endif // defined(ARCH_CPU_X86_FAMILY)
66 UMA_HISTOGRAM_SPARSE_SLOWLY("Platform.LogicalCpuCount",
67 base::SysInfo::NumberOfProcessors());
70 // Called on the blocking pool some time after startup to avoid slowing down
71 // startup with metrics that aren't trivial to compute.
72 void RecordStartupMetricsOnBlockingPool() {
74 GoogleUpdateSettings::RecordChromeUpdatePolicyHistograms();
75 #endif // defined(OS_WIN)
78 void RecordLinuxGlibcVersion() {
79 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
80 Version
version(gnu_get_libc_version());
82 UMALinuxGlibcVersion glibc_version_result
= UMA_LINUX_GLIBC_NOT_PARSEABLE
;
83 if (version
.IsValid() && version
.components().size() == 2) {
84 glibc_version_result
= UMA_LINUX_GLIBC_UNKNOWN
;
85 int glibc_major_version
= version
.components()[0];
86 int glibc_minor_version
= version
.components()[1];
87 if (glibc_major_version
== 2) {
88 // A constant to translate glibc 2.x minor versions to their
89 // equivalent UMALinuxGlibcVersion values.
90 const int kGlibcMinorVersionTranslationOffset
= 11 - UMA_LINUX_GLIBC_2_11
;
91 int translated_glibc_minor_version
=
92 glibc_minor_version
- kGlibcMinorVersionTranslationOffset
;
93 if (translated_glibc_minor_version
>= UMA_LINUX_GLIBC_2_11
&&
94 translated_glibc_minor_version
<= UMA_LINUX_GLIBC_2_19
) {
95 glibc_version_result
=
96 static_cast<UMALinuxGlibcVersion
>(translated_glibc_minor_version
);
100 UMA_HISTOGRAM_ENUMERATION("Linux.GlibcVersion", glibc_version_result
,
101 UMA_LINUX_GLIBC_VERSION_COUNT
);
105 void RecordTouchEventState() {
106 const CommandLine
& command_line
= *CommandLine::ForCurrentProcess();
107 const std::string touch_enabled_switch
=
108 command_line
.HasSwitch(switches::kTouchEvents
) ?
109 command_line
.GetSwitchValueASCII(switches::kTouchEvents
) :
110 switches::kTouchEventsAuto
;
112 UMATouchEventsState state
;
113 if (touch_enabled_switch
.empty() ||
114 touch_enabled_switch
== switches::kTouchEventsEnabled
) {
115 state
= UMA_TOUCH_EVENTS_ENABLED
;
116 } else if (touch_enabled_switch
== switches::kTouchEventsAuto
) {
117 state
= ui::IsTouchDevicePresent() ?
118 UMA_TOUCH_EVENTS_AUTO_ENABLED
: UMA_TOUCH_EVENTS_AUTO_DISABLED
;
119 } else if (touch_enabled_switch
== switches::kTouchEventsDisabled
) {
120 state
= UMA_TOUCH_EVENTS_DISABLED
;
126 UMA_HISTOGRAM_ENUMERATION("Touchscreen.TouchEventsEnabled", state
,
127 UMA_TOUCH_EVENTS_STATE_COUNT
);
132 ChromeBrowserMainExtraPartsMetrics::ChromeBrowserMainExtraPartsMetrics() {
135 ChromeBrowserMainExtraPartsMetrics::~ChromeBrowserMainExtraPartsMetrics() {
138 void ChromeBrowserMainExtraPartsMetrics::PreProfileInit() {
139 RecordMicroArchitectureStats();
142 void ChromeBrowserMainExtraPartsMetrics::PreBrowserStart() {
143 about_flags::PrefServiceFlagsStorage
flags_storage_(
144 g_browser_process
->local_state());
145 about_flags::RecordUMAStatistics(&flags_storage_
);
148 void ChromeBrowserMainExtraPartsMetrics::PostBrowserStart() {
149 RecordLinuxGlibcVersion();
150 RecordTouchEventState();
152 const int kStartupMetricsGatheringDelaySeconds
= 45;
153 content::BrowserThread::GetBlockingPool()->PostDelayedTask(
155 base::Bind(&RecordStartupMetricsOnBlockingPool
),
156 base::TimeDelta::FromSeconds(kStartupMetricsGatheringDelaySeconds
));
161 void AddMetricsExtraParts(ChromeBrowserMainParts
* main_parts
) {
162 main_parts
->AddParts(new ChromeBrowserMainExtraPartsMetrics());
165 } // namespace chrome