diff options
author | jeremy <jeremy@chromium.org> | 2014-11-06 10:47:10 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-06 18:47:23 +0000 |
commit | ba4eca9bf6691e4ed55eee55a0bcac1a932b7688 (patch) | |
tree | f0d265c69ef707893ca877a8642176d58cb04041 | |
parent | 5fc1223ad2f83c6ee3b285a73f86f927f3e348e4 (diff) | |
download | chromium_src-ba4eca9bf6691e4ed55eee55a0bcac1a932b7688.zip chromium_src-ba4eca9bf6691e4ed55eee55a0bcac1a932b7688.tar.gz chromium_src-ba4eca9bf6691e4ed55eee55a0bcac1a932b7688.tar.bz2 |
UMA: Set Hardware model class on Mac.
Record the hardware model on Mac e.g. MacPro1,1 .
BUG=429487
Review URL: https://codereview.chromium.org/699173002
Cr-Commit-Position: refs/heads/master@{#303054}
-rw-r--r-- | base/sys_info.cc | 6 | ||||
-rw-r--r-- | base/sys_info.h | 6 | ||||
-rw-r--r-- | base/sys_info_mac.cc | 8 | ||||
-rw-r--r-- | base/sys_info_unittest.cc | 7 | ||||
-rw-r--r-- | components/metrics/metrics_log.cc | 5 |
5 files changed, 30 insertions, 2 deletions
diff --git a/base/sys_info.cc b/base/sys_info.cc index 0b3b317..cb93480 100644 --- a/base/sys_info.cc +++ b/base/sys_info.cc @@ -44,6 +44,12 @@ bool SysInfo::IsLowEndDevice() { } #endif +#if !defined(OS_MACOSX) || defined(OS_IOS) +std::string SysInfo::HardwareModelName() { + return std::string(); +} +#endif + // static int64 SysInfo::Uptime() { // This code relies on an implementation detail of TimeTicks::Now() - that diff --git a/base/sys_info.h b/base/sys_info.h index d24acdf..660343d 100644 --- a/base/sys_info.h +++ b/base/sys_info.h @@ -51,6 +51,12 @@ class BASE_EXPORT SysInfo { // Returns system uptime in milliseconds. static int64 Uptime(); + // Returns a descriptive string for the current machine model or an empty + // string if machime model is unknown or an error occured. + // e.g. MacPro1,1 on Mac. + // Only implemented on OS X, will return an empty string on other platforms. + static std::string HardwareModelName(); + // Returns the name of the host operating system. static std::string OperatingSystemName(); diff --git a/base/sys_info_mac.cc b/base/sys_info_mac.cc index 57e1f83..18df624 100644 --- a/base/sys_info_mac.cc +++ b/base/sys_info_mac.cc @@ -85,4 +85,12 @@ std::string SysInfo::CPUModelName() { return std::string(); } +std::string SysInfo::HardwareModelName() { + char model[256]; + size_t len = sizeof(model); + if (sysctlbyname("hw.model", model, &len, NULL, 0) == 0) + return std::string(model, 0, len); + return std::string(); +} + } // namespace base diff --git a/base/sys_info_unittest.cc b/base/sys_info_unittest.cc index 29409ee..15ae098 100644 --- a/base/sys_info_unittest.cc +++ b/base/sys_info_unittest.cc @@ -65,6 +65,13 @@ TEST_F(SysInfoTest, Uptime) { EXPECT_GT(up_time_2, up_time_1); } +#if defined(OS_MACOSX) && !defined(OS_IOS) +TEST_F(SysInfoTest, HardwareModelName) { + std::string hardware_model = base::SysInfo::HardwareModelName(); + EXPECT_FALSE(hardware_model.empty()); +} +#endif + #if defined(OS_CHROMEOS) TEST_F(SysInfoTest, GoogleChromeOSVersionNumbers) { diff --git a/components/metrics/metrics_log.cc b/components/metrics/metrics_log.cc index 8764a73..2ea6f89 100644 --- a/components/metrics/metrics_log.cc +++ b/components/metrics/metrics_log.cc @@ -351,8 +351,9 @@ void MetricsLog::RecordEnvironment( SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware(); - // By default, the hardware class is empty (i.e., unknown). - hardware->set_hardware_class(std::string()); + // HardwareModelName() will return an empty string on platforms where it's + // not implemented or if an error occured. + hardware->set_hardware_class(base::SysInfo::HardwareModelName()); hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture()); hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB()); |