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

Side by Side Diff: chrome/browser/metrics/metrics_log.cc

Issue 9232071: Upload UMA data using protocol buffers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/metrics/metrics_log.h" 5 #include "chrome/browser/metrics/metrics_log.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/perftimer.h" 14 #include "base/perftimer.h"
15 #include "base/string_number_conversions.h"
15 #include "base/string_util.h" 16 #include "base/string_util.h"
16 #include "base/sys_info.h" 17 #include "base/sys_info.h"
17 #include "base/third_party/nspr/prtime.h" 18 #include "base/third_party/nspr/prtime.h"
18 #include "base/time.h" 19 #include "base/time.h"
19 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
20 #include "chrome/browser/autocomplete/autocomplete.h" 21 #include "chrome/browser/autocomplete/autocomplete.h"
21 #include "chrome/browser/autocomplete/autocomplete_match.h" 22 #include "chrome/browser/autocomplete/autocomplete_match.h"
22 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/plugin_prefs.h" 24 #include "chrome/browser/plugin_prefs.h"
24 #include "chrome/browser/prefs/pref_service.h" 25 #include "chrome/browser/prefs/pref_service.h"
25 #include "chrome/browser/profiles/profile_manager.h" 26 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/common/chrome_version_info.h" 27 #include "chrome/common/chrome_version_info.h"
27 #include "chrome/common/logging_chrome.h" 28 #include "chrome/common/logging_chrome.h"
29 #include "chrome/common/metrics/proto/omnibox_event.pb.h"
30 #include "chrome/common/metrics/proto/system_profile.pb.h"
28 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
29 #include "content/browser/gpu/gpu_data_manager.h" 32 #include "content/browser/gpu/gpu_data_manager.h"
33 #include "content/browser/gpu/gpu_performance_stats.h"
34 #include "content/public/browser/content_browser_client.h"
35 #include "content/public/common/content_client.h"
30 #include "googleurl/src/gurl.h" 36 #include "googleurl/src/gurl.h"
31 #include "ui/gfx/screen.h" 37 #include "ui/gfx/screen.h"
32 #include "webkit/plugins/webplugininfo.h" 38 #include "webkit/plugins/webplugininfo.h"
33 39
34 #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name) 40 #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
35 41
36 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx 42 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
37 #if defined(OS_WIN) 43 #if defined(OS_WIN)
38 extern "C" IMAGE_DOS_HEADER __ImageBase; 44 extern "C" IMAGE_DOS_HEADER __ImageBase;
39 #endif 45 #endif
40 46
47 using metrics::OmniboxEventProto;
48 using metrics::SystemProfileProto;
49
41 namespace { 50 namespace {
42 51
43 // Returns the date at which the current metrics client ID was created as 52 // Returns the date at which the current metrics client ID was created as
44 // a string containing milliseconds since the epoch, or "0" if none was found. 53 // a string containing milliseconds since the epoch, or "0" if none was found.
45 std::string GetInstallDate() { 54 std::string GetInstallDate() {
46 PrefService* pref = g_browser_process->local_state(); 55 PrefService* pref = g_browser_process->local_state();
47 if (pref) { 56 if (pref) {
48 return pref->GetString(prefs::kMetricsClientIDTimestamp); 57 return pref->GetString(prefs::kMetricsClientIDTimestamp);
49 } else { 58 } else {
50 NOTREACHED(); 59 NOTREACHED();
51 return "0"; 60 return "0";
52 } 61 }
53 } 62 }
54 63
64 OmniboxEventProto::InputType AsOmniboxEventInputType(
65 AutocompleteInput::Type type) {
66 switch (type) {
67 case AutocompleteInput::INVALID:
68 return OmniboxEventProto::INVALID;
69 case AutocompleteInput::UNKNOWN:
70 return OmniboxEventProto::UNKNOWN;
71 case AutocompleteInput::REQUESTED_URL:
72 return OmniboxEventProto::REQUESTED_URL;
73 case AutocompleteInput::URL:
74 return OmniboxEventProto::URL;
75 case AutocompleteInput::QUERY:
76 return OmniboxEventProto::QUERY;
77 case AutocompleteInput::FORCED_QUERY:
78 return OmniboxEventProto::FORCED_QUERY;
79 default:
80 NOTREACHED();
81 return OmniboxEventProto::INVALID;
82 }
83 }
84
85 OmniboxEventProto::Suggestion::ProviderType AsOmniboxEventProviderType(
86 const AutocompleteProvider* provider) {
87 if (!provider)
88 return OmniboxEventProto::Suggestion::UNKNOWN_PROVIDER;
89
90 const std::string& name = provider->name();
91 if (name == "HistoryURL")
92 return OmniboxEventProto::Suggestion::URL;
93 if (name == "HistoryContents")
94 return OmniboxEventProto::Suggestion::HISTORY_CONTENTS;
95 if (name == "HistoryQuickProvider")
96 return OmniboxEventProto::Suggestion::HISTORY_QUICK;
97 if (name == "Search")
98 return OmniboxEventProto::Suggestion::SEARCH;
99 if (name == "Keyword")
100 return OmniboxEventProto::Suggestion::KEYWORD;
101 if (name == "Builtin")
102 return OmniboxEventProto::Suggestion::BUILTIN;
103 if (name == "ShortcutsProvider")
104 return OmniboxEventProto::Suggestion::SHORTCUTS;
105 if (name == "ExtensionApps")
106 return OmniboxEventProto::Suggestion::EXTENSION_APPS;
107
108 NOTREACHED();
109 return OmniboxEventProto::Suggestion::UNKNOWN_PROVIDER;
110 }
111
112 OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
113 AutocompleteMatch::Type type) {
114 switch (type) {
115 case AutocompleteMatch::URL_WHAT_YOU_TYPED:
116 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
117 case AutocompleteMatch::HISTORY_URL:
118 return OmniboxEventProto::Suggestion::HISTORY_URL;
119 case AutocompleteMatch::HISTORY_TITLE:
120 return OmniboxEventProto::Suggestion::HISTORY_TITLE;
121 case AutocompleteMatch::HISTORY_BODY:
122 return OmniboxEventProto::Suggestion::HISTORY_BODY;
123 case AutocompleteMatch::HISTORY_KEYWORD:
124 return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
125 case AutocompleteMatch::NAVSUGGEST:
126 return OmniboxEventProto::Suggestion::NAVSUGGEST;
127 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
128 return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
129 case AutocompleteMatch::SEARCH_HISTORY:
130 return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
131 case AutocompleteMatch::SEARCH_SUGGEST:
132 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
133 case AutocompleteMatch::SEARCH_OTHER_ENGINE:
134 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
135 case AutocompleteMatch::EXTENSION_APP:
136 return OmniboxEventProto::Suggestion::EXTENSION_APP;
137 default:
138 NOTREACHED();
139 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
140 }
141 }
142
55 // Returns the plugin preferences corresponding for this user, if available. 143 // Returns the plugin preferences corresponding for this user, if available.
56 // If multiple user profiles are loaded, returns the preferences corresponding 144 // If multiple user profiles are loaded, returns the preferences corresponding
57 // to an arbitrary one of the profiles. 145 // to an arbitrary one of the profiles.
58 PluginPrefs* GetPluginPrefs() { 146 PluginPrefs* GetPluginPrefs() {
59 ProfileManager* profile_manager = g_browser_process->profile_manager(); 147 ProfileManager* profile_manager = g_browser_process->profile_manager();
60 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); 148 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
61 if (profiles.empty()) 149 if (profiles.empty())
62 return NULL; 150 return NULL;
63 151
64 return PluginPrefs::GetForProfile(profiles.front()); 152 return PluginPrefs::GetForProfile(profiles.front());
65 } 153 }
66 154
155 // Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
156 void SetPluginInfo(const webkit::WebPluginInfo& plugin_info,
157 const PluginPrefs* plugin_prefs,
158 SystemProfileProto::Plugin* plugin) {
159 plugin->set_name(UTF16ToUTF8(plugin_info.name));
160 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
161 plugin->set_version(UTF16ToUTF8(plugin_info.version));
162 if (plugin_prefs)
163 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
164 }
165
67 } // namespace 166 } // namespace
68 167
69 static base::LazyInstance<std::string>::Leaky 168 static base::LazyInstance<std::string>::Leaky
70 g_version_extension = LAZY_INSTANCE_INITIALIZER; 169 g_version_extension = LAZY_INSTANCE_INITIALIZER;
71 170
72 MetricsLog::MetricsLog(const std::string& client_id, int session_id) 171 MetricsLog::MetricsLog(const std::string& client_id, int session_id)
73 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {} 172 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
74 173
75 MetricsLog::~MetricsLog() {} 174 MetricsLog::~MetricsLog() {}
76 175
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // static 213 // static
115 void MetricsLog::set_version_extension(const std::string& extension) { 214 void MetricsLog::set_version_extension(const std::string& extension) {
116 g_version_extension.Get() = extension; 215 g_version_extension.Get() = extension;
117 } 216 }
118 217
119 // static 218 // static
120 const std::string& MetricsLog::version_extension() { 219 const std::string& MetricsLog::version_extension() {
121 return g_version_extension.Get(); 220 return g_version_extension.Get();
122 } 221 }
123 222
124 void MetricsLog::RecordIncrementalStabilityElements() { 223 void MetricsLog::RecordIncrementalStabilityElements(
224 const std::vector<webkit::WebPluginInfo>& plugin_list) {
125 DCHECK(!locked_); 225 DCHECK(!locked_);
126 226
127 PrefService* pref = g_browser_process->local_state(); 227 PrefService* pref = g_browser_process->local_state();
128 DCHECK(pref); 228 DCHECK(pref);
129 229
130 OPEN_ELEMENT_FOR_SCOPE("profile"); 230 OPEN_ELEMENT_FOR_SCOPE("profile");
131 WriteCommonEventAttributes(); 231 WriteCommonEventAttributes();
132 232
133 WriteInstallElement(); 233 WriteInstallElement();
134 234
135 { 235 {
136 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements. 236 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
137 WriteRequiredStabilityAttributes(pref); 237 WriteRequiredStabilityAttributes(pref);
138 WriteRealtimeStabilityAttributes(pref); 238 WriteRealtimeStabilityAttributes(pref);
139 239
140 WritePluginStabilityElements(pref); 240 WritePluginStabilityElements(plugin_list, pref);
141 } 241 }
142 } 242 }
143 243
144 void MetricsLog::WriteStabilityElement(PrefService* pref) { 244 void MetricsLog::WriteStabilityElement(
245 const std::vector<webkit::WebPluginInfo>& plugin_list,
246 PrefService* pref) {
145 DCHECK(!locked_); 247 DCHECK(!locked_);
146 248
147 DCHECK(pref);
148
149 // Get stability attributes out of Local State, zeroing out stored values. 249 // Get stability attributes out of Local State, zeroing out stored values.
150 // NOTE: This could lead to some data loss if this report isn't successfully 250 // NOTE: This could lead to some data loss if this report isn't successfully
151 // sent, but that's true for all the metrics. 251 // sent, but that's true for all the metrics.
152 252
153 OPEN_ELEMENT_FOR_SCOPE("stability"); 253 OPEN_ELEMENT_FOR_SCOPE("stability");
154 WriteRequiredStabilityAttributes(pref); 254 WriteRequiredStabilityAttributes(pref);
155 WriteRealtimeStabilityAttributes(pref); 255 WriteRealtimeStabilityAttributes(pref);
156 256
257 int incomplete_shutdown_count =
258 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
259 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
260 int breakpad_registration_success_count =
261 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
262 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
263 int breakpad_registration_failure_count =
264 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
265 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
266 int debugger_present_count =
267 pref->GetInteger(prefs::kStabilityDebuggerPresent);
268 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
269 int debugger_not_present_count =
270 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
271 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
272
157 // TODO(jar): The following are all optional, so we *could* optimize them for 273 // TODO(jar): The following are all optional, so we *could* optimize them for
158 // values of zero (and not include them). 274 // values of zero (and not include them).
159 WriteIntAttribute("incompleteshutdowncount",
160 pref->GetInteger(
161 prefs::kStabilityIncompleteSessionEndCount));
162 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
163 275
276 // Write the XML version.
277 WriteIntAttribute("incompleteshutdowncount", incomplete_shutdown_count);
278 WriteIntAttribute("breakpadregistrationok",
279 breakpad_registration_success_count);
280 WriteIntAttribute("breakpadregistrationfail",
281 breakpad_registration_failure_count);
282 WriteIntAttribute("debuggerpresent", debugger_present_count);
283 WriteIntAttribute("debuggernotpresent", debugger_not_present_count);
164 284
165 WriteIntAttribute("breakpadregistrationok", 285 // Write the protobuf version.
166 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess)); 286 SystemProfileProto::Stability* stability =
167 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); 287 uma_proto_.mutable_system_profile()->mutable_stability();
168 WriteIntAttribute("breakpadregistrationfail", 288 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
169 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail)); 289 stability->set_breakpad_registration_success_count(
170 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); 290 breakpad_registration_success_count);
171 WriteIntAttribute("debuggerpresent", 291 stability->set_breakpad_registration_failure_count(
172 pref->GetInteger(prefs::kStabilityDebuggerPresent)); 292 breakpad_registration_failure_count);
173 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0); 293 stability->set_debugger_present_count(debugger_present_count);
174 WriteIntAttribute("debuggernotpresent", 294 stability->set_debugger_not_present_count(debugger_not_present_count);
175 pref->GetInteger(prefs::kStabilityDebuggerNotPresent));
176 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
177 295
178 WritePluginStabilityElements(pref); 296 WritePluginStabilityElements(plugin_list, pref);
179 } 297 }
180 298
181 void MetricsLog::WritePluginStabilityElements(PrefService* pref) { 299 void MetricsLog::WritePluginStabilityElements(
300 const std::vector<webkit::WebPluginInfo>& plugin_list,
301 PrefService* pref) {
182 // Now log plugin stability info. 302 // Now log plugin stability info.
183 const ListValue* plugin_stats_list = pref->GetList( 303 const ListValue* plugin_stats_list = pref->GetList(
184 prefs::kStabilityPluginStats); 304 prefs::kStabilityPluginStats);
185 if (!plugin_stats_list) 305 if (!plugin_stats_list)
186 return; 306 return;
187 307
188 OPEN_ELEMENT_FOR_SCOPE("plugins"); 308 OPEN_ELEMENT_FOR_SCOPE("plugins");
309 SystemProfileProto::Stability* stability =
310 uma_proto_.mutable_system_profile()->mutable_stability();
311 PluginPrefs* plugin_prefs = GetPluginPrefs();
189 for (ListValue::const_iterator iter = plugin_stats_list->begin(); 312 for (ListValue::const_iterator iter = plugin_stats_list->begin();
190 iter != plugin_stats_list->end(); ++iter) { 313 iter != plugin_stats_list->end(); ++iter) {
191 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) { 314 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
192 NOTREACHED(); 315 NOTREACHED();
193 continue; 316 continue;
194 } 317 }
195 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter); 318 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
196 319
197 std::string plugin_name; 320 std::string plugin_name;
198 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name); 321 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
199 322
323 std::string base64_name_hash;
324 uint64 numeric_name_hash_ignored;
325 CreateHashes(plugin_name, &base64_name_hash, &numeric_name_hash_ignored);
326
327 // Write the XML verison.
200 OPEN_ELEMENT_FOR_SCOPE("pluginstability"); 328 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
201 // Use "filename" instead of "name", otherwise we need to update the 329 // Use "filename" instead of "name", otherwise we need to update the
202 // UMA servers. 330 // UMA servers.
203 WriteAttribute("filename", CreateBase64Hash(plugin_name)); 331 WriteAttribute("filename", base64_name_hash);
204 332
205 int launches = 0; 333 int launches = 0;
206 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches); 334 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
207 WriteIntAttribute("launchcount", launches); 335 WriteIntAttribute("launchcount", launches);
208 336
209 int instances = 0; 337 int instances = 0;
210 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances); 338 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
211 WriteIntAttribute("instancecount", instances); 339 WriteIntAttribute("instancecount", instances);
212 340
213 int crashes = 0; 341 int crashes = 0;
214 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes); 342 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
215 WriteIntAttribute("crashcount", crashes); 343 WriteIntAttribute("crashcount", crashes);
344
345 // Write the protobuf version.
346 // Note that this search is potentially a quadratic operation, but given the
347 // low number of plugins installed on a "reasonable" setup, this should be
348 // fine.
349 const webkit::WebPluginInfo* plugin_info = NULL;
350 const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name);
351 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
352 plugin_list.begin();
353 iter != plugin_list.end(); ++iter) {
354 if (iter->name == plugin_name_utf16) {
355 plugin_info = &(*iter);
356 break;
357 }
358 }
359
360 if (!plugin_info) {
361 NOTREACHED();
362 continue;
363 }
364
365 SystemProfileProto::Stability::PluginStability* plugin_stability =
366 stability->add_plugin_stability();
367 SetPluginInfo(*plugin_info, plugin_prefs,
368 plugin_stability->mutable_plugin());
369 plugin_stability->set_launch_count(launches);
370 plugin_stability->set_instance_count(instances);
371 plugin_stability->set_crash_count(crashes);
216 } 372 }
217 373
218 pref->ClearPref(prefs::kStabilityPluginStats); 374 pref->ClearPref(prefs::kStabilityPluginStats);
219 } 375 }
220 376
377 // The server refuses data that doesn't have certain values. crashcount and
378 // launchcount are currently "required" in the "stability" group.
379 // TODO(isherman): Stop writing these attributes specially once the migration to
380 // protobufs is complete.
221 void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) { 381 void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
222 // The server refuses data that doesn't have certain values. crashcount and 382 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
223 // launchcount are currently "required" in the "stability" group.
224 WriteIntAttribute("launchcount",
225 pref->GetInteger(prefs::kStabilityLaunchCount));
226 pref->SetInteger(prefs::kStabilityLaunchCount, 0); 383 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
227 WriteIntAttribute("crashcount", 384 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
228 pref->GetInteger(prefs::kStabilityCrashCount));
229 pref->SetInteger(prefs::kStabilityCrashCount, 0); 385 pref->SetInteger(prefs::kStabilityCrashCount, 0);
386
387 // Write the XML version.
388 WriteIntAttribute("launchcount", launch_count);
389 WriteIntAttribute("crashcount", crash_count);
390
391 // Write the protobuf version.
392 SystemProfileProto::Stability* stability =
393 uma_proto_.mutable_system_profile()->mutable_stability();
394 stability->set_launch_count(launch_count);
395 stability->set_crash_count(crash_count);
230 } 396 }
231 397
232 void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) { 398 void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
233 // Update the stats which are critical for real-time stability monitoring. 399 // Update the stats which are critical for real-time stability monitoring.
234 // Since these are "optional," only list ones that are non-zero, as the counts 400 // Since these are "optional," only list ones that are non-zero, as the counts
235 // are aggergated (summed) server side. 401 // are aggergated (summed) server side.
236 402
403 SystemProfileProto::Stability* stability =
404 uma_proto_.mutable_system_profile()->mutable_stability();
237 int count = pref->GetInteger(prefs::kStabilityPageLoadCount); 405 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
238 if (count) { 406 if (count) {
239 WriteIntAttribute("pageloadcount", count); 407 WriteIntAttribute("pageloadcount", count);
408 stability->set_page_load_count(count);
240 pref->SetInteger(prefs::kStabilityPageLoadCount, 0); 409 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
241 } 410 }
242 411
243 count = pref->GetInteger(prefs::kStabilityRendererCrashCount); 412 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
244 if (count) { 413 if (count) {
245 WriteIntAttribute("renderercrashcount", count); 414 WriteIntAttribute("renderercrashcount", count);
415 stability->set_renderer_crash_count(count);
246 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0); 416 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
247 } 417 }
248 418
249 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount); 419 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
250 if (count) { 420 if (count) {
251 WriteIntAttribute("extensionrenderercrashcount", count); 421 WriteIntAttribute("extensionrenderercrashcount", count);
422 stability->set_extension_renderer_crash_count(count);
252 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0); 423 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
253 } 424 }
254 425
255 count = pref->GetInteger(prefs::kStabilityRendererHangCount); 426 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
256 if (count) { 427 if (count) {
257 WriteIntAttribute("rendererhangcount", count); 428 WriteIntAttribute("rendererhangcount", count);
429 stability->set_renderer_hang_count(count);
258 pref->SetInteger(prefs::kStabilityRendererHangCount, 0); 430 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
259 } 431 }
260 432
261 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount); 433 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
262 if (count) { 434 if (count) {
263 WriteIntAttribute("childprocesscrashcount", count); 435 WriteIntAttribute("childprocesscrashcount", count);
436 stability->set_child_process_crash_count(count);
264 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); 437 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
265 } 438 }
266 439
267 #if defined(OS_CHROMEOS) 440 #if defined(OS_CHROMEOS)
268 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount); 441 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
269 if (count) { 442 if (count) {
270 // TODO(kmixter): Write attribute once log server supports it 443 stability->set_other_user_crash_count(count);
271 // and remove warning log.
272 // WriteIntAttribute("otherusercrashcount", count);
273 LOG(WARNING) << "Not yet able to send otherusercrashcount="
274 << count;
275 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0); 444 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
276 } 445 }
277 446
278 count = pref->GetInteger(prefs::kStabilityKernelCrashCount); 447 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
279 if (count) { 448 if (count) {
280 // TODO(kmixter): Write attribute once log server supports it 449 stability->set_kernel_crash_count(count);
281 // and remove warning log.
282 // WriteIntAttribute("kernelcrashcount", count);
283 LOG(WARNING) << "Not yet able to send kernelcrashcount="
284 << count;
285 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0); 450 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
286 } 451 }
287 452
288 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount); 453 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
289 if (count) { 454 if (count) {
290 // TODO(kmixter): Write attribute once log server supports it 455 stability->set_unclean_system_shutdown_count(count);
291 // and remove warning log.
292 // WriteIntAttribute("systemuncleanshutdowns", count);
293 LOG(WARNING) << "Not yet able to send systemuncleanshutdowns="
294 << count;
295 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0); 456 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
296 } 457 }
297 #endif // OS_CHROMEOS 458 #endif // OS_CHROMEOS
298 459
299 int64 recent_duration = GetIncrementalUptime(pref); 460 int64 recent_duration = GetIncrementalUptime(pref);
300 if (recent_duration) 461 if (recent_duration) {
301 WriteInt64Attribute("uptimesec", recent_duration); 462 WriteInt64Attribute("uptimesec", recent_duration);
463 stability->set_uptime_sec(recent_duration);
464 }
302 } 465 }
303 466
304 void MetricsLog::WritePluginList( 467 void MetricsLog::WritePluginList(
305 const std::vector<webkit::WebPluginInfo>& plugin_list) { 468 const std::vector<webkit::WebPluginInfo>& plugin_list) {
306 DCHECK(!locked_); 469 DCHECK(!locked_);
307 470
308 PluginPrefs* plugin_prefs = GetPluginPrefs(); 471 PluginPrefs* plugin_prefs = GetPluginPrefs();
309 472
310 OPEN_ELEMENT_FOR_SCOPE("plugins"); 473 OPEN_ELEMENT_FOR_SCOPE("plugins");
311 474 SystemProfileProto* system_profile = uma_proto_.mutable_system_profile();
312 for (std::vector<webkit::WebPluginInfo>::const_iterator iter = 475 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
313 plugin_list.begin(); 476 plugin_list.begin();
314 iter != plugin_list.end(); ++iter) { 477 iter != plugin_list.end(); ++iter) {
478 std::string base64_name_hash;
479 uint64 numeric_name_hash_ignored;
480 CreateHashes(UTF16ToUTF8(iter->name),
481 &base64_name_hash,
482 &numeric_name_hash_ignored);
483
484 std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe();
485 std::string base64_filename_hash;
486 uint64 numeric_filename_hash;
487 CreateHashes(filename_bytes,
488 &base64_filename_hash,
489 &numeric_filename_hash);
490
491 // Write the XML version.
315 OPEN_ELEMENT_FOR_SCOPE("plugin"); 492 OPEN_ELEMENT_FOR_SCOPE("plugin");
316 493
317 // Plugin name and filename are hashed for the privacy of those 494 // Plugin name and filename are hashed for the privacy of those
318 // testing unreleased new extensions. 495 // testing unreleased new extensions.
319 WriteAttribute("name", CreateBase64Hash(UTF16ToUTF8(iter->name))); 496 WriteAttribute("name", base64_name_hash);
320 std::string filename_bytes = 497 WriteAttribute("filename", base64_filename_hash);
321 #if defined(OS_WIN)
322 UTF16ToUTF8(iter->path.BaseName().value());
323 #else
324 iter->path.BaseName().value();
325 #endif
326 WriteAttribute("filename", CreateBase64Hash(filename_bytes));
327 WriteAttribute("version", UTF16ToUTF8(iter->version)); 498 WriteAttribute("version", UTF16ToUTF8(iter->version));
328 if (plugin_prefs) 499 if (plugin_prefs)
329 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter)); 500 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
501
502 // Write the protobuf version.
503 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
504 SetPluginInfo(*iter, plugin_prefs, plugin);
330 } 505 }
331 } 506 }
332 507
333 void MetricsLog::WriteInstallElement() { 508 void MetricsLog::WriteInstallElement() {
509 std::string install_date = GetInstallDate();
510
511 // Write the XML version.
334 OPEN_ELEMENT_FOR_SCOPE("install"); 512 OPEN_ELEMENT_FOR_SCOPE("install");
335 WriteAttribute("installdate", GetInstallDate()); 513 WriteAttribute("installdate", install_date);
336 WriteIntAttribute("buildid", 0); // We're using appversion instead. 514 WriteIntAttribute("buildid", 0); // We're using appversion instead.
515
516 // Write the protobuf version.
517 int numeric_install_date;
518 bool success = base::StringToInt(install_date, &numeric_install_date);
519 DCHECK(success);
520 uma_proto_.mutable_system_profile()->set_install_date(numeric_install_date);
337 } 521 }
338 522
339 void MetricsLog::RecordEnvironment( 523 void MetricsLog::RecordEnvironment(
340 const std::vector<webkit::WebPluginInfo>& plugin_list, 524 const std::vector<webkit::WebPluginInfo>& plugin_list,
341 const DictionaryValue* profile_metrics) { 525 const DictionaryValue* profile_metrics) {
342 DCHECK(!locked_); 526 DCHECK(!locked_);
343 527
344 PrefService* pref = g_browser_process->local_state(); 528 PrefService* pref = g_browser_process->local_state();
345 529
346 OPEN_ELEMENT_FOR_SCOPE("profile"); 530 OPEN_ELEMENT_FOR_SCOPE("profile");
347 WriteCommonEventAttributes(); 531 WriteCommonEventAttributes();
348 532
349 WriteInstallElement(); 533 WriteInstallElement();
350 534
351 WritePluginList(plugin_list); 535 WritePluginList(plugin_list);
352 536
353 WriteStabilityElement(pref); 537 WriteStabilityElement(plugin_list, pref);
354 538
539 SystemProfileProto* system_profile = uma_proto_.mutable_system_profile();
540 system_profile->set_application_locale(
541 content::GetContentClient()->browser()->GetApplicationLocale());
542
543 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
355 { 544 {
545 std::string cpu_architecture = base::SysInfo::CPUArchitecture();
546
547 // Write the XML version.
356 OPEN_ELEMENT_FOR_SCOPE("cpu"); 548 OPEN_ELEMENT_FOR_SCOPE("cpu");
357 WriteAttribute("arch", base::SysInfo::CPUArchitecture()); 549 WriteAttribute("arch", cpu_architecture);
550
551 // Write the protobuf version.
552 hardware->set_cpu_architecture(cpu_architecture);
358 } 553 }
359 554
360 { 555 {
556 int system_memory_mb = base::SysInfo::AmountOfPhysicalMemoryMB();
557
558 // Write the XML version.
361 OPEN_ELEMENT_FOR_SCOPE("memory"); 559 OPEN_ELEMENT_FOR_SCOPE("memory");
362 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB()); 560 WriteIntAttribute("mb", system_memory_mb);
363 #if defined(OS_WIN) 561 #if defined(OS_WIN)
364 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase)); 562 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
365 #endif 563 #endif
564
565 // Write the protobuf version.
566 hardware->set_system_ram_mb(system_memory_mb);
567 #if defined(OS_WIN)
568 // TODO(isherman): This does the wrong thing on a 64-bit OS, doesn't it?
569 hardware->set_dll_base(reinterpret_cast<int>(&__ImageBase));
570 #endif
366 } 571 }
367 572
368 { 573 {
574 std::string os_name = base::SysInfo::OperatingSystemName();
575 std::string os_version = base::SysInfo::OperatingSystemVersion();
576
577 // Write the XML version.
369 OPEN_ELEMENT_FOR_SCOPE("os"); 578 OPEN_ELEMENT_FOR_SCOPE("os");
370 WriteAttribute("name", 579 WriteAttribute("name", os_name);
371 base::SysInfo::OperatingSystemName()); 580 WriteAttribute("version", os_version);
372 WriteAttribute("version", 581
373 base::SysInfo::OperatingSystemVersion()); 582 // Write the protobuf version.
583 SystemProfileProto::OS* os = system_profile->mutable_os();
584 os->set_name(os_name);
585 os->set_version(os_version);
374 } 586 }
375 587
376 { 588 {
589 GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance();
377 OPEN_ELEMENT_FOR_SCOPE("gpu"); 590 OPEN_ELEMENT_FOR_SCOPE("gpu");
378 GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance();
379 if (gpu_data_manager) { 591 if (gpu_data_manager) {
380 WriteIntAttribute("vendorid", gpu_data_manager->gpu_info().vendor_id); 592 const content::GPUInfo& gpu_info = gpu_data_manager->gpu_info();
381 WriteIntAttribute("deviceid", gpu_data_manager->gpu_info().device_id); 593 GpuPerformanceStats gpu_performance_stats =
594 GpuPerformanceStats::RetrieveGpuPerformanceStats();
595
596 // Write the XML version.
597 WriteIntAttribute("vendorid", gpu_info.vendor_id);
598 WriteIntAttribute("deviceid", gpu_info.device_id);
599
600 // Write the protobuf version.
601 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
602 gpu->set_vendor_id(gpu_info.vendor_id);
603 gpu->set_device_id(gpu_info.device_id);
604 gpu->set_driver_version(gpu_info.driver_version);
605 gpu->set_driver_date(gpu_info.driver_date);
606 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
607 gpu_performance = gpu->mutable_performance_statistics();
608 gpu_performance->set_graphics_score(gpu_performance_stats.graphics);
609 gpu_performance->set_gaming_score(gpu_performance_stats.gaming);
610 gpu_performance->set_overall_score(gpu_performance_stats.overall);
382 } 611 }
383 } 612 }
384 613
385 { 614 {
615 const gfx::Size display_size = gfx::Screen::GetPrimaryMonitorSize();
616 int display_width = display_size.width();
617 int display_height = display_size.height();
618 int screen_count = gfx::Screen::GetNumMonitors();
619
620 // Write the XML version.
386 OPEN_ELEMENT_FOR_SCOPE("display"); 621 OPEN_ELEMENT_FOR_SCOPE("display");
387 const gfx::Size display_size = gfx::Screen::GetPrimaryMonitorSize(); 622 WriteIntAttribute("xsize", display_width);
388 WriteIntAttribute("xsize", display_size.width()); 623 WriteIntAttribute("ysize", display_height);
389 WriteIntAttribute("ysize", display_size.height()); 624 WriteIntAttribute("screens", screen_count);
390 WriteIntAttribute("screens", gfx::Screen::GetNumMonitors()); 625
626 // Write the protobuf version.
627 hardware->set_primary_screen_width(display_width);
628 hardware->set_primary_screen_height(display_height);
629 hardware->set_screen_count(screen_count);
391 } 630 }
392 631
393 { 632 {
394 OPEN_ELEMENT_FOR_SCOPE("bookmarks"); 633 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
395 int num_bookmarks_on_bookmark_bar = 634 int num_bookmarks_on_bookmark_bar =
396 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar); 635 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
397 int num_folders_on_bookmark_bar = 636 int num_folders_on_bookmark_bar =
398 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar); 637 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
399 int num_bookmarks_in_other_bookmarks_folder = 638 int num_bookmarks_in_other_bookmarks_folder =
400 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder); 639 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 NOTREACHED(); 724 NOTREACHED();
486 break; 725 break;
487 } 726 }
488 } 727 }
489 } 728 }
490 } 729 }
491 730
492 void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) { 731 void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
493 DCHECK(!locked_); 732 DCHECK(!locked_);
494 733
734 // Write the XML version.
495 OPEN_ELEMENT_FOR_SCOPE("uielement"); 735 OPEN_ELEMENT_FOR_SCOPE("uielement");
496 WriteAttribute("action", "autocomplete"); 736 WriteAttribute("action", "autocomplete");
497 WriteAttribute("targetidhash", ""); 737 WriteAttribute("targetidhash", "");
498 // TODO(kochi): Properly track windows. 738 // TODO(kochi): Properly track windows.
499 WriteIntAttribute("window", 0); 739 WriteIntAttribute("window", 0);
500 if (log.tab_id != -1) { 740 if (log.tab_id != -1) {
501 // If we know what tab the autocomplete URL was opened in, log it. 741 // If we know what tab the autocomplete URL was opened in, log it.
502 WriteIntAttribute("tab", static_cast<int>(log.tab_id)); 742 WriteIntAttribute("tab", static_cast<int>(log.tab_id));
503 } 743 }
504 WriteCommonEventAttributes(); 744 WriteCommonEventAttributes();
(...skipping 19 matching lines...) Expand all
524 if (i->provider) 764 if (i->provider)
525 WriteAttribute("provider", i->provider->name()); 765 WriteAttribute("provider", i->provider->name());
526 const std::string result_type(AutocompleteMatch::TypeToString(i->type)); 766 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
527 if (!result_type.empty()) 767 if (!result_type.empty())
528 WriteAttribute("resulttype", result_type); 768 WriteAttribute("resulttype", result_type);
529 WriteIntAttribute("relevance", i->relevance); 769 WriteIntAttribute("relevance", i->relevance);
530 WriteIntAttribute("isstarred", i->starred ? 1 : 0); 770 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
531 } 771 }
532 } 772 }
533 773
774 // Write the protobuf version.
775 OmniboxEventProto* omnibox_event = uma_proto_.add_omnibox_event();
776 omnibox_event->set_time(base::Time::Now().ToTimeT());
777 if (log.tab_id != -1) {
778 // If we know what tab the autocomplete URL was opened in, log it.
779 omnibox_event->set_tab_id(log.tab_id);
780 }
781 omnibox_event->set_typed_length(log.text.length());
782 omnibox_event->set_selected_index(log.selected_index);
783 omnibox_event->set_completed_length(log.inline_autocompleted_length);
784 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
785 for (AutocompleteResult::const_iterator i(log.result.begin());
786 i != log.result.end(); ++i) {
787 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
788 suggestion->set_provider(AsOmniboxEventProviderType(i->provider));
789 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
790 suggestion->set_relevance(i->relevance);
791 suggestion->set_is_starred(i->starred);
792 }
793
534 ++num_events_; 794 ++num_events_;
535 } 795 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698