summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorblundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-23 11:02:25 +0000
committerblundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-23 11:02:25 +0000
commit2d8c6e666fb5ba1fc1bf534393961f2ceb6fa36c (patch)
tree8182dfd6562b892a0457028f586188526f14f6e7
parent46cb853b1b3ba42875c369a7ba8c1942cba8d58f (diff)
downloadchromium_src-2d8c6e666fb5ba1fc1bf534393961f2ceb6fa36c.zip
chromium_src-2d8c6e666fb5ba1fc1bf534393961f2ceb6fa36c.tar.gz
chromium_src-2d8c6e666fb5ba1fc1bf534393961f2ceb6fa36c.tar.bz2
Create GPUMetricsProvider.
This CL moves the GPU-related system profile metrics logging out of MetricsLog into GPUMetricsProvider, which is a metrics::MetricsProvider. A new unittest is created to provide the related test coverage that was previously provided in the MetricsLog unittest. BUG=374228 R=asvitkine@chromium.org, isherman@chromium.org Review URL: https://codereview.chromium.org/291163006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272484 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/metrics/gpu_metrics_provider.cc108
-rw-r--r--chrome/browser/metrics/gpu_metrics_provider.h38
-rw-r--r--chrome/browser/metrics/gpu_metrics_provider_unittest.cc64
-rw-r--r--chrome/browser/metrics/metrics_log.cc81
-rw-r--r--chrome/browser/metrics/metrics_log.h9
-rw-r--r--chrome/browser/metrics/metrics_log_unittest.cc21
-rw-r--r--chrome/browser/metrics/metrics_service.cc3
-rw-r--r--chrome/browser/metrics/metrics_service_unittest.cc13
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/chrome_tests_unit.gypi1
10 files changed, 216 insertions, 124 deletions
diff --git a/chrome/browser/metrics/gpu_metrics_provider.cc b/chrome/browser/metrics/gpu_metrics_provider.cc
new file mode 100644
index 0000000..34b8a39
--- /dev/null
+++ b/chrome/browser/metrics/gpu_metrics_provider.cc
@@ -0,0 +1,108 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/metrics/gpu_metrics_provider.h"
+
+#include "components/metrics/proto/system_profile.pb.h"
+#include "content/public/browser/gpu_data_manager.h"
+#include "gpu/config/gpu_info.h"
+#include "ui/gfx/screen.h"
+
+#if defined(OS_WIN)
+
+#include <windows.h>
+
+namespace {
+
+struct ScreenDPIInformation {
+ double max_dpi_x;
+ double max_dpi_y;
+};
+
+// Called once for each connected monitor.
+BOOL CALLBACK GetMonitorDPICallback(HMONITOR, HDC hdc, LPRECT, LPARAM dwData) {
+ const double kMillimetersPerInch = 25.4;
+ ScreenDPIInformation* screen_info =
+ reinterpret_cast<ScreenDPIInformation*>(dwData);
+ // Size of screen, in mm.
+ DWORD size_x = GetDeviceCaps(hdc, HORZSIZE);
+ DWORD size_y = GetDeviceCaps(hdc, VERTSIZE);
+ double dpi_x = (size_x > 0) ?
+ GetDeviceCaps(hdc, HORZRES) / (size_x / kMillimetersPerInch) : 0;
+ double dpi_y = (size_y > 0) ?
+ GetDeviceCaps(hdc, VERTRES) / (size_y / kMillimetersPerInch) : 0;
+ screen_info->max_dpi_x = std::max(dpi_x, screen_info->max_dpi_x);
+ screen_info->max_dpi_y = std::max(dpi_y, screen_info->max_dpi_y);
+ return TRUE;
+}
+
+void WriteScreenDPIInformationProto(
+ metrics::SystemProfileProto::Hardware* hardware) {
+ HDC desktop_dc = GetDC(NULL);
+ if (desktop_dc) {
+ ScreenDPIInformation si = {0, 0};
+ if (EnumDisplayMonitors(desktop_dc, NULL, GetMonitorDPICallback,
+ reinterpret_cast<LPARAM>(&si))) {
+ hardware->set_max_dpi_x(si.max_dpi_x);
+ hardware->set_max_dpi_y(si.max_dpi_y);
+ }
+ ReleaseDC(GetDesktopWindow(), desktop_dc);
+ }
+}
+
+} // namespace
+
+#endif // defined(OS_WIN)
+
+GPUMetricsProvider::GPUMetricsProvider() {
+}
+
+GPUMetricsProvider::~GPUMetricsProvider() {
+}
+
+void GPUMetricsProvider::ProvideSystemProfileMetrics(
+ metrics::SystemProfileProto* system_profile_proto) {
+ metrics::SystemProfileProto::Hardware* hardware =
+ system_profile_proto->mutable_hardware();
+
+ const gpu::GPUInfo& gpu_info =
+ content::GpuDataManager::GetInstance()->GetGPUInfo();
+ metrics::SystemProfileProto::Hardware::Graphics* gpu =
+ hardware->mutable_gpu();
+ gpu->set_vendor_id(gpu_info.gpu.vendor_id);
+ gpu->set_device_id(gpu_info.gpu.device_id);
+ gpu->set_driver_version(gpu_info.driver_version);
+ gpu->set_driver_date(gpu_info.driver_date);
+ metrics::SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
+ gpu_performance = gpu->mutable_performance_statistics();
+ gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
+ gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
+ gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
+ gpu->set_gl_vendor(gpu_info.gl_vendor);
+ gpu->set_gl_renderer(gpu_info.gl_renderer);
+
+ const gfx::Size display_size = GetScreenSize();
+ hardware->set_primary_screen_width(display_size.width());
+ hardware->set_primary_screen_height(display_size.height());
+ hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor());
+ hardware->set_screen_count(GetScreenCount());
+
+#if defined(OS_WIN)
+ WriteScreenDPIInformationProto(hardware);
+#endif
+}
+
+gfx::Size GPUMetricsProvider::GetScreenSize() const {
+ return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel();
+}
+
+float GPUMetricsProvider::GetScreenDeviceScaleFactor() const {
+ return gfx::Screen::GetNativeScreen()->
+ GetPrimaryDisplay().device_scale_factor();
+}
+
+int GPUMetricsProvider::GetScreenCount() const {
+ // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312
+ return gfx::Screen::GetNativeScreen()->GetNumDisplays();
+}
diff --git a/chrome/browser/metrics/gpu_metrics_provider.h b/chrome/browser/metrics/gpu_metrics_provider.h
new file mode 100644
index 0000000..2c3a3f0
--- /dev/null
+++ b/chrome/browser/metrics/gpu_metrics_provider.h
@@ -0,0 +1,38 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_METRICS_GPU_METRICS_PROVIDER_H_
+#define CHROME_BROWSER_METRICS_GPU_METRICS_PROVIDER_H_
+
+#include "base/basictypes.h"
+#include "components/metrics/metrics_provider.h"
+#include "ui/gfx/size.h"
+
+// GPUMetricsProvider provides GPU-related metrics.
+class GPUMetricsProvider : public metrics::MetricsProvider {
+ public:
+ GPUMetricsProvider();
+ virtual ~GPUMetricsProvider();
+
+ // metrics::MetricsProvider:
+ virtual void ProvideSystemProfileMetrics(
+ metrics::SystemProfileProto* system_profile_proto) OVERRIDE;
+
+ protected:
+ // Exposed for the sake of mocking in test code.
+
+ // Returns the screen size for the primary monitor.
+ virtual gfx::Size GetScreenSize() const;
+
+ // Returns the device scale factor for the primary monitor.
+ virtual float GetScreenDeviceScaleFactor() const;
+
+ // Returns the number of monitors the user is using.
+ virtual int GetScreenCount() const;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(GPUMetricsProvider);
+};
+
+#endif // CHROME_BROWSER_METRICS_GPU_METRICS_PROVIDER_H_
diff --git a/chrome/browser/metrics/gpu_metrics_provider_unittest.cc b/chrome/browser/metrics/gpu_metrics_provider_unittest.cc
new file mode 100644
index 0000000..6c753ba
--- /dev/null
+++ b/chrome/browser/metrics/gpu_metrics_provider_unittest.cc
@@ -0,0 +1,64 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/metrics/gpu_metrics_provider.h"
+
+#include "base/basictypes.h"
+#include "components/metrics/proto/chrome_user_metrics_extension.pb.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gfx/size.h"
+
+namespace {
+
+const int kScreenWidth = 1024;
+const int kScreenHeight = 768;
+const int kScreenCount = 3;
+const float kScreenScaleFactor = 2;
+
+class TestGPUMetricsProvider : public GPUMetricsProvider {
+ public:
+ TestGPUMetricsProvider() {}
+ virtual ~TestGPUMetricsProvider() {}
+
+ private:
+ virtual gfx::Size GetScreenSize() const OVERRIDE {
+ return gfx::Size(kScreenWidth, kScreenHeight);
+ }
+
+ virtual float GetScreenDeviceScaleFactor() const OVERRIDE {
+ return kScreenScaleFactor;
+ }
+
+ virtual int GetScreenCount() const OVERRIDE {
+ return kScreenCount;
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(TestGPUMetricsProvider);
+};
+
+} // namespace
+
+class GPUMetricsProviderTest : public testing::Test {
+ public:
+ GPUMetricsProviderTest() {}
+ virtual ~GPUMetricsProviderTest() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(GPUMetricsProviderTest);
+};
+
+TEST_F(GPUMetricsProviderTest, ProvideSystemProfileMetrics) {
+ TestGPUMetricsProvider provider;
+ metrics::ChromeUserMetricsExtension uma_proto;
+
+ provider.ProvideSystemProfileMetrics(uma_proto.mutable_system_profile());
+
+ // Check that the system profile has the correct values set.
+ const metrics::SystemProfileProto::Hardware& hardware =
+ uma_proto.system_profile().hardware();
+ EXPECT_EQ(kScreenWidth, hardware.primary_screen_width());
+ EXPECT_EQ(kScreenHeight, hardware.primary_screen_height());
+ EXPECT_EQ(kScreenScaleFactor, hardware.primary_screen_scale_factor());
+ EXPECT_EQ(kScreenCount, hardware.screen_count());
+}
diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc
index b421c74..72c8269 100644
--- a/chrome/browser/metrics/metrics_log.cc
+++ b/chrome/browser/metrics/metrics_log.cc
@@ -33,10 +33,7 @@
#include "components/metrics/proto/system_profile.pb.h"
#include "components/nacl/common/nacl_process_type.h"
#include "components/variations/active_field_trials.h"
-#include "content/public/browser/gpu_data_manager.h"
#include "content/public/common/content_client.h"
-#include "gpu/config/gpu_info.h"
-#include "ui/gfx/screen.h"
#include "url/gurl.h"
#if defined(OS_ANDROID)
@@ -54,7 +51,6 @@ extern "C" IMAGE_DOS_HEADER __ImageBase;
#include "chrome/browser/metrics/metrics_log_chromeos.h"
#endif // OS_CHROMEOS
-using content::GpuDataManager;
using metrics::MetricsLogBase;
using metrics::ProfilerEventProto;
using metrics::SystemProfileProto;
@@ -178,44 +174,6 @@ void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
}
}
-#if defined(OS_WIN)
-struct ScreenDPIInformation {
- double max_dpi_x;
- double max_dpi_y;
-};
-
-// Called once for each connected monitor.
-BOOL CALLBACK GetMonitorDPICallback(HMONITOR, HDC hdc, LPRECT, LPARAM dwData) {
- const double kMillimetersPerInch = 25.4;
- ScreenDPIInformation* screen_info =
- reinterpret_cast<ScreenDPIInformation*>(dwData);
- // Size of screen, in mm.
- DWORD size_x = GetDeviceCaps(hdc, HORZSIZE);
- DWORD size_y = GetDeviceCaps(hdc, VERTSIZE);
- double dpi_x = (size_x > 0) ?
- GetDeviceCaps(hdc, HORZRES) / (size_x / kMillimetersPerInch) : 0;
- double dpi_y = (size_y > 0) ?
- GetDeviceCaps(hdc, VERTRES) / (size_y / kMillimetersPerInch) : 0;
- screen_info->max_dpi_x = std::max(dpi_x, screen_info->max_dpi_x);
- screen_info->max_dpi_y = std::max(dpi_y, screen_info->max_dpi_y);
- return TRUE;
-}
-
-void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) {
- HDC desktop_dc = GetDC(NULL);
- if (desktop_dc) {
- ScreenDPIInformation si = {0, 0};
- if (EnumDisplayMonitors(desktop_dc, NULL, GetMonitorDPICallback,
- reinterpret_cast<LPARAM>(&si))) {
- hardware->set_max_dpi_x(si.max_dpi_x);
- hardware->set_max_dpi_y(si.max_dpi_y);
- }
- ReleaseDC(GetDesktopWindow(), desktop_dc);
- }
-}
-
-#endif // defined(OS_WIN)
-
// Round a timestamp measured in seconds since epoch to one with a granularity
// of an hour. This can be used before uploaded potentially sensitive
// timestamps.
@@ -315,20 +273,6 @@ PrefService* MetricsLog::GetPrefService() {
return g_browser_process->local_state();
}
-gfx::Size MetricsLog::GetScreenSize() const {
- return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel();
-}
-
-float MetricsLog::GetScreenDeviceScaleFactor() const {
- return gfx::Screen::GetNativeScreen()->
- GetPrimaryDisplay().device_scale_factor();
-}
-
-int MetricsLog::GetScreenCount() const {
- // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312
- return gfx::Screen::GetNativeScreen()->GetNumDisplays();
-}
-
void MetricsLog::GetFieldTrialIds(
std::vector<ActiveGroupId>* field_trial_ids) const {
variations::GetFieldTrialActiveGroupIds(field_trial_ids);
@@ -443,31 +387,6 @@ void MetricsLog::RecordEnvironment(
cpu->set_vendor_name(cpu_info.vendor_name());
cpu->set_signature(cpu_info.signature());
- const gpu::GPUInfo& gpu_info =
- GpuDataManager::GetInstance()->GetGPUInfo();
- SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
- gpu->set_vendor_id(gpu_info.gpu.vendor_id);
- gpu->set_device_id(gpu_info.gpu.device_id);
- gpu->set_driver_version(gpu_info.driver_version);
- gpu->set_driver_date(gpu_info.driver_date);
- SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
- gpu_performance = gpu->mutable_performance_statistics();
- gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
- gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
- gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
- gpu->set_gl_vendor(gpu_info.gl_vendor);
- gpu->set_gl_renderer(gpu_info.gl_renderer);
-
- const gfx::Size display_size = GetScreenSize();
- hardware->set_primary_screen_width(display_size.width());
- hardware->set_primary_screen_height(display_size.height());
- hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor());
- hardware->set_screen_count(GetScreenCount());
-
-#if defined(OS_WIN)
- WriteScreenDPIInformationProto(hardware);
-#endif
-
extension_metrics_.WriteExtensionList(uma_proto()->mutable_system_profile());
std::vector<ActiveGroupId> field_trial_ids;
diff --git a/chrome/browser/metrics/metrics_log.h b/chrome/browser/metrics/metrics_log.h
index 27f54a4..b22aefd 100644
--- a/chrome/browser/metrics/metrics_log.h
+++ b/chrome/browser/metrics/metrics_log.h
@@ -110,15 +110,6 @@ class MetricsLog : public metrics::MetricsLogBase {
// Returns the PrefService from which to log metrics data.
virtual PrefService* GetPrefService();
- // Returns the screen size for the primary monitor.
- virtual gfx::Size GetScreenSize() const;
-
- // Returns the device scale factor for the primary monitor.
- virtual float GetScreenDeviceScaleFactor() const;
-
- // Returns the number of monitors the user is using.
- virtual int GetScreenCount() const;
-
// Fills |field_trial_ids| with the list of initialized field trials name and
// group ids.
virtual void GetFieldTrialIds(
diff --git a/chrome/browser/metrics/metrics_log_unittest.cc b/chrome/browser/metrics/metrics_log_unittest.cc
index 2a52719..43b59cb 100644
--- a/chrome/browser/metrics/metrics_log_unittest.cc
+++ b/chrome/browser/metrics/metrics_log_unittest.cc
@@ -33,7 +33,6 @@
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/gfx/size.h"
#include "url/gurl.h"
#if defined(OS_CHROMEOS)
@@ -80,10 +79,6 @@ const int64 kInstallDateExpected = 1373050800; // Computed from kInstallDate.
const int64 kEnabledDate = 1373001211;
const int64 kEnabledDateExpected = 1373000400; // Computed from kEnabledDate.
const int kSessionId = 127;
-const int kScreenWidth = 1024;
-const int kScreenHeight = 768;
-const int kScreenCount = 3;
-const float kScreenScaleFactor = 2;
const variations::ActiveGroupId kFieldTrialIds[] = {
{37, 43},
{13, 47},
@@ -172,18 +167,6 @@ class TestMetricsLog : public MetricsLog {
}
}
- virtual gfx::Size GetScreenSize() const OVERRIDE {
- return gfx::Size(kScreenWidth, kScreenHeight);
- }
-
- virtual float GetScreenDeviceScaleFactor() const OVERRIDE {
- return kScreenScaleFactor;
- }
-
- virtual int GetScreenCount() const OVERRIDE {
- return kScreenCount;
- }
-
// Scoped PrefsService, which may not be used if |prefs_ != &scoped_prefs|.
TestingPrefServiceSimple scoped_prefs_;
// Weak pointer to the PrefsService used by this log.
@@ -265,10 +248,6 @@ class MetricsLogTest : public testing::Test {
const metrics::SystemProfileProto::Hardware& hardware =
system_profile.hardware();
- EXPECT_EQ(kScreenWidth, hardware.primary_screen_width());
- EXPECT_EQ(kScreenHeight, hardware.primary_screen_height());
- EXPECT_EQ(kScreenScaleFactor, hardware.primary_screen_scale_factor());
- EXPECT_EQ(kScreenCount, hardware.screen_count());
EXPECT_TRUE(hardware.has_cpu());
EXPECT_TRUE(hardware.cpu().has_vendor_name());
diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc
index 354315a..e4a8688 100644
--- a/chrome/browser/metrics/metrics_service.cc
+++ b/chrome/browser/metrics/metrics_service.cc
@@ -186,6 +186,7 @@
#include "chrome/browser/io_thread.h"
#include "chrome/browser/metrics/chrome_stability_metrics_provider.h"
#include "chrome/browser/metrics/compression_utils.h"
+#include "chrome/browser/metrics/gpu_metrics_provider.h"
#include "chrome/browser/metrics/metrics_log.h"
#include "chrome/browser/metrics/metrics_state_manager.h"
#include "chrome/browser/metrics/network_metrics_provider.h"
@@ -415,6 +416,8 @@ MetricsService::MetricsService(metrics::MetricsStateManager* state_manager,
scoped_ptr<metrics::MetricsProvider>(new OmniboxMetricsProvider));
RegisterMetricsProvider(
scoped_ptr<metrics::MetricsProvider>(new ChromeStabilityMetricsProvider));
+ RegisterMetricsProvider(
+ scoped_ptr<metrics::MetricsProvider>(new GPUMetricsProvider()));
#if defined(OS_WIN)
google_update_metrics_provider_ = new GoogleUpdateMetricsProviderWin;
diff --git a/chrome/browser/metrics/metrics_service_unittest.cc b/chrome/browser/metrics/metrics_service_unittest.cc
index 33aea72..5cb53de 100644
--- a/chrome/browser/metrics/metrics_service_unittest.cc
+++ b/chrome/browser/metrics/metrics_service_unittest.cc
@@ -18,7 +18,6 @@
#include "components/variations/metrics_util.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/gfx/size.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/metrics/metrics_log_chromeos.h"
@@ -70,18 +69,6 @@ class TestMetricsLog : public MetricsLog {
virtual ~TestMetricsLog() {}
private:
- virtual gfx::Size GetScreenSize() const OVERRIDE {
- return gfx::Size(1024, 768);
- }
-
- virtual float GetScreenDeviceScaleFactor() const OVERRIDE {
- return 1.0f;
- }
-
- virtual int GetScreenCount() const OVERRIDE {
- return 1;
- }
-
DISALLOW_COPY_AND_ASSIGN(TestMetricsLog);
};
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 711e45c..7d99444 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1199,6 +1199,8 @@
'browser/metrics/field_trial_synchronizer.h',
'browser/metrics/google_update_metrics_provider_win.cc',
'browser/metrics/google_update_metrics_provider_win.h',
+ 'browser/metrics/gpu_metrics_provider.cc',
+ 'browser/metrics/gpu_metrics_provider.h',
'browser/metrics/metric_event_duration_details.h',
'browser/metrics/metrics_log.cc',
'browser/metrics/metrics_log.h',
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index 8b0031b..ab383a8 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -1084,6 +1084,7 @@
'browser/metrics/cloned_install_detector_unittest.cc',
'browser/metrics/compression_utils_unittest.cc',
'browser/metrics/extension_metrics_unittest.cc',
+ 'browser/metrics/gpu_metrics_provider_unittest.cc',
'browser/metrics/metrics_log_unittest.cc',
'browser/metrics/metrics_service_unittest.cc',
'browser/metrics/metrics_state_manager_unittest.cc',