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

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

Powered by Google App Engine
This is Rietveld 408576698