OLD | NEW |
---|---|
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" |
33 #include "content/public/browser/content_browser_client.h" | |
29 #include "content/public/browser/gpu_data_manager.h" | 34 #include "content/public/browser/gpu_data_manager.h" |
30 #include "content/public/common/gpu_info.h" | 35 #include "content/public/common/gpu_info.h" |
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 Loading... | |
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. | |
351 // TODO(isherman): Verify that this does not show up as a hotspot in | |
352 // profiler runs. | |
353 const webkit::WebPluginInfo* plugin_info = NULL; | |
354 const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name); | |
355 for (std::vector<webkit::WebPluginInfo>::const_iterator iter = | |
356 plugin_list.begin(); | |
357 iter != plugin_list.end(); ++iter) { | |
358 if (iter->name == plugin_name_utf16) { | |
359 plugin_info = &(*iter); | |
360 break; | |
361 } | |
362 } | |
363 | |
364 if (!plugin_info) { | |
365 NOTREACHED(); | |
366 continue; | |
367 } | |
368 | |
369 SystemProfileProto::Stability::PluginStability* plugin_stability = | |
370 stability->add_plugin_stability(); | |
371 SetPluginInfo(*plugin_info, plugin_prefs, | |
372 plugin_stability->mutable_plugin()); | |
373 plugin_stability->set_launch_count(launches); | |
374 plugin_stability->set_instance_count(instances); | |
375 plugin_stability->set_crash_count(crashes); | |
219 } | 376 } |
220 | 377 |
221 pref->ClearPref(prefs::kStabilityPluginStats); | 378 pref->ClearPref(prefs::kStabilityPluginStats); |
222 } | 379 } |
223 | 380 |
381 // The server refuses data that doesn't have certain values. crashcount and | |
382 // launchcount are currently "required" in the "stability" group. | |
383 // TODO(isherman): Stop writing these attributes specially once the migration to | |
384 // protobufs is complete. | |
224 void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) { | 385 void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) { |
225 // The server refuses data that doesn't have certain values. crashcount and | 386 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); | 387 pref->SetInteger(prefs::kStabilityLaunchCount, 0); |
230 WriteIntAttribute("crashcount", | 388 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount); |
231 pref->GetInteger(prefs::kStabilityCrashCount)); | |
232 pref->SetInteger(prefs::kStabilityCrashCount, 0); | 389 pref->SetInteger(prefs::kStabilityCrashCount, 0); |
390 | |
391 // Write the XML version. | |
392 WriteIntAttribute("launchcount", launch_count); | |
393 WriteIntAttribute("crashcount", crash_count); | |
394 | |
395 // Write the protobuf version. | |
396 SystemProfileProto::Stability* stability = | |
397 uma_proto_.mutable_system_profile()->mutable_stability(); | |
398 stability->set_launch_count(launch_count); | |
399 stability->set_crash_count(crash_count); | |
233 } | 400 } |
234 | 401 |
235 void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) { | 402 void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) { |
236 // Update the stats which are critical for real-time stability monitoring. | 403 // 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 | 404 // Since these are "optional," only list ones that are non-zero, as the counts |
238 // are aggergated (summed) server side. | 405 // are aggergated (summed) server side. |
239 | 406 |
407 SystemProfileProto::Stability* stability = | |
408 uma_proto_.mutable_system_profile()->mutable_stability(); | |
240 int count = pref->GetInteger(prefs::kStabilityPageLoadCount); | 409 int count = pref->GetInteger(prefs::kStabilityPageLoadCount); |
241 if (count) { | 410 if (count) { |
242 WriteIntAttribute("pageloadcount", count); | 411 WriteIntAttribute("pageloadcount", count); |
412 stability->set_page_load_count(count); | |
243 pref->SetInteger(prefs::kStabilityPageLoadCount, 0); | 413 pref->SetInteger(prefs::kStabilityPageLoadCount, 0); |
244 } | 414 } |
245 | 415 |
246 count = pref->GetInteger(prefs::kStabilityRendererCrashCount); | 416 count = pref->GetInteger(prefs::kStabilityRendererCrashCount); |
247 if (count) { | 417 if (count) { |
248 WriteIntAttribute("renderercrashcount", count); | 418 WriteIntAttribute("renderercrashcount", count); |
419 stability->set_renderer_crash_count(count); | |
249 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0); | 420 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0); |
250 } | 421 } |
251 | 422 |
252 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount); | 423 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount); |
253 if (count) { | 424 if (count) { |
254 WriteIntAttribute("extensionrenderercrashcount", count); | 425 WriteIntAttribute("extensionrenderercrashcount", count); |
426 stability->set_extension_renderer_crash_count(count); | |
255 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0); | 427 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0); |
256 } | 428 } |
257 | 429 |
258 count = pref->GetInteger(prefs::kStabilityRendererHangCount); | 430 count = pref->GetInteger(prefs::kStabilityRendererHangCount); |
259 if (count) { | 431 if (count) { |
260 WriteIntAttribute("rendererhangcount", count); | 432 WriteIntAttribute("rendererhangcount", count); |
433 stability->set_renderer_hang_count(count); | |
261 pref->SetInteger(prefs::kStabilityRendererHangCount, 0); | 434 pref->SetInteger(prefs::kStabilityRendererHangCount, 0); |
262 } | 435 } |
263 | 436 |
264 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount); | 437 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount); |
265 if (count) { | 438 if (count) { |
266 WriteIntAttribute("childprocesscrashcount", count); | 439 WriteIntAttribute("childprocesscrashcount", count); |
440 stability->set_child_process_crash_count(count); | |
267 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); | 441 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); |
268 } | 442 } |
269 | 443 |
270 #if defined(OS_CHROMEOS) | 444 #if defined(OS_CHROMEOS) |
271 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount); | 445 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount); |
272 if (count) { | 446 if (count) { |
273 // TODO(kmixter): Write attribute once log server supports it | 447 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); | 448 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0); |
279 } | 449 } |
280 | 450 |
281 count = pref->GetInteger(prefs::kStabilityKernelCrashCount); | 451 count = pref->GetInteger(prefs::kStabilityKernelCrashCount); |
282 if (count) { | 452 if (count) { |
283 // TODO(kmixter): Write attribute once log server supports it | 453 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); | 454 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0); |
289 } | 455 } |
290 | 456 |
291 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount); | 457 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount); |
292 if (count) { | 458 if (count) { |
293 // TODO(kmixter): Write attribute once log server supports it | 459 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); | 460 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0); |
299 } | 461 } |
300 #endif // OS_CHROMEOS | 462 #endif // OS_CHROMEOS |
301 | 463 |
302 int64 recent_duration = GetIncrementalUptime(pref); | 464 int64 recent_duration = GetIncrementalUptime(pref); |
303 if (recent_duration) | 465 if (recent_duration) { |
304 WriteInt64Attribute("uptimesec", recent_duration); | 466 WriteInt64Attribute("uptimesec", recent_duration); |
467 stability->set_uptime_sec(recent_duration); | |
468 } | |
305 } | 469 } |
306 | 470 |
307 void MetricsLog::WritePluginList( | 471 void MetricsLog::WritePluginList( |
308 const std::vector<webkit::WebPluginInfo>& plugin_list) { | 472 const std::vector<webkit::WebPluginInfo>& plugin_list) { |
309 DCHECK(!locked_); | 473 DCHECK(!locked_); |
310 | 474 |
311 PluginPrefs* plugin_prefs = GetPluginPrefs(); | 475 PluginPrefs* plugin_prefs = GetPluginPrefs(); |
312 | 476 |
313 OPEN_ELEMENT_FOR_SCOPE("plugins"); | 477 OPEN_ELEMENT_FOR_SCOPE("plugins"); |
314 | 478 SystemProfileProto* system_profile = uma_proto_.mutable_system_profile(); |
315 for (std::vector<webkit::WebPluginInfo>::const_iterator iter = | 479 for (std::vector<webkit::WebPluginInfo>::const_iterator iter = |
316 plugin_list.begin(); | 480 plugin_list.begin(); |
317 iter != plugin_list.end(); ++iter) { | 481 iter != plugin_list.end(); ++iter) { |
482 std::string base64_name_hash; | |
483 uint64 numeric_name_hash_ignored; | |
484 CreateHashes(UTF16ToUTF8(iter->name), | |
485 &base64_name_hash, | |
486 &numeric_name_hash_ignored); | |
487 | |
488 std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe(); | |
489 std::string base64_filename_hash; | |
490 uint64 numeric_filename_hash; | |
491 CreateHashes(filename_bytes, | |
492 &base64_filename_hash, | |
493 &numeric_filename_hash); | |
494 | |
495 // Write the XML version. | |
318 OPEN_ELEMENT_FOR_SCOPE("plugin"); | 496 OPEN_ELEMENT_FOR_SCOPE("plugin"); |
319 | 497 |
320 // Plugin name and filename are hashed for the privacy of those | 498 // Plugin name and filename are hashed for the privacy of those |
321 // testing unreleased new extensions. | 499 // testing unreleased new extensions. |
322 WriteAttribute("name", CreateBase64Hash(UTF16ToUTF8(iter->name))); | 500 WriteAttribute("name", base64_name_hash); |
323 std::string filename_bytes = | 501 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)); | 502 WriteAttribute("version", UTF16ToUTF8(iter->version)); |
331 if (plugin_prefs) | 503 if (plugin_prefs) |
332 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter)); | 504 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter)); |
505 | |
506 // Write the protobuf version. | |
507 SystemProfileProto::Plugin* plugin = system_profile->add_plugin(); | |
508 SetPluginInfo(*iter, plugin_prefs, plugin); | |
333 } | 509 } |
334 } | 510 } |
335 | 511 |
336 void MetricsLog::WriteInstallElement() { | 512 void MetricsLog::WriteInstallElement() { |
513 std::string install_date = GetInstallDate(); | |
514 | |
515 // Write the XML version. | |
337 OPEN_ELEMENT_FOR_SCOPE("install"); | 516 OPEN_ELEMENT_FOR_SCOPE("install"); |
338 WriteAttribute("installdate", GetInstallDate()); | 517 WriteAttribute("installdate", install_date); |
339 WriteIntAttribute("buildid", 0); // We're using appversion instead. | 518 WriteIntAttribute("buildid", 0); // We're using appversion instead. |
519 | |
520 // Write the protobuf version. | |
521 int numeric_install_date; | |
522 bool success = base::StringToInt(install_date, &numeric_install_date); | |
523 DCHECK(success); | |
524 uma_proto_.mutable_system_profile()->set_install_date(numeric_install_date); | |
340 } | 525 } |
341 | 526 |
342 void MetricsLog::RecordEnvironment( | 527 void MetricsLog::RecordEnvironment( |
343 const std::vector<webkit::WebPluginInfo>& plugin_list, | 528 const std::vector<webkit::WebPluginInfo>& plugin_list, |
344 const DictionaryValue* profile_metrics) { | 529 const DictionaryValue* profile_metrics) { |
345 DCHECK(!locked_); | 530 DCHECK(!locked_); |
346 | 531 |
347 PrefService* pref = g_browser_process->local_state(); | 532 PrefService* pref = g_browser_process->local_state(); |
348 | 533 |
349 OPEN_ELEMENT_FOR_SCOPE("profile"); | 534 OPEN_ELEMENT_FOR_SCOPE("profile"); |
350 WriteCommonEventAttributes(); | 535 WriteCommonEventAttributes(); |
351 | 536 |
352 WriteInstallElement(); | 537 WriteInstallElement(); |
353 | 538 |
354 WritePluginList(plugin_list); | 539 WritePluginList(plugin_list); |
355 | 540 |
356 WriteStabilityElement(pref); | 541 WriteStabilityElement(plugin_list, pref); |
357 | 542 |
543 SystemProfileProto* system_profile = uma_proto_.mutable_system_profile(); | |
544 system_profile->set_application_locale( | |
545 content::GetContentClient()->browser()->GetApplicationLocale()); | |
546 | |
547 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware(); | |
358 { | 548 { |
549 std::string cpu_architecture = base::SysInfo::CPUArchitecture(); | |
550 | |
551 // Write the XML version. | |
359 OPEN_ELEMENT_FOR_SCOPE("cpu"); | 552 OPEN_ELEMENT_FOR_SCOPE("cpu"); |
360 WriteAttribute("arch", base::SysInfo::CPUArchitecture()); | 553 WriteAttribute("arch", cpu_architecture); |
554 | |
555 // Write the protobuf version. | |
556 hardware->set_cpu_architecture(cpu_architecture); | |
361 } | 557 } |
362 | 558 |
363 { | 559 { |
560 int system_memory_mb = base::SysInfo::AmountOfPhysicalMemoryMB(); | |
561 | |
562 // Write the XML version. | |
364 OPEN_ELEMENT_FOR_SCOPE("memory"); | 563 OPEN_ELEMENT_FOR_SCOPE("memory"); |
365 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB()); | 564 WriteIntAttribute("mb", system_memory_mb); |
366 #if defined(OS_WIN) | 565 #if defined(OS_WIN) |
367 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase)); | 566 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase)); |
368 #endif | 567 #endif |
568 | |
569 // Write the protobuf version. | |
570 hardware->set_system_ram_mb(system_memory_mb); | |
571 #if defined(OS_WIN) | |
572 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase)); | |
573 #endif | |
369 } | 574 } |
370 | 575 |
371 { | 576 { |
577 std::string os_name = base::SysInfo::OperatingSystemName(); | |
578 std::string os_version = base::SysInfo::OperatingSystemVersion(); | |
579 | |
580 // Write the XML version. | |
372 OPEN_ELEMENT_FOR_SCOPE("os"); | 581 OPEN_ELEMENT_FOR_SCOPE("os"); |
373 WriteAttribute("name", | 582 WriteAttribute("name", os_name); |
374 base::SysInfo::OperatingSystemName()); | 583 WriteAttribute("version", os_version); |
375 WriteAttribute("version", | 584 |
376 base::SysInfo::OperatingSystemVersion()); | 585 // Write the protobuf version. |
586 SystemProfileProto::OS* os = system_profile->mutable_os(); | |
587 os->set_name(os_name); | |
588 os->set_version(os_version); | |
377 } | 589 } |
378 | 590 |
379 { | 591 { |
380 OPEN_ELEMENT_FOR_SCOPE("gpu"); | 592 OPEN_ELEMENT_FOR_SCOPE("gpu"); |
381 content::GPUInfo gpu_info = GpuDataManager::GetInstance()->GetGPUInfo(); | 593 const content::GPUInfo& gpu_info = |
594 GpuDataManager::GetInstance()->GetGPUInfo(); | |
595 GpuPerformanceStats gpu_performance_stats = | |
596 GpuPerformanceStats::RetrieveGpuPerformanceStats(); | |
597 | |
598 // Write the XML version. | |
382 WriteIntAttribute("vendorid", gpu_info.vendor_id); | 599 WriteIntAttribute("vendorid", gpu_info.vendor_id); |
383 WriteIntAttribute("deviceid", gpu_info.device_id); | 600 WriteIntAttribute("deviceid", gpu_info.device_id); |
601 | |
602 // Write the protobuf version. | |
603 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu(); | |
604 gpu->set_vendor_id(gpu_info.vendor_id); | |
605 gpu->set_device_id(gpu_info.device_id); | |
606 gpu->set_driver_version(gpu_info.driver_version); | |
607 gpu->set_driver_date(gpu_info.driver_date); | |
608 SystemProfileProto::Hardware::Graphics::PerformanceStatistics* | |
609 gpu_performance = gpu->mutable_performance_statistics(); | |
610 gpu_performance->set_graphics_score(gpu_performance_stats.graphics); | |
611 gpu_performance->set_gaming_score(gpu_performance_stats.gaming); | |
612 gpu_performance->set_overall_score(gpu_performance_stats.overall); | |
384 } | 613 } |
385 | 614 |
386 { | 615 { |
616 const gfx::Size display_size = gfx::Screen::GetPrimaryMonitorSize(); | |
617 int display_width = display_size.width(); | |
618 int display_height = display_size.height(); | |
619 int screen_count = gfx::Screen::GetNumMonitors(); | |
620 | |
621 // Write the XML version. | |
387 OPEN_ELEMENT_FOR_SCOPE("display"); | 622 OPEN_ELEMENT_FOR_SCOPE("display"); |
388 const gfx::Size display_size = gfx::Screen::GetPrimaryMonitorSize(); | 623 WriteIntAttribute("xsize", display_width); |
389 WriteIntAttribute("xsize", display_size.width()); | 624 WriteIntAttribute("ysize", display_height); |
390 WriteIntAttribute("ysize", display_size.height()); | 625 WriteIntAttribute("screens", screen_count); |
391 WriteIntAttribute("screens", gfx::Screen::GetNumMonitors()); | 626 |
627 // Write the protobuf version. | |
628 hardware->set_primary_screen_width(display_width); | |
629 hardware->set_primary_screen_height(display_height); | |
630 hardware->set_screen_count(screen_count); | |
392 } | 631 } |
393 | 632 |
394 { | 633 { |
395 OPEN_ELEMENT_FOR_SCOPE("bookmarks"); | 634 OPEN_ELEMENT_FOR_SCOPE("bookmarks"); |
396 int num_bookmarks_on_bookmark_bar = | 635 int num_bookmarks_on_bookmark_bar = |
397 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar); | 636 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar); |
398 int num_folders_on_bookmark_bar = | 637 int num_folders_on_bookmark_bar = |
399 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar); | 638 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar); |
400 int num_bookmarks_in_other_bookmarks_folder = | 639 int num_bookmarks_in_other_bookmarks_folder = |
401 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder); | 640 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
486 NOTREACHED(); | 725 NOTREACHED(); |
487 break; | 726 break; |
488 } | 727 } |
489 } | 728 } |
490 } | 729 } |
491 } | 730 } |
492 | 731 |
493 void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) { | 732 void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) { |
494 DCHECK(!locked_); | 733 DCHECK(!locked_); |
495 | 734 |
735 // Write the XML version. | |
496 OPEN_ELEMENT_FOR_SCOPE("uielement"); | 736 OPEN_ELEMENT_FOR_SCOPE("uielement"); |
497 WriteAttribute("action", "autocomplete"); | 737 WriteAttribute("action", "autocomplete"); |
498 WriteAttribute("targetidhash", ""); | 738 WriteAttribute("targetidhash", ""); |
499 // TODO(kochi): Properly track windows. | 739 // TODO(kochi): Properly track windows. |
500 WriteIntAttribute("window", 0); | 740 WriteIntAttribute("window", 0); |
501 if (log.tab_id != -1) { | 741 if (log.tab_id != -1) { |
502 // If we know what tab the autocomplete URL was opened in, log it. | 742 // If we know what tab the autocomplete URL was opened in, log it. |
503 WriteIntAttribute("tab", static_cast<int>(log.tab_id)); | 743 WriteIntAttribute("tab", static_cast<int>(log.tab_id)); |
504 } | 744 } |
505 WriteCommonEventAttributes(); | 745 WriteCommonEventAttributes(); |
(...skipping 25 matching lines...) Expand all Loading... | |
531 if (i->provider) | 771 if (i->provider) |
532 WriteAttribute("provider", i->provider->name()); | 772 WriteAttribute("provider", i->provider->name()); |
533 const std::string result_type(AutocompleteMatch::TypeToString(i->type)); | 773 const std::string result_type(AutocompleteMatch::TypeToString(i->type)); |
534 if (!result_type.empty()) | 774 if (!result_type.empty()) |
535 WriteAttribute("resulttype", result_type); | 775 WriteAttribute("resulttype", result_type); |
536 WriteIntAttribute("relevance", i->relevance); | 776 WriteIntAttribute("relevance", i->relevance); |
537 WriteIntAttribute("isstarred", i->starred ? 1 : 0); | 777 WriteIntAttribute("isstarred", i->starred ? 1 : 0); |
538 } | 778 } |
539 } | 779 } |
540 | 780 |
781 // Write the protobuf version. | |
782 OmniboxEventProto* omnibox_event = uma_proto_.add_omnibox_event(); | |
783 omnibox_event->set_time(base::TimeTicks::Now().ToInternalValue()); | |
jar (doing other things)
2012/02/27 20:35:34
ToTimeT returns a count of seconds. ToInternalVal
Ilya Sherman
2012/02/28 00:23:10
Done.
| |
784 if (log.tab_id != -1) { | |
785 // If we know what tab the autocomplete URL was opened in, log it. | |
786 omnibox_event->set_tab_id(log.tab_id); | |
787 } | |
788 omnibox_event->set_typed_length(log.text.length()); | |
789 omnibox_event->set_selected_index(log.selected_index); | |
790 omnibox_event->set_completed_length(log.inline_autocompleted_length); | |
791 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type)); | |
792 for (AutocompleteResult::const_iterator i(log.result.begin()); | |
793 i != log.result.end(); ++i) { | |
794 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion(); | |
795 suggestion->set_provider(AsOmniboxEventProviderType(i->provider)); | |
796 suggestion->set_result_type(AsOmniboxEventResultType(i->type)); | |
797 suggestion->set_relevance(i->relevance); | |
798 suggestion->set_is_starred(i->starred); | |
799 } | |
800 | |
541 ++num_events_; | 801 ++num_events_; |
542 } | 802 } |
OLD | NEW |