[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | cd1adc2 | 2009-01-16 01:29:22 | [diff] [blame] | 5 | #include "chrome/browser/metrics/metrics_log.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | 1eeb5e0 | 2010-07-20 23:02:11 | [diff] [blame] | 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 10 | #include "base/basictypes.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 11 | #include "base/file_util.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 12 | #include "base/memory/scoped_ptr.h" |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 13 | #include "base/perftimer.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 14 | #include "base/string_util.h" |
[email protected] | fadf97f | 2008-09-18 12:18:14 | [diff] [blame] | 15 | #include "base/sys_info.h" |
[email protected] | 37f39e4 | 2010-01-06 17:35:17 | [diff] [blame] | 16 | #include "base/third_party/nspr/prtime.h" |
[email protected] | 1eeb5e0 | 2010-07-20 23:02:11 | [diff] [blame] | 17 | #include "base/time.h" |
| 18 | #include "base/utf_string_conversions.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | #include "chrome/browser/autocomplete/autocomplete.h" |
[email protected] | 9ac4009 | 2010-10-27 23:05:26 | [diff] [blame] | 20 | #include "chrome/browser/autocomplete/autocomplete_match.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 21 | #include "chrome/browser/browser_process.h" |
[email protected] | e9c0ba7 | 2011-06-15 15:46:26 | [diff] [blame] | 22 | #include "chrome/browser/metrics/display_utils.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 23 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 1eeb5e0 | 2010-07-20 23:02:11 | [diff] [blame] | 24 | #include "chrome/common/chrome_version_info.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 25 | #include "chrome/common/logging_chrome.h" |
| 26 | #include "chrome/common/pref_names.h" |
[email protected] | d9f3793 | 2011-05-09 20:09:24 | [diff] [blame] | 27 | #include "content/browser/gpu/gpu_data_manager.h" |
[email protected] | 46072d4 | 2008-07-28 14:49:35 | [diff] [blame] | 28 | #include "googleurl/src/gurl.h" |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame^] | 29 | #include "webkit/plugins/webplugininfo.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 30 | |
| 31 | #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name) |
| 32 | |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 33 | // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx |
| 34 | #if defined(OS_WIN) |
| 35 | extern "C" IMAGE_DOS_HEADER __ImageBase; |
| 36 | #endif |
| 37 | |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 38 | MetricsLog::MetricsLog(const std::string& client_id, int session_id) |
| 39 | : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {} |
[email protected] | 5ed7d457 | 2009-12-23 17:42:41 | [diff] [blame] | 40 | |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 41 | MetricsLog::~MetricsLog() {} |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 42 | |
| 43 | // static |
| 44 | void MetricsLog::RegisterPrefs(PrefService* local_state) { |
| 45 | local_state->RegisterListPref(prefs::kStabilityPluginStats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 46 | } |
| 47 | |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 48 | int64 MetricsLog::GetIncrementalUptime(PrefService* pref) { |
| 49 | base::TimeTicks now = base::TimeTicks::Now(); |
| 50 | static base::TimeTicks last_updated_time(now); |
| 51 | int64 incremental_time = (now - last_updated_time).InSeconds(); |
| 52 | last_updated_time = now; |
| 53 | |
| 54 | if (incremental_time > 0) { |
| 55 | int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec); |
| 56 | metrics_uptime += incremental_time; |
| 57 | pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime); |
| 58 | } |
| 59 | |
| 60 | return incremental_time; |
| 61 | } |
| 62 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 63 | std::string MetricsLog::GetInstallDate() const { |
| 64 | PrefService* pref = g_browser_process->local_state(); |
| 65 | if (pref) { |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 66 | return pref->GetString(prefs::kMetricsClientIDTimestamp); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 67 | } else { |
| 68 | NOTREACHED(); |
| 69 | return "0"; |
| 70 | } |
| 71 | } |
| 72 | |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 73 | // static |
| 74 | std::string MetricsLog::GetVersionString() { |
[email protected] | 0211f57e | 2010-08-27 20:28:42 | [diff] [blame] | 75 | chrome::VersionInfo version_info; |
[email protected] | 30c9180 | 2010-12-18 00:40:17 | [diff] [blame] | 76 | if (!version_info.is_valid()) { |
| 77 | NOTREACHED() << "Unable to retrieve version info."; |
| 78 | return std::string(); |
| 79 | } |
| 80 | |
[email protected] | 0211f57e | 2010-08-27 20:28:42 | [diff] [blame] | 81 | std::string version = version_info.Version(); |
| 82 | if (!version_extension_.empty()) |
| 83 | version += version_extension_; |
| 84 | if (!version_info.IsOfficialBuild()) |
| 85 | version.append("-devel"); |
| 86 | return version; |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 87 | } |
| 88 | |
[email protected] | dec76e80 | 2010-09-23 22:43:53 | [diff] [blame] | 89 | MetricsLog* MetricsLog::AsMetricsLog() { |
| 90 | return this; |
| 91 | } |
| 92 | |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 93 | void MetricsLog::RecordIncrementalStabilityElements() { |
| 94 | DCHECK(!locked_); |
| 95 | |
| 96 | PrefService* pref = g_browser_process->local_state(); |
| 97 | DCHECK(pref); |
| 98 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 99 | OPEN_ELEMENT_FOR_SCOPE("profile"); |
| 100 | WriteCommonEventAttributes(); |
| 101 | |
[email protected] | 9958a32 | 2011-03-08 20:04:17 | [diff] [blame] | 102 | WriteInstallElement(); |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 103 | |
| 104 | { |
| 105 | OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements. |
| 106 | WriteRequiredStabilityAttributes(pref); |
| 107 | WriteRealtimeStabilityAttributes(pref); |
| 108 | |
| 109 | WritePluginStabilityElements(pref); |
| 110 | } |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 111 | } |
| 112 | |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 113 | void MetricsLog::WriteStabilityElement(PrefService* pref) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 114 | DCHECK(!locked_); |
| 115 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 116 | DCHECK(pref); |
| 117 | |
| 118 | // Get stability attributes out of Local State, zeroing out stored values. |
| 119 | // NOTE: This could lead to some data loss if this report isn't successfully |
| 120 | // sent, but that's true for all the metrics. |
| 121 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 122 | OPEN_ELEMENT_FOR_SCOPE("stability"); |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 123 | WriteRequiredStabilityAttributes(pref); |
| 124 | WriteRealtimeStabilityAttributes(pref); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 125 | |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 126 | // TODO(jar): The following are all optional, so we *could* optimize them for |
| 127 | // values of zero (and not include them). |
[email protected] | 8e674e4 | 2008-07-30 16:05:48 | [diff] [blame] | 128 | WriteIntAttribute("incompleteshutdowncount", |
| 129 | pref->GetInteger( |
| 130 | prefs::kStabilityIncompleteSessionEndCount)); |
| 131 | pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 132 | |
| 133 | |
[email protected] | e73c0197 | 2008-08-13 00:18:24 | [diff] [blame] | 134 | WriteIntAttribute("breakpadregistrationok", |
| 135 | pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess)); |
| 136 | pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); |
| 137 | WriteIntAttribute("breakpadregistrationfail", |
| 138 | pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail)); |
| 139 | pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); |
| 140 | WriteIntAttribute("debuggerpresent", |
| 141 | pref->GetInteger(prefs::kStabilityDebuggerPresent)); |
| 142 | pref->SetInteger(prefs::kStabilityDebuggerPresent, 0); |
| 143 | WriteIntAttribute("debuggernotpresent", |
| 144 | pref->GetInteger(prefs::kStabilityDebuggerNotPresent)); |
| 145 | pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 146 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 147 | WritePluginStabilityElements(pref); |
| 148 | } |
| 149 | |
| 150 | void MetricsLog::WritePluginStabilityElements(PrefService* pref) { |
| 151 | // Now log plugin stability info. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 152 | const ListValue* plugin_stats_list = pref->GetList( |
| 153 | prefs::kStabilityPluginStats); |
| 154 | if (plugin_stats_list) { |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 155 | OPEN_ELEMENT_FOR_SCOPE("plugins"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 156 | for (ListValue::const_iterator iter = plugin_stats_list->begin(); |
| 157 | iter != plugin_stats_list->end(); ++iter) { |
| 158 | if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) { |
| 159 | NOTREACHED(); |
| 160 | continue; |
| 161 | } |
| 162 | DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter); |
| 163 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 164 | std::string plugin_name; |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 165 | plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 166 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 167 | OPEN_ELEMENT_FOR_SCOPE("pluginstability"); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 168 | // Use "filename" instead of "name", otherwise we need to update the |
| 169 | // UMA servers. |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 170 | WriteAttribute("filename", CreateBase64Hash(plugin_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 171 | |
| 172 | int launches = 0; |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 173 | plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 174 | WriteIntAttribute("launchcount", launches); |
| 175 | |
| 176 | int instances = 0; |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 177 | plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 178 | WriteIntAttribute("instancecount", instances); |
| 179 | |
| 180 | int crashes = 0; |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 181 | plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 182 | WriteIntAttribute("crashcount", crashes); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | pref->ClearPref(prefs::kStabilityPluginStats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 186 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 187 | } |
| 188 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 189 | void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) { |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 190 | // The server refuses data that doesn't have certain values. crashcount and |
| 191 | // launchcount are currently "required" in the "stability" group. |
| 192 | WriteIntAttribute("launchcount", |
| 193 | pref->GetInteger(prefs::kStabilityLaunchCount)); |
| 194 | pref->SetInteger(prefs::kStabilityLaunchCount, 0); |
| 195 | WriteIntAttribute("crashcount", |
| 196 | pref->GetInteger(prefs::kStabilityCrashCount)); |
| 197 | pref->SetInteger(prefs::kStabilityCrashCount, 0); |
| 198 | } |
| 199 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 200 | void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) { |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 201 | // Update the stats which are critical for real-time stability monitoring. |
| 202 | // Since these are "optional," only list ones that are non-zero, as the counts |
| 203 | // are aggergated (summed) server side. |
| 204 | |
| 205 | int count = pref->GetInteger(prefs::kStabilityPageLoadCount); |
| 206 | if (count) { |
| 207 | WriteIntAttribute("pageloadcount", count); |
| 208 | pref->SetInteger(prefs::kStabilityPageLoadCount, 0); |
| 209 | } |
| 210 | |
| 211 | count = pref->GetInteger(prefs::kStabilityRendererCrashCount); |
| 212 | if (count) { |
| 213 | WriteIntAttribute("renderercrashcount", count); |
| 214 | pref->SetInteger(prefs::kStabilityRendererCrashCount, 0); |
| 215 | } |
| 216 | |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 217 | count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount); |
| 218 | if (count) { |
| 219 | WriteIntAttribute("extensionrenderercrashcount", count); |
| 220 | pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0); |
| 221 | } |
| 222 | |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 223 | count = pref->GetInteger(prefs::kStabilityRendererHangCount); |
| 224 | if (count) { |
| 225 | WriteIntAttribute("rendererhangcount", count); |
| 226 | pref->SetInteger(prefs::kStabilityRendererHangCount, 0); |
| 227 | } |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 228 | |
| 229 | count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount); |
| 230 | if (count) { |
| 231 | WriteIntAttribute("childprocesscrashcount", count); |
| 232 | pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); |
| 233 | } |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 234 | |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 235 | #if defined(OS_CHROMEOS) |
| 236 | count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount); |
| 237 | if (count) { |
| 238 | // TODO(kmixter): Write attribute once log server supports it |
| 239 | // and remove warning log. |
| 240 | // WriteIntAttribute("otherusercrashcount", count); |
| 241 | LOG(WARNING) << "Not yet able to send otherusercrashcount=" |
| 242 | << count; |
| 243 | pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0); |
| 244 | } |
| 245 | |
| 246 | count = pref->GetInteger(prefs::kStabilityKernelCrashCount); |
| 247 | if (count) { |
| 248 | // TODO(kmixter): Write attribute once log server supports it |
| 249 | // and remove warning log. |
| 250 | // WriteIntAttribute("kernelcrashcount", count); |
| 251 | LOG(WARNING) << "Not yet able to send kernelcrashcount=" |
| 252 | << count; |
| 253 | pref->SetInteger(prefs::kStabilityKernelCrashCount, 0); |
| 254 | } |
| 255 | |
| 256 | count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount); |
| 257 | if (count) { |
| 258 | // TODO(kmixter): Write attribute once log server supports it |
| 259 | // and remove warning log. |
| 260 | // WriteIntAttribute("systemuncleanshutdowns", count); |
| 261 | LOG(WARNING) << "Not yet able to send systemuncleanshutdowns=" |
| 262 | << count; |
| 263 | pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0); |
| 264 | } |
| 265 | #endif // OS_CHROMEOS |
| 266 | |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 267 | int64 recent_duration = GetIncrementalUptime(pref); |
| 268 | if (recent_duration) |
| 269 | WriteInt64Attribute("uptimesec", recent_duration); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 270 | } |
| 271 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 272 | void MetricsLog::WritePluginList( |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame^] | 273 | const std::vector<webkit::WebPluginInfo>& plugin_list) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 274 | DCHECK(!locked_); |
| 275 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 276 | OPEN_ELEMENT_FOR_SCOPE("plugins"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 277 | |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame^] | 278 | for (std::vector<webkit::WebPluginInfo>::const_iterator iter = |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 279 | plugin_list.begin(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 280 | iter != plugin_list.end(); ++iter) { |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 281 | OPEN_ELEMENT_FOR_SCOPE("plugin"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 282 | |
| 283 | // Plugin name and filename are hashed for the privacy of those |
| 284 | // testing unreleased new extensions. |
[email protected] | c9d81137 | 2010-06-23 21:44:57 | [diff] [blame] | 285 | WriteAttribute("name", CreateBase64Hash(UTF16ToUTF8(iter->name))); |
[email protected] | 0abb165 | 2011-02-07 23:37:55 | [diff] [blame] | 286 | std::string filename_bytes = |
| 287 | #if defined(OS_WIN) |
| 288 | UTF16ToUTF8(iter->path.BaseName().value()); |
| 289 | #else |
| 290 | iter->path.BaseName().value(); |
| 291 | #endif |
| 292 | WriteAttribute("filename", CreateBase64Hash(filename_bytes)); |
[email protected] | c9d81137 | 2010-06-23 21:44:57 | [diff] [blame] | 293 | WriteAttribute("version", UTF16ToUTF8(iter->version)); |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame^] | 294 | WriteIntAttribute("disabled", !webkit::IsPluginEnabled(*iter)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 295 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 296 | } |
| 297 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 298 | void MetricsLog::WriteInstallElement() { |
| 299 | OPEN_ELEMENT_FOR_SCOPE("install"); |
| 300 | WriteAttribute("installdate", GetInstallDate()); |
| 301 | WriteIntAttribute("buildid", 0); // We're using appversion instead. |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 302 | } |
| 303 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 304 | void MetricsLog::RecordEnvironment( |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame^] | 305 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 306 | const DictionaryValue* profile_metrics) { |
| 307 | DCHECK(!locked_); |
| 308 | |
| 309 | PrefService* pref = g_browser_process->local_state(); |
| 310 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 311 | OPEN_ELEMENT_FOR_SCOPE("profile"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 312 | WriteCommonEventAttributes(); |
| 313 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 314 | WriteInstallElement(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 315 | |
| 316 | WritePluginList(plugin_list); |
| 317 | |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 318 | WriteStabilityElement(pref); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 319 | |
| 320 | { |
| 321 | OPEN_ELEMENT_FOR_SCOPE("cpu"); |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 322 | WriteAttribute("arch", base::SysInfo::CPUArchitecture()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 326 | OPEN_ELEMENT_FOR_SCOPE("memory"); |
[email protected] | ed6fc35 | 2008-09-18 12:44:40 | [diff] [blame] | 327 | WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB()); |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 328 | #if defined(OS_WIN) |
| 329 | WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase)); |
| 330 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | { |
| 334 | OPEN_ELEMENT_FOR_SCOPE("os"); |
| 335 | WriteAttribute("name", |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 336 | base::SysInfo::OperatingSystemName()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 337 | WriteAttribute("version", |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 338 | base::SysInfo::OperatingSystemVersion()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | { |
[email protected] | e8c287c87 | 2010-07-20 00:49:42 | [diff] [blame] | 342 | OPEN_ELEMENT_FOR_SCOPE("gpu"); |
[email protected] | 27d8778e | 2011-03-09 22:00:59 | [diff] [blame] | 343 | GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance(); |
| 344 | if (gpu_data_manager) { |
| 345 | WriteIntAttribute("vendorid", gpu_data_manager->gpu_info().vendor_id); |
| 346 | WriteIntAttribute("deviceid", gpu_data_manager->gpu_info().device_id); |
[email protected] | 06b2fc9 | 2011-02-22 22:00:40 | [diff] [blame] | 347 | } |
[email protected] | e8c287c87 | 2010-07-20 00:49:42 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 351 | OPEN_ELEMENT_FOR_SCOPE("display"); |
| 352 | int width = 0; |
| 353 | int height = 0; |
[email protected] | e9c0ba7 | 2011-06-15 15:46:26 | [diff] [blame] | 354 | DisplayUtils::GetPrimaryDisplayDimensions(&width, &height); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 355 | WriteIntAttribute("xsize", width); |
| 356 | WriteIntAttribute("ysize", height); |
[email protected] | e9c0ba7 | 2011-06-15 15:46:26 | [diff] [blame] | 357 | WriteIntAttribute("screens", DisplayUtils::GetDisplayCount()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | { |
| 361 | OPEN_ELEMENT_FOR_SCOPE("bookmarks"); |
| 362 | int num_bookmarks_on_bookmark_bar = |
| 363 | pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar); |
| 364 | int num_folders_on_bookmark_bar = |
| 365 | pref->GetInteger(prefs::kNumFoldersOnBookmarkBar); |
| 366 | int num_bookmarks_in_other_bookmarks_folder = |
| 367 | pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder); |
| 368 | int num_folders_in_other_bookmarks_folder = |
| 369 | pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder); |
| 370 | { |
| 371 | OPEN_ELEMENT_FOR_SCOPE("bookmarklocation"); |
| 372 | WriteAttribute("name", "full-tree"); |
| 373 | WriteIntAttribute("foldercount", |
| 374 | num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder); |
| 375 | WriteIntAttribute("itemcount", |
| 376 | num_bookmarks_on_bookmark_bar + |
| 377 | num_bookmarks_in_other_bookmarks_folder); |
| 378 | } |
| 379 | { |
| 380 | OPEN_ELEMENT_FOR_SCOPE("bookmarklocation"); |
| 381 | WriteAttribute("name", "toolbar"); |
| 382 | WriteIntAttribute("foldercount", num_folders_on_bookmark_bar); |
| 383 | WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | { |
| 388 | OPEN_ELEMENT_FOR_SCOPE("keywords"); |
| 389 | WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords)); |
| 390 | } |
| 391 | |
| 392 | if (profile_metrics) |
| 393 | WriteAllProfilesMetrics(*profile_metrics); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | void MetricsLog::WriteAllProfilesMetrics( |
| 397 | const DictionaryValue& all_profiles_metrics) { |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 398 | const std::string profile_prefix(prefs::kProfilePrefix); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 399 | for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys(); |
| 400 | i != all_profiles_metrics.end_keys(); ++i) { |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 401 | const std::string& key_name = *i; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 402 | if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) { |
| 403 | DictionaryValue* profile; |
[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 404 | if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name, |
| 405 | &profile)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 406 | WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile); |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 411 | void MetricsLog::WriteProfileMetrics(const std::string& profileidhash, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 412 | const DictionaryValue& profile_metrics) { |
| 413 | OPEN_ELEMENT_FOR_SCOPE("userprofile"); |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 414 | WriteAttribute("profileidhash", profileidhash); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 415 | for (DictionaryValue::key_iterator i = profile_metrics.begin_keys(); |
| 416 | i != profile_metrics.end_keys(); ++i) { |
| 417 | Value* value; |
[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 418 | if (profile_metrics.GetWithoutPathExpansion(*i, &value)) { |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 419 | DCHECK(*i != "id"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 420 | switch (value->GetType()) { |
| 421 | case Value::TYPE_STRING: { |
[email protected] | 5e324b7 | 2008-12-18 00:07:59 | [diff] [blame] | 422 | std::string string_value; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 423 | if (value->GetAsString(&string_value)) { |
| 424 | OPEN_ELEMENT_FOR_SCOPE("profileparam"); |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 425 | WriteAttribute("name", *i); |
[email protected] | 5e324b7 | 2008-12-18 00:07:59 | [diff] [blame] | 426 | WriteAttribute("value", string_value); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 427 | } |
| 428 | break; |
| 429 | } |
| 430 | |
| 431 | case Value::TYPE_BOOLEAN: { |
| 432 | bool bool_value; |
| 433 | if (value->GetAsBoolean(&bool_value)) { |
| 434 | OPEN_ELEMENT_FOR_SCOPE("profileparam"); |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 435 | WriteAttribute("name", *i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 436 | WriteIntAttribute("value", bool_value ? 1 : 0); |
| 437 | } |
| 438 | break; |
| 439 | } |
| 440 | |
| 441 | case Value::TYPE_INTEGER: { |
| 442 | int int_value; |
| 443 | if (value->GetAsInteger(&int_value)) { |
| 444 | OPEN_ELEMENT_FOR_SCOPE("profileparam"); |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 445 | WriteAttribute("name", *i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 446 | WriteIntAttribute("value", int_value); |
| 447 | } |
| 448 | break; |
| 449 | } |
| 450 | |
| 451 | default: |
| 452 | NOTREACHED(); |
| 453 | break; |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) { |
| 460 | DCHECK(!locked_); |
| 461 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 462 | OPEN_ELEMENT_FOR_SCOPE("uielement"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 463 | WriteAttribute("action", "autocomplete"); |
| 464 | WriteAttribute("targetidhash", ""); |
| 465 | // TODO(kochi): Properly track windows. |
| 466 | WriteIntAttribute("window", 0); |
| 467 | WriteCommonEventAttributes(); |
| 468 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 469 | { |
| 470 | OPEN_ELEMENT_FOR_SCOPE("autocomplete"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 471 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 472 | WriteIntAttribute("typedlength", static_cast<int>(log.text.length())); |
| 473 | WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index)); |
| 474 | WriteIntAttribute("completedlength", |
| 475 | static_cast<int>(log.inline_autocompleted_length)); |
[email protected] | 381e299 | 2008-12-16 01:41:00 | [diff] [blame] | 476 | const std::string input_type( |
| 477 | AutocompleteInput::TypeToString(log.input_type)); |
| 478 | if (!input_type.empty()) |
| 479 | WriteAttribute("inputtype", input_type); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 480 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 481 | for (AutocompleteResult::const_iterator i(log.result.begin()); |
| 482 | i != log.result.end(); ++i) { |
| 483 | OPEN_ELEMENT_FOR_SCOPE("autocompleteitem"); |
| 484 | if (i->provider) |
| 485 | WriteAttribute("provider", i->provider->name()); |
[email protected] | 381e299 | 2008-12-16 01:41:00 | [diff] [blame] | 486 | const std::string result_type(AutocompleteMatch::TypeToString(i->type)); |
| 487 | if (!result_type.empty()) |
| 488 | WriteAttribute("resulttype", result_type); |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 489 | WriteIntAttribute("relevance", i->relevance); |
| 490 | WriteIntAttribute("isstarred", i->starred ? 1 : 0); |
| 491 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 492 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 493 | |
| 494 | ++num_events_; |
| 495 | } |