Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: content/browser/devtools/devtools_system_info_handler.cc

Issue 21682002: Expose GPU information to Telemetry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactored more code into WebSocketBrowserConnection on nduca's request. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/devtools/devtools_system_info_handler.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/devtools/devtools_system_info_handler.h"
6
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/values.h"
10 #include "content/browser/devtools/devtools_protocol_constants.h"
11 #include "content/browser/gpu/gpu_data_manager_impl.h"
12 #include "gpu/config/gpu_info.h"
13
14 namespace content {
15
16 namespace {
17
18 const char kAuxAttributes[] = "auxAttributes";
19 const char kDeviceId[] = "deviceId";
20 const char kDeviceString[] = "deviceString";
21 const char kDevices[] = "devices";
22 const char kGPU[] = "gpu";
23 const char kModelName[] = "modelName";
24 const char kVendorId[] = "vendorId";
25 const char kVendorString[] = "vendorString";
26
27 class AuxGPUInfoEnumerator : public gpu::GPUInfo::Enumerator {
28 public:
29 AuxGPUInfoEnumerator(base::DictionaryValue* dictionary)
30 : dictionary_(dictionary),
31 in_aux_attributes_(false) { }
32
33 virtual void AddInt64(const char* name, int64 value) OVERRIDE {
34 if (in_aux_attributes_)
35 dictionary_->SetDouble(name, value);
36 }
37
38 virtual void AddInt(const char* name, int value) OVERRIDE {
39 if (in_aux_attributes_)
40 dictionary_->SetInteger(name, value);
41 }
42
43 virtual void AddString(const char* name, const std::string& value) OVERRIDE {
44 if (in_aux_attributes_)
45 dictionary_->SetString(name, value);
46 }
47
48 virtual void AddBool(const char* name, bool value) OVERRIDE {
49 if (in_aux_attributes_)
50 dictionary_->SetBoolean(name, value);
51 }
52
53 virtual void AddTimeDeltaInSecondsF(const char* name,
54 const base::TimeDelta& value) OVERRIDE {
55 if (in_aux_attributes_)
56 dictionary_->SetDouble(name, value.InSecondsF());
57 }
58
59 virtual void BeginGPUDevice() OVERRIDE {
60 }
61
62 virtual void EndGPUDevice() OVERRIDE {
63 }
64
65 virtual void BeginAuxAttributes() OVERRIDE {
66 in_aux_attributes_ = true;
67 }
68
69 virtual void EndAuxAttributes() OVERRIDE {
70 in_aux_attributes_ = false;
71 }
72
73 private:
74 base::DictionaryValue* dictionary_;
75 bool in_aux_attributes_;
76 };
77
78 base::DictionaryValue* GPUDeviceToDictionary(
79 const gpu::GPUInfo::GPUDevice& device) {
80 base::DictionaryValue* result = new base::DictionaryValue;
81 result->SetInteger(kVendorId, device.vendor_id);
82 result->SetInteger(kDeviceId, device.device_id);
83 result->SetString(kVendorString, device.vendor_string);
84 result->SetString(kDeviceString, device.device_string);
85 return result;
86 }
87
88 } // namespace
89
90 DevToolsSystemInfoHandler::DevToolsSystemInfoHandler() {
91 RegisterCommandHandler(devtools::SystemInfo::getInfo::kName,
92 base::Bind(&DevToolsSystemInfoHandler::OnGetInfo,
93 base::Unretained(this)));
94 }
95
96 DevToolsSystemInfoHandler::~DevToolsSystemInfoHandler() {
97 }
98
99 scoped_refptr<DevToolsProtocol::Response>
100 DevToolsSystemInfoHandler::OnGetInfo(
101 scoped_refptr<DevToolsProtocol::Command> command) {
102 gpu::GPUInfo gpu_info = GpuDataManagerImpl::GetInstance()->GetGPUInfo();
103 base::DictionaryValue* gpu_dict = new base::DictionaryValue;
104
105 base::ListValue* devices = new base::ListValue;
106 devices->Append(GPUDeviceToDictionary(gpu_info.gpu));
107 for (size_t ii = 0; ii < gpu_info.secondary_gpus.size(); ++ii) {
pfeldman 2013/08/15 05:49:47 nit: prefer iterator while iterating stl collectio
108 devices->Append(GPUDeviceToDictionary(gpu_info.secondary_gpus[ii]));
109 }
110 gpu_dict->Set(kDevices, devices);
111
112 base::DictionaryValue* aux_attributes = new base::DictionaryValue;
113 AuxGPUInfoEnumerator enumerator(aux_attributes);
114 gpu_info.EnumerateFields(&enumerator);
115 gpu_dict->Set(kAuxAttributes, aux_attributes);
116
117 base::DictionaryValue* system_dict = new base::DictionaryValue;
118 system_dict->SetString(kModelName, gpu_info.machine_model);
119 system_dict->Set(kGPU, gpu_dict);
120 return command->SuccessResponse(system_dict);
121 }
122
123 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/devtools_system_info_handler.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698