This source file includes following definitions.
- RecordMicroArchitectureStats
- RecordStartupMetricsOnBlockingPool
- RecordLinuxGlibcVersion
- RecordTouchEventState
- PreProfileInit
- PreBrowserStart
- PostBrowserStart
- AddMetricsExtraParts
#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
#include <string>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/cpu.h"
#include "base/metrics/histogram.h"
#include "base/metrics/sparse_histogram.h"
#include "base/sys_info.h"
#include "base/threading/sequenced_worker_pool.h"
#include "base/time/time.h"
#include "chrome/browser/about_flags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_browser_main.h"
#include "chrome/browser/pref_service_flags_storage.h"
#include "chrome/browser/shell_integration.h"
#include "content/public/browser/browser_thread.h"
#include "ui/base/touch/touch_device.h"
#include "ui/base/ui_base_switches.h"
#include "ui/events/event_switches.h"
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
#include <gnu/libc-version.h>
#include "base/version.h"
#endif
#if defined(OS_WIN)
#include "chrome/installer/util/google_update_settings.h"
#endif
namespace {
enum UMALinuxGlibcVersion {
UMA_LINUX_GLIBC_NOT_PARSEABLE,
UMA_LINUX_GLIBC_UNKNOWN,
UMA_LINUX_GLIBC_2_11,
UMA_LINUX_GLIBC_2_19 = UMA_LINUX_GLIBC_2_11 + 8,
UMA_LINUX_GLIBC_VERSION_COUNT
};
enum UMATouchEventsState {
UMA_TOUCH_EVENTS_ENABLED,
UMA_TOUCH_EVENTS_AUTO_ENABLED,
UMA_TOUCH_EVENTS_AUTO_DISABLED,
UMA_TOUCH_EVENTS_DISABLED,
UMA_TOUCH_EVENTS_STATE_COUNT
};
void RecordMicroArchitectureStats() {
#if defined(ARCH_CPU_X86_FAMILY)
base::CPU cpu;
base::CPU::IntelMicroArchitecture arch = cpu.GetIntelMicroArchitecture();
UMA_HISTOGRAM_ENUMERATION("Platform.IntelMaxMicroArchitecture", arch,
base::CPU::MAX_INTEL_MICRO_ARCHITECTURE);
#endif
UMA_HISTOGRAM_SPARSE_SLOWLY("Platform.LogicalCpuCount",
base::SysInfo::NumberOfProcessors());
}
void RecordStartupMetricsOnBlockingPool() {
#if defined(OS_WIN)
GoogleUpdateSettings::RecordChromeUpdatePolicyHistograms();
#endif
}
void RecordLinuxGlibcVersion() {
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Version version(gnu_get_libc_version());
UMALinuxGlibcVersion glibc_version_result = UMA_LINUX_GLIBC_NOT_PARSEABLE;
if (version.IsValid() && version.components().size() == 2) {
glibc_version_result = UMA_LINUX_GLIBC_UNKNOWN;
int glibc_major_version = version.components()[0];
int glibc_minor_version = version.components()[1];
if (glibc_major_version == 2) {
const int kGlibcMinorVersionTranslationOffset = 11 - UMA_LINUX_GLIBC_2_11;
int translated_glibc_minor_version =
glibc_minor_version - kGlibcMinorVersionTranslationOffset;
if (translated_glibc_minor_version >= UMA_LINUX_GLIBC_2_11 &&
translated_glibc_minor_version <= UMA_LINUX_GLIBC_2_19) {
glibc_version_result =
static_cast<UMALinuxGlibcVersion>(translated_glibc_minor_version);
}
}
}
UMA_HISTOGRAM_ENUMERATION("Linux.GlibcVersion", glibc_version_result,
UMA_LINUX_GLIBC_VERSION_COUNT);
#endif
}
void RecordTouchEventState() {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
const std::string touch_enabled_switch =
command_line.HasSwitch(switches::kTouchEvents) ?
command_line.GetSwitchValueASCII(switches::kTouchEvents) :
switches::kTouchEventsAuto;
UMATouchEventsState state;
if (touch_enabled_switch.empty() ||
touch_enabled_switch == switches::kTouchEventsEnabled) {
state = UMA_TOUCH_EVENTS_ENABLED;
} else if (touch_enabled_switch == switches::kTouchEventsAuto) {
state = ui::IsTouchDevicePresent() ?
UMA_TOUCH_EVENTS_AUTO_ENABLED : UMA_TOUCH_EVENTS_AUTO_DISABLED;
} else if (touch_enabled_switch == switches::kTouchEventsDisabled) {
state = UMA_TOUCH_EVENTS_DISABLED;
} else {
NOTREACHED();
return;
}
UMA_HISTOGRAM_ENUMERATION("Touchscreen.TouchEventsEnabled", state,
UMA_TOUCH_EVENTS_STATE_COUNT);
}
}
ChromeBrowserMainExtraPartsMetrics::ChromeBrowserMainExtraPartsMetrics() {
}
ChromeBrowserMainExtraPartsMetrics::~ChromeBrowserMainExtraPartsMetrics() {
}
void ChromeBrowserMainExtraPartsMetrics::PreProfileInit() {
RecordMicroArchitectureStats();
}
void ChromeBrowserMainExtraPartsMetrics::PreBrowserStart() {
about_flags::PrefServiceFlagsStorage flags_storage_(
g_browser_process->local_state());
about_flags::RecordUMAStatistics(&flags_storage_);
}
void ChromeBrowserMainExtraPartsMetrics::PostBrowserStart() {
RecordLinuxGlibcVersion();
RecordTouchEventState();
const int kStartupMetricsGatheringDelaySeconds = 45;
content::BrowserThread::GetBlockingPool()->PostDelayedTask(
FROM_HERE,
base::Bind(&RecordStartupMetricsOnBlockingPool),
base::TimeDelta::FromSeconds(kStartupMetricsGatheringDelaySeconds));
}
namespace chrome {
void AddMetricsExtraParts(ChromeBrowserMainParts* main_parts) {
main_parts->AddParts(new ChromeBrowserMainExtraPartsMetrics());
}
}