Commit 2d8c6e66 authored by blundell@chromium.org's avatar blundell@chromium.org

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
parent 46cb853b
// 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();
}
// 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_
// 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());
}
...@@ -33,10 +33,7 @@ ...@@ -33,10 +33,7 @@
#include "components/metrics/proto/system_profile.pb.h" #include "components/metrics/proto/system_profile.pb.h"
#include "components/nacl/common/nacl_process_type.h" #include "components/nacl/common/nacl_process_type.h"
#include "components/variations/active_field_trials.h" #include "components/variations/active_field_trials.h"
#include "content/public/browser/gpu_data_manager.h"
#include "content/public/common/content_client.h" #include "content/public/common/content_client.h"
#include "gpu/config/gpu_info.h"
#include "ui/gfx/screen.h"
#include "url/gurl.h" #include "url/gurl.h"
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
...@@ -54,7 +51,6 @@ extern "C" IMAGE_DOS_HEADER __ImageBase; ...@@ -54,7 +51,6 @@ extern "C" IMAGE_DOS_HEADER __ImageBase;
#include "chrome/browser/metrics/metrics_log_chromeos.h" #include "chrome/browser/metrics/metrics_log_chromeos.h"
#endif // OS_CHROMEOS #endif // OS_CHROMEOS
using content::GpuDataManager;
using metrics::MetricsLogBase; using metrics::MetricsLogBase;
using metrics::ProfilerEventProto; using metrics::ProfilerEventProto;
using metrics::SystemProfileProto; using metrics::SystemProfileProto;
...@@ -178,44 +174,6 @@ void WriteProfilerData(const ProcessDataSnapshot& profiler_data, ...@@ -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 // Round a timestamp measured in seconds since epoch to one with a granularity
// of an hour. This can be used before uploaded potentially sensitive // of an hour. This can be used before uploaded potentially sensitive
// timestamps. // timestamps.
...@@ -315,20 +273,6 @@ PrefService* MetricsLog::GetPrefService() { ...@@ -315,20 +273,6 @@ PrefService* MetricsLog::GetPrefService() {
return g_browser_process->local_state(); 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( void MetricsLog::GetFieldTrialIds(
std::vector<ActiveGroupId>* field_trial_ids) const { std::vector<ActiveGroupId>* field_trial_ids) const {
variations::GetFieldTrialActiveGroupIds(field_trial_ids); variations::GetFieldTrialActiveGroupIds(field_trial_ids);
...@@ -443,31 +387,6 @@ void MetricsLog::RecordEnvironment( ...@@ -443,31 +387,6 @@ void MetricsLog::RecordEnvironment(
cpu->set_vendor_name(cpu_info.vendor_name()); cpu->set_vendor_name(cpu_info.vendor_name());
cpu->set_signature(cpu_info.signature()); 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()); extension_metrics_.WriteExtensionList(uma_proto()->mutable_system_profile());
std::vector<ActiveGroupId> field_trial_ids; std::vector<ActiveGroupId> field_trial_ids;
......
...@@ -110,15 +110,6 @@ class MetricsLog : public metrics::MetricsLogBase { ...@@ -110,15 +110,6 @@ class MetricsLog : public metrics::MetricsLogBase {
// Returns the PrefService from which to log metrics data. // Returns the PrefService from which to log metrics data.
virtual PrefService* GetPrefService(); 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 // Fills |field_trial_ids| with the list of initialized field trials name and
// group ids. // group ids.
virtual void GetFieldTrialIds( virtual void GetFieldTrialIds(
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/size.h"
#include "url/gurl.h" #include "url/gurl.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
...@@ -80,10 +79,6 @@ const int64 kInstallDateExpected = 1373050800; // Computed from kInstallDate. ...@@ -80,10 +79,6 @@ const int64 kInstallDateExpected = 1373050800; // Computed from kInstallDate.
const int64 kEnabledDate = 1373001211; const int64 kEnabledDate = 1373001211;
const int64 kEnabledDateExpected = 1373000400; // Computed from kEnabledDate. const int64 kEnabledDateExpected = 1373000400; // Computed from kEnabledDate.
const int kSessionId = 127; const int kSessionId = 127;
const int kScreenWidth = 1024;
const int kScreenHeight = 768;
const int kScreenCount = 3;
const float kScreenScaleFactor = 2;
const variations::ActiveGroupId kFieldTrialIds[] = { const variations::ActiveGroupId kFieldTrialIds[] = {
{37, 43}, {37, 43},
{13, 47}, {13, 47},
...@@ -172,18 +167,6 @@ class TestMetricsLog : public MetricsLog { ...@@ -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|. // Scoped PrefsService, which may not be used if |prefs_ != &scoped_prefs|.
TestingPrefServiceSimple scoped_prefs_; TestingPrefServiceSimple scoped_prefs_;
// Weak pointer to the PrefsService used by this log. // Weak pointer to the PrefsService used by this log.
...@@ -265,10 +248,6 @@ class MetricsLogTest : public testing::Test { ...@@ -265,10 +248,6 @@ class MetricsLogTest : public testing::Test {
const metrics::SystemProfileProto::Hardware& hardware = const metrics::SystemProfileProto::Hardware& hardware =
system_profile.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.has_cpu());
EXPECT_TRUE(hardware.cpu().has_vendor_name()); EXPECT_TRUE(hardware.cpu().has_vendor_name());
......
...@@ -186,6 +186,7 @@ ...@@ -186,6 +186,7 @@
#include "chrome/browser/io_thread.h" #include "chrome/browser/io_thread.h"
#include "chrome/browser/metrics/chrome_stability_metrics_provider.h" #include "chrome/browser/metrics/chrome_stability_metrics_provider.h"
#include "chrome/browser/metrics/compression_utils.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_log.h"
#include "chrome/browser/metrics/metrics_state_manager.h" #include "chrome/browser/metrics/metrics_state_manager.h"
#include "chrome/browser/metrics/network_metrics_provider.h" #include "chrome/browser/metrics/network_metrics_provider.h"
...@@ -415,6 +416,8 @@ MetricsService::MetricsService(metrics::MetricsStateManager* state_manager, ...@@ -415,6 +416,8 @@ MetricsService::MetricsService(metrics::MetricsStateManager* state_manager,
scoped_ptr<metrics::MetricsProvider>(new OmniboxMetricsProvider)); scoped_ptr<metrics::MetricsProvider>(new OmniboxMetricsProvider));
RegisterMetricsProvider( RegisterMetricsProvider(
scoped_ptr<metrics::MetricsProvider>(new ChromeStabilityMetricsProvider)); scoped_ptr<metrics::MetricsProvider>(new ChromeStabilityMetricsProvider));
RegisterMetricsProvider(
scoped_ptr<metrics::MetricsProvider>(new GPUMetricsProvider()));
#if defined(OS_WIN) #if defined(OS_WIN)
google_update_metrics_provider_ = new GoogleUpdateMetricsProviderWin; google_update_metrics_provider_ = new GoogleUpdateMetricsProviderWin;
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "components/variations/metrics_util.h" #include "components/variations/metrics_util.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/size.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chrome/browser/metrics/metrics_log_chromeos.h" #include "chrome/browser/metrics/metrics_log_chromeos.h"
...@@ -70,18 +69,6 @@ class TestMetricsLog : public MetricsLog { ...@@ -70,18 +69,6 @@ class TestMetricsLog : public MetricsLog {
virtual ~TestMetricsLog() {} virtual ~TestMetricsLog() {}
private: 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); DISALLOW_COPY_AND_ASSIGN(TestMetricsLog);
}; };
......
...@@ -1199,6 +1199,8 @@ ...@@ -1199,6 +1199,8 @@
'browser/metrics/field_trial_synchronizer.h', 'browser/metrics/field_trial_synchronizer.h',
'browser/metrics/google_update_metrics_provider_win.cc', 'browser/metrics/google_update_metrics_provider_win.cc',
'browser/metrics/google_update_metrics_provider_win.h', '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/metric_event_duration_details.h',
'browser/metrics/metrics_log.cc', 'browser/metrics/metrics_log.cc',
'browser/metrics/metrics_log.h', 'browser/metrics/metrics_log.h',
......
...@@ -1084,6 +1084,7 @@ ...@@ -1084,6 +1084,7 @@
'browser/metrics/cloned_install_detector_unittest.cc', 'browser/metrics/cloned_install_detector_unittest.cc',
'browser/metrics/compression_utils_unittest.cc', 'browser/metrics/compression_utils_unittest.cc',
'browser/metrics/extension_metrics_unittest.cc', 'browser/metrics/extension_metrics_unittest.cc',
'browser/metrics/gpu_metrics_provider_unittest.cc',
'browser/metrics/metrics_log_unittest.cc', 'browser/metrics/metrics_log_unittest.cc',
'browser/metrics/metrics_service_unittest.cc', 'browser/metrics/metrics_service_unittest.cc',
'browser/metrics/metrics_state_manager_unittest.cc', 'browser/metrics/metrics_state_manager_unittest.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment