summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorgunsch <gunsch@chromium.org>2014-09-15 17:03:32 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-16 00:05:44 +0000
commit1afc65175c84ddf6087f65da818bbdbba6d28101 (patch)
tree1c4edefc4ee98a2ca85815bd545ba5fd9684aba0 /components
parent0b527c1ef9f0794742e8ea004fbaf7ecea2f4cef (diff)
downloadchromium_src-1afc65175c84ddf6087f65da818bbdbba6d28101.zip
chromium_src-1afc65175c84ddf6087f65da818bbdbba6d28101.tar.gz
chromium_src-1afc65175c84ddf6087f65da818bbdbba6d28101.tar.bz2
Moves GPUMetricsProvider to //components/metrics.
R=asvitkine@chromium.org,isherman@chromium.org BUG=404791 Review URL: https://codereview.chromium.org/523273003 Cr-Commit-Position: refs/heads/master@{#294935}
Diffstat (limited to 'components')
-rw-r--r--components/components_tests.gyp2
-rw-r--r--components/metrics.gypi16
-rw-r--r--components/metrics/BUILD.gn15
-rw-r--r--components/metrics/gpu/DEPS5
-rw-r--r--components/metrics/gpu/gpu_metrics_provider.cc111
-rw-r--r--components/metrics/gpu/gpu_metrics_provider.h42
-rw-r--r--components/metrics/gpu/gpu_metrics_provider_unittest.cc68
7 files changed, 259 insertions, 0 deletions
diff --git a/components/components_tests.gyp b/components/components_tests.gyp
index b3f9ed3..837921e 100644
--- a/components/components_tests.gyp
+++ b/components/components_tests.gyp
@@ -366,6 +366,7 @@
# Dependencies of metrics
'components.gyp:metrics',
+ 'components.gyp:metrics_gpu',
'components.gyp:metrics_net',
'components.gyp:metrics_test_support',
@@ -449,6 +450,7 @@
'sources': [
'autofill/content/renderer/renderer_save_password_progress_logger_unittest.cc',
'dom_distiller/content/dom_distiller_viewer_source_unittest.cc',
+ 'metrics/gpu/gpu_metrics_provider_unittest.cc',
'power/origin_power_map_unittest.cc',
],
'dependencies': [
diff --git a/components/metrics.gypi b/components/metrics.gypi
index 29e52b2..dafeb0e 100644
--- a/components/metrics.gypi
+++ b/components/metrics.gypi
@@ -68,6 +68,22 @@
],
},
{
+ # GN version: //components/metrics:gpu
+ 'target_name': 'metrics_gpu',
+ 'type': 'static_library',
+ 'include_dirs': [
+ '..',
+ ],
+ 'dependencies': [
+ 'component_metrics_proto',
+ 'metrics',
+ ],
+ 'sources': [
+ 'metrics/gpu/gpu_metrics_provider.cc',
+ 'metrics/gpu/gpu_metrics_provider.h',
+ ],
+ },
+ {
# GN version: //components/metrics:net
'target_name': 'metrics_net',
'type': 'static_library',
diff --git a/components/metrics/BUILD.gn b/components/metrics/BUILD.gn
index d91a4fa..8179e2746 100644
--- a/components/metrics/BUILD.gn
+++ b/components/metrics/BUILD.gn
@@ -52,6 +52,21 @@ source_set("metrics") {
forward_dependent_configs_from = [ "//components/metrics/proto" ]
}
+# GYP version: components/metrics.gypi:metrics_gpu
+source_set("gpu") {
+ sources = [
+ "gpu/gpu_metrics_provider.cc",
+ "gpu/gpu_metrics_provider.h",
+ ]
+
+ deps = [
+ ":metrics",
+ "//gpu/config",
+ ]
+
+ forward_dependent_configs_from = [ ":metrics" ]
+}
+
# GYP version: components/metrics.gypi:metrics_net
static_library("net") {
sources = [
diff --git a/components/metrics/gpu/DEPS b/components/metrics/gpu/DEPS
new file mode 100644
index 0000000..537521e
--- /dev/null
+++ b/components/metrics/gpu/DEPS
@@ -0,0 +1,5 @@
+include_rules = [
+ "+content/public/browser",
+ "+gpu/config",
+ "+ui/gfx",
+]
diff --git a/components/metrics/gpu/gpu_metrics_provider.cc b/components/metrics/gpu/gpu_metrics_provider.cc
new file mode 100644
index 0000000..ba81e7b
--- /dev/null
+++ b/components/metrics/gpu/gpu_metrics_provider.cc
@@ -0,0 +1,111 @@
+// 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 "components/metrics/gpu/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"
+
+namespace metrics {
+
+#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(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(
+ SystemProfileProto* system_profile_proto) {
+ SystemProfileProto::Hardware* hardware =
+ system_profile_proto->mutable_hardware();
+
+ const gpu::GPUInfo& gpu_info =
+ content::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
+}
+
+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();
+}
+
+} // namespace metrics
diff --git a/components/metrics/gpu/gpu_metrics_provider.h b/components/metrics/gpu/gpu_metrics_provider.h
new file mode 100644
index 0000000..d10db56
--- /dev/null
+++ b/components/metrics/gpu/gpu_metrics_provider.h
@@ -0,0 +1,42 @@
+// 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 COMPONENTS_METRICS_GPU_GPU_METRICS_PROVIDER_H_
+#define COMPONENTS_METRICS_GPU_GPU_METRICS_PROVIDER_H_
+
+#include "base/basictypes.h"
+#include "components/metrics/metrics_provider.h"
+#include "ui/gfx/size.h"
+
+namespace metrics {
+
+// GPUMetricsProvider provides GPU-related metrics.
+class GPUMetricsProvider : public MetricsProvider {
+ public:
+ GPUMetricsProvider();
+ virtual ~GPUMetricsProvider();
+
+ // MetricsProvider:
+ virtual void ProvideSystemProfileMetrics(
+ 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);
+};
+
+} // namespace metrics
+
+#endif // COMPONENTS_METRICS_GPU_GPU_METRICS_PROVIDER_H_
diff --git a/components/metrics/gpu/gpu_metrics_provider_unittest.cc b/components/metrics/gpu/gpu_metrics_provider_unittest.cc
new file mode 100644
index 0000000..1aea17a
--- /dev/null
+++ b/components/metrics/gpu/gpu_metrics_provider_unittest.cc
@@ -0,0 +1,68 @@
+// 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 "components/metrics/gpu/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 metrics {
+
+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());
+}
+
+} // namespace metrics