isherman@chromium.org | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 1 | // Copyright (c) 2012 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 | |
ben@chromium.org | 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 | |
thestig@chromium.org | 1eeb5e0 | 2010-07-20 23:02:11 | [diff] [blame] | 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
deanm@chromium.org | 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" |
thakis@chromium.org | 054c801 | 2011-11-16 00:12:42 | [diff] [blame] | 12 | #include "base/lazy_instance.h" |
levin@chromium.org | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 13 | #include "base/memory/scoped_ptr.h" |
zelidrag@chromium.org | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 14 | #include "base/perftimer.h" |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 15 | #include "base/string_number_conversions.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 16 | #include "base/string_util.h" |
deanm@chromium.org | fadf97f | 2008-09-18 12:18:14 | [diff] [blame] | 17 | #include "base/sys_info.h" |
jar@chromium.org | 37f39e4 | 2010-01-06 17:35:17 | [diff] [blame] | 18 | #include "base/third_party/nspr/prtime.h" |
thestig@chromium.org | 1eeb5e0 | 2010-07-20 23:02:11 | [diff] [blame] | 19 | #include "base/time.h" |
| 20 | #include "base/utf_string_conversions.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 21 | #include "chrome/browser/autocomplete/autocomplete.h" |
scr@chromium.org | 9ac4009 | 2010-10-27 23:05:26 | [diff] [blame] | 22 | #include "chrome/browser/autocomplete/autocomplete_match.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 23 | #include "chrome/browser/browser_process.h" |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 24 | #include "chrome/browser/gpu_performance_stats.h" |
bauerb@chromium.org | 1008498 | 2011-08-19 17:56:56 | [diff] [blame] | 25 | #include "chrome/browser/plugin_prefs.h" |
evan@chromium.org | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 26 | #include "chrome/browser/prefs/pref_service.h" |
bauerb@chromium.org | 1008498 | 2011-08-19 17:56:56 | [diff] [blame] | 27 | #include "chrome/browser/profiles/profile_manager.h" |
thestig@chromium.org | 1eeb5e0 | 2010-07-20 23:02:11 | [diff] [blame] | 28 | #include "chrome/common/chrome_version_info.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 29 | #include "chrome/common/logging_chrome.h" |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 30 | #include "chrome/common/metrics/proto/omnibox_event.pb.h" |
| 31 | #include "chrome/common/metrics/proto/system_profile.pb.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 32 | #include "chrome/common/pref_names.h" |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 33 | #include "content/public/browser/content_browser_client.h" |
jam@chromium.org | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 34 | #include "content/public/browser/gpu_data_manager.h" |
| 35 | #include "content/public/common/gpu_info.h" |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 36 | #include "content/public/common/content_client.h" |
deanm@google.com | 46072d4 | 2008-07-28 14:49:35 | [diff] [blame] | 37 | #include "googleurl/src/gurl.h" |
derat@chromium.org | 6b7d954ff | 2011-10-25 00:39:35 | [diff] [blame] | 38 | #include "ui/gfx/screen.h" |
cpu@chromium.org | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 39 | #include "webkit/plugins/webplugininfo.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 40 | |
| 41 | #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name) |
| 42 | |
deanm@chromium.org | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 43 | // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx |
| 44 | #if defined(OS_WIN) |
| 45 | extern "C" IMAGE_DOS_HEADER __ImageBase; |
| 46 | #endif |
| 47 | |
jam@chromium.org | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 48 | using content::GpuDataManager; |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 49 | using metrics::OmniboxEventProto; |
| 50 | using metrics::SystemProfileProto; |
jam@chromium.org | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 51 | |
isherman@chromium.org | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 52 | namespace { |
| 53 | |
| 54 | // Returns the date at which the current metrics client ID was created as |
| 55 | // a string containing milliseconds since the epoch, or "0" if none was found. |
| 56 | std::string GetInstallDate() { |
| 57 | PrefService* pref = g_browser_process->local_state(); |
| 58 | if (pref) { |
| 59 | return pref->GetString(prefs::kMetricsClientIDTimestamp); |
| 60 | } else { |
| 61 | NOTREACHED(); |
| 62 | return "0"; |
| 63 | } |
| 64 | } |
| 65 | |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 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 | |
isherman@chromium.org | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 145 | // Returns the plugin preferences corresponding for this user, if available. |
| 146 | // If multiple user profiles are loaded, returns the preferences corresponding |
| 147 | // to an arbitrary one of the profiles. |
| 148 | PluginPrefs* GetPluginPrefs() { |
| 149 | ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 150 | std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); |
| 151 | if (profiles.empty()) |
| 152 | return NULL; |
| 153 | |
| 154 | return PluginPrefs::GetForProfile(profiles.front()); |
| 155 | } |
| 156 | |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 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 | |
isherman@chromium.org | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 168 | } // namespace |
| 169 | |
fischman@chromium.org | 67f92bc3 | 2012-01-26 01:56:19 | [diff] [blame] | 170 | static base::LazyInstance<std::string>::Leaky |
thakis@chromium.org | 054c801 | 2011-11-16 00:12:42 | [diff] [blame] | 171 | g_version_extension = LAZY_INSTANCE_INITIALIZER; |
| 172 | |
ananta@chromium.org | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 173 | MetricsLog::MetricsLog(const std::string& client_id, int session_id) |
| 174 | : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {} |
jar@chromium.org | 5ed7d457 | 2009-12-23 17:42:41 | [diff] [blame] | 175 | |
ananta@chromium.org | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 176 | MetricsLog::~MetricsLog() {} |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 177 | |
| 178 | // static |
| 179 | void MetricsLog::RegisterPrefs(PrefService* local_state) { |
| 180 | local_state->RegisterListPref(prefs::kStabilityPluginStats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 181 | } |
| 182 | |
isherman@chromium.org | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 183 | // static |
jar@chromium.org | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 184 | int64 MetricsLog::GetIncrementalUptime(PrefService* pref) { |
| 185 | base::TimeTicks now = base::TimeTicks::Now(); |
| 186 | static base::TimeTicks last_updated_time(now); |
| 187 | int64 incremental_time = (now - last_updated_time).InSeconds(); |
| 188 | last_updated_time = now; |
| 189 | |
| 190 | if (incremental_time > 0) { |
| 191 | int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec); |
| 192 | metrics_uptime += incremental_time; |
| 193 | pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime); |
| 194 | } |
| 195 | |
| 196 | return incremental_time; |
| 197 | } |
| 198 | |
ananta@chromium.org | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 199 | // static |
| 200 | std::string MetricsLog::GetVersionString() { |
evan@chromium.org | 0211f57e | 2010-08-27 20:28:42 | [diff] [blame] | 201 | chrome::VersionInfo version_info; |
dmaclach@chromium.org | 30c9180 | 2010-12-18 00:40:17 | [diff] [blame] | 202 | if (!version_info.is_valid()) { |
| 203 | NOTREACHED() << "Unable to retrieve version info."; |
| 204 | return std::string(); |
| 205 | } |
| 206 | |
evan@chromium.org | 0211f57e | 2010-08-27 20:28:42 | [diff] [blame] | 207 | std::string version = version_info.Version(); |
thakis@chromium.org | 054c801 | 2011-11-16 00:12:42 | [diff] [blame] | 208 | if (!version_extension().empty()) |
| 209 | version += version_extension(); |
evan@chromium.org | 0211f57e | 2010-08-27 20:28:42 | [diff] [blame] | 210 | if (!version_info.IsOfficialBuild()) |
| 211 | version.append("-devel"); |
| 212 | return version; |
ananta@chromium.org | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 213 | } |
| 214 | |
thakis@chromium.org | 054c801 | 2011-11-16 00:12:42 | [diff] [blame] | 215 | // static |
| 216 | void MetricsLog::set_version_extension(const std::string& extension) { |
| 217 | g_version_extension.Get() = extension; |
| 218 | } |
| 219 | |
| 220 | // static |
| 221 | const std::string& MetricsLog::version_extension() { |
| 222 | return g_version_extension.Get(); |
| 223 | } |
| 224 | |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 225 | void MetricsLog::RecordIncrementalStabilityElements( |
| 226 | const std::vector<webkit::WebPluginInfo>& plugin_list) { |
jar@google.com | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 227 | DCHECK(!locked_); |
| 228 | |
| 229 | PrefService* pref = g_browser_process->local_state(); |
| 230 | DCHECK(pref); |
| 231 | |
jar@google.com | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 232 | OPEN_ELEMENT_FOR_SCOPE("profile"); |
| 233 | WriteCommonEventAttributes(); |
| 234 | |
jar@chromium.org | 9958a32 | 2011-03-08 20:04:17 | [diff] [blame] | 235 | WriteInstallElement(); |
jar@google.com | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 236 | |
| 237 | { |
| 238 | OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements. |
| 239 | WriteRequiredStabilityAttributes(pref); |
| 240 | WriteRealtimeStabilityAttributes(pref); |
| 241 | |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 242 | WritePluginStabilityElements(plugin_list, pref); |
jar@google.com | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 243 | } |
jar@google.com | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 244 | } |
| 245 | |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 246 | void MetricsLog::WriteStabilityElement( |
| 247 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
| 248 | PrefService* pref) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 249 | DCHECK(!locked_); |
| 250 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 251 | // Get stability attributes out of Local State, zeroing out stored values. |
| 252 | // NOTE: This could lead to some data loss if this report isn't successfully |
| 253 | // sent, but that's true for all the metrics. |
| 254 | |
pkasting@chromium.org | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 255 | OPEN_ELEMENT_FOR_SCOPE("stability"); |
jar@google.com | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 256 | WriteRequiredStabilityAttributes(pref); |
| 257 | WriteRealtimeStabilityAttributes(pref); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 258 | |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 259 | int incomplete_shutdown_count = |
| 260 | pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount); |
evanm@google.com | 8e674e4 | 2008-07-30 16:05:48 | [diff] [blame] | 261 | pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 262 | int breakpad_registration_success_count = |
| 263 | pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess); |
cpu@google.com | e73c0197 | 2008-08-13 00:18:24 | [diff] [blame] | 264 | pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 265 | int breakpad_registration_failure_count = |
| 266 | pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail); |
cpu@google.com | e73c0197 | 2008-08-13 00:18:24 | [diff] [blame] | 267 | pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 268 | int debugger_present_count = |
| 269 | pref->GetInteger(prefs::kStabilityDebuggerPresent); |
cpu@google.com | e73c0197 | 2008-08-13 00:18:24 | [diff] [blame] | 270 | pref->SetInteger(prefs::kStabilityDebuggerPresent, 0); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 271 | int debugger_not_present_count = |
| 272 | pref->GetInteger(prefs::kStabilityDebuggerNotPresent); |
cpu@google.com | e73c0197 | 2008-08-13 00:18:24 | [diff] [blame] | 273 | pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 274 | |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 275 | // TODO(jar): The following are all optional, so we *could* optimize them for |
| 276 | // values of zero (and not include them). |
| 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); |
| 286 | |
| 287 | // Write the protobuf version. |
| 288 | SystemProfileProto::Stability* stability = |
| 289 | uma_proto_.mutable_system_profile()->mutable_stability(); |
| 290 | stability->set_incomplete_shutdown_count(incomplete_shutdown_count); |
| 291 | stability->set_breakpad_registration_success_count( |
| 292 | breakpad_registration_success_count); |
| 293 | stability->set_breakpad_registration_failure_count( |
| 294 | breakpad_registration_failure_count); |
| 295 | stability->set_debugger_present_count(debugger_present_count); |
| 296 | stability->set_debugger_not_present_count(debugger_not_present_count); |
| 297 | |
| 298 | WritePluginStabilityElements(plugin_list, pref); |
jar@google.com | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 299 | } |
| 300 | |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 301 | void MetricsLog::WritePluginStabilityElements( |
| 302 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
| 303 | PrefService* pref) { |
jar@google.com | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 304 | // Now log plugin stability info. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 305 | const ListValue* plugin_stats_list = pref->GetList( |
| 306 | prefs::kStabilityPluginStats); |
isherman@chromium.org | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 307 | if (!plugin_stats_list) |
| 308 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 309 | |
isherman@chromium.org | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 310 | OPEN_ELEMENT_FOR_SCOPE("plugins"); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 311 | SystemProfileProto::Stability* stability = |
| 312 | uma_proto_.mutable_system_profile()->mutable_stability(); |
| 313 | PluginPrefs* plugin_prefs = GetPluginPrefs(); |
isherman@chromium.org | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 314 | for (ListValue::const_iterator iter = plugin_stats_list->begin(); |
| 315 | iter != plugin_stats_list->end(); ++iter) { |
| 316 | if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) { |
| 317 | NOTREACHED(); |
| 318 | continue; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 319 | } |
isherman@chromium.org | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 320 | DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 321 | |
isherman@chromium.org | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 322 | std::string plugin_name; |
| 323 | plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name); |
| 324 | |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 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. |
isherman@chromium.org | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 330 | OPEN_ELEMENT_FOR_SCOPE("pluginstability"); |
| 331 | // Use "filename" instead of "name", otherwise we need to update the |
| 332 | // UMA servers. |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 333 | WriteAttribute("filename", base64_name_hash); |
isherman@chromium.org | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 334 | |
| 335 | int launches = 0; |
| 336 | plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches); |
| 337 | WriteIntAttribute("launchcount", launches); |
| 338 | |
| 339 | int instances = 0; |
| 340 | plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances); |
| 341 | WriteIntAttribute("instancecount", instances); |
| 342 | |
| 343 | int crashes = 0; |
| 344 | plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes); |
| 345 | WriteIntAttribute("crashcount", crashes); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 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); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 376 | } |
isherman@chromium.org | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 377 | |
| 378 | pref->ClearPref(prefs::kStabilityPluginStats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 379 | } |
| 380 | |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 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. |
jar@google.com | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 385 | void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) { |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 386 | int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount); |
jar@google.com | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 387 | pref->SetInteger(prefs::kStabilityLaunchCount, 0); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 388 | int crash_count = pref->GetInteger(prefs::kStabilityCrashCount); |
jar@google.com | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 389 | pref->SetInteger(prefs::kStabilityCrashCount, 0); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 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); |
jar@google.com | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 400 | } |
| 401 | |
jar@google.com | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 402 | void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) { |
jar@google.com | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 403 | // Update the stats which are critical for real-time stability monitoring. |
| 404 | // Since these are "optional," only list ones that are non-zero, as the counts |
| 405 | // are aggergated (summed) server side. |
| 406 | |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 407 | SystemProfileProto::Stability* stability = |
| 408 | uma_proto_.mutable_system_profile()->mutable_stability(); |
jar@google.com | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 409 | int count = pref->GetInteger(prefs::kStabilityPageLoadCount); |
| 410 | if (count) { |
| 411 | WriteIntAttribute("pageloadcount", count); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 412 | stability->set_page_load_count(count); |
jar@google.com | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 413 | pref->SetInteger(prefs::kStabilityPageLoadCount, 0); |
| 414 | } |
| 415 | |
| 416 | count = pref->GetInteger(prefs::kStabilityRendererCrashCount); |
| 417 | if (count) { |
| 418 | WriteIntAttribute("renderercrashcount", count); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 419 | stability->set_renderer_crash_count(count); |
jar@google.com | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 420 | pref->SetInteger(prefs::kStabilityRendererCrashCount, 0); |
| 421 | } |
| 422 | |
asargent@chromium.org | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 423 | count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount); |
| 424 | if (count) { |
| 425 | WriteIntAttribute("extensionrenderercrashcount", count); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 426 | stability->set_extension_renderer_crash_count(count); |
asargent@chromium.org | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 427 | pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0); |
| 428 | } |
| 429 | |
jar@google.com | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 430 | count = pref->GetInteger(prefs::kStabilityRendererHangCount); |
| 431 | if (count) { |
| 432 | WriteIntAttribute("rendererhangcount", count); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 433 | stability->set_renderer_hang_count(count); |
jar@google.com | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 434 | pref->SetInteger(prefs::kStabilityRendererHangCount, 0); |
| 435 | } |
asargent@chromium.org | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 436 | |
| 437 | count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount); |
| 438 | if (count) { |
| 439 | WriteIntAttribute("childprocesscrashcount", count); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 440 | stability->set_child_process_crash_count(count); |
asargent@chromium.org | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 441 | pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); |
| 442 | } |
jar@chromium.org | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 443 | |
petkov@chromium.org | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 444 | #if defined(OS_CHROMEOS) |
| 445 | count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount); |
| 446 | if (count) { |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 447 | stability->set_other_user_crash_count(count); |
petkov@chromium.org | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 448 | pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0); |
| 449 | } |
| 450 | |
| 451 | count = pref->GetInteger(prefs::kStabilityKernelCrashCount); |
| 452 | if (count) { |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 453 | stability->set_kernel_crash_count(count); |
petkov@chromium.org | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 454 | pref->SetInteger(prefs::kStabilityKernelCrashCount, 0); |
| 455 | } |
| 456 | |
| 457 | count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount); |
| 458 | if (count) { |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 459 | stability->set_unclean_system_shutdown_count(count); |
petkov@chromium.org | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 460 | pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0); |
| 461 | } |
| 462 | #endif // OS_CHROMEOS |
| 463 | |
jar@chromium.org | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 464 | int64 recent_duration = GetIncrementalUptime(pref); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 465 | if (recent_duration) { |
jar@chromium.org | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 466 | WriteInt64Attribute("uptimesec", recent_duration); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 467 | stability->set_uptime_sec(recent_duration); |
| 468 | } |
jar@google.com | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 469 | } |
| 470 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 471 | void MetricsLog::WritePluginList( |
cpu@chromium.org | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 472 | const std::vector<webkit::WebPluginInfo>& plugin_list) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 473 | DCHECK(!locked_); |
| 474 | |
isherman@chromium.org | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 475 | PluginPrefs* plugin_prefs = GetPluginPrefs(); |
bauerb@chromium.org | 1008498 | 2011-08-19 17:56:56 | [diff] [blame] | 476 | |
pkasting@chromium.org | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 477 | OPEN_ELEMENT_FOR_SCOPE("plugins"); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 478 | SystemProfileProto* system_profile = uma_proto_.mutable_system_profile(); |
cpu@chromium.org | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 479 | for (std::vector<webkit::WebPluginInfo>::const_iterator iter = |
brettw@chromium.org | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 480 | plugin_list.begin(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 481 | iter != plugin_list.end(); ++iter) { |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 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. |
pkasting@chromium.org | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 496 | OPEN_ELEMENT_FOR_SCOPE("plugin"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 497 | |
| 498 | // Plugin name and filename are hashed for the privacy of those |
| 499 | // testing unreleased new extensions. |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 500 | WriteAttribute("name", base64_name_hash); |
| 501 | WriteAttribute("filename", base64_filename_hash); |
stuartmorgan@chromium.org | c9d81137 | 2010-06-23 21:44:57 | [diff] [blame] | 502 | WriteAttribute("version", UTF16ToUTF8(iter->version)); |
bauerb@chromium.org | 24c935e5 | 2011-09-01 12:06:26 | [diff] [blame] | 503 | if (plugin_prefs) |
| 504 | WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter)); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 505 | |
| 506 | // Write the protobuf version. |
| 507 | SystemProfileProto::Plugin* plugin = system_profile->add_plugin(); |
| 508 | SetPluginInfo(*iter, plugin_prefs, plugin); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 509 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 510 | } |
| 511 | |
jar@google.com | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 512 | void MetricsLog::WriteInstallElement() { |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 513 | std::string install_date = GetInstallDate(); |
| 514 | |
| 515 | // Write the XML version. |
jar@google.com | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 516 | OPEN_ELEMENT_FOR_SCOPE("install"); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 517 | WriteAttribute("installdate", install_date); |
jar@google.com | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 518 | WriteIntAttribute("buildid", 0); // We're using appversion instead. |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 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); |
jar@google.com | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 525 | } |
| 526 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 527 | void MetricsLog::RecordEnvironment( |
cpu@chromium.org | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 528 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 529 | const DictionaryValue* profile_metrics) { |
| 530 | DCHECK(!locked_); |
| 531 | |
| 532 | PrefService* pref = g_browser_process->local_state(); |
| 533 | |
pkasting@chromium.org | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 534 | OPEN_ELEMENT_FOR_SCOPE("profile"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 535 | WriteCommonEventAttributes(); |
| 536 | |
jar@google.com | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 537 | WriteInstallElement(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 538 | |
| 539 | WritePluginList(plugin_list); |
| 540 | |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 541 | WriteStabilityElement(plugin_list, pref); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 542 | |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 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(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 548 | { |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 549 | std::string cpu_architecture = base::SysInfo::CPUArchitecture(); |
| 550 | |
| 551 | // Write the XML version. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 552 | OPEN_ELEMENT_FOR_SCOPE("cpu"); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 553 | WriteAttribute("arch", cpu_architecture); |
| 554 | |
| 555 | // Write the protobuf version. |
| 556 | hardware->set_cpu_architecture(cpu_architecture); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | { |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 560 | int system_memory_mb = base::SysInfo::AmountOfPhysicalMemoryMB(); |
| 561 | |
| 562 | // Write the XML version. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 563 | OPEN_ELEMENT_FOR_SCOPE("memory"); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 564 | WriteIntAttribute("mb", system_memory_mb); |
deanm@chromium.org | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 565 | #if defined(OS_WIN) |
| 566 | WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase)); |
| 567 | #endif |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 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 |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | { |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 577 | std::string os_name = base::SysInfo::OperatingSystemName(); |
| 578 | std::string os_version = base::SysInfo::OperatingSystemVersion(); |
| 579 | |
| 580 | // Write the XML version. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 581 | OPEN_ELEMENT_FOR_SCOPE("os"); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 582 | WriteAttribute("name", os_name); |
| 583 | WriteAttribute("version", os_version); |
| 584 | |
| 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); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | { |
rlp@chromium.org | e8c287c87 | 2010-07-20 00:49:42 | [diff] [blame] | 592 | OPEN_ELEMENT_FOR_SCOPE("gpu"); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 593 | const content::GPUInfo& gpu_info = |
| 594 | GpuDataManager::GetInstance()->GetGPUInfo(); |
| 595 | GpuPerformanceStats gpu_performance_stats = |
| 596 | GpuPerformanceStats::RetrieveGpuPerformanceStats(); |
| 597 | |
| 598 | // Write the XML version. |
jam@chromium.org | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 599 | WriteIntAttribute("vendorid", gpu_info.vendor_id); |
| 600 | WriteIntAttribute("deviceid", gpu_info.device_id); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 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); |
rlp@chromium.org | e8c287c87 | 2010-07-20 00:49:42 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | { |
derat@chromium.org | 6b7d954ff | 2011-10-25 00:39:35 | [diff] [blame] | 616 | const gfx::Size display_size = gfx::Screen::GetPrimaryMonitorSize(); |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 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. |
| 622 | OPEN_ELEMENT_FOR_SCOPE("display"); |
| 623 | WriteIntAttribute("xsize", display_width); |
| 624 | WriteIntAttribute("ysize", display_height); |
| 625 | WriteIntAttribute("screens", screen_count); |
| 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); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | { |
| 634 | OPEN_ELEMENT_FOR_SCOPE("bookmarks"); |
| 635 | int num_bookmarks_on_bookmark_bar = |
| 636 | pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar); |
| 637 | int num_folders_on_bookmark_bar = |
| 638 | pref->GetInteger(prefs::kNumFoldersOnBookmarkBar); |
| 639 | int num_bookmarks_in_other_bookmarks_folder = |
| 640 | pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder); |
| 641 | int num_folders_in_other_bookmarks_folder = |
| 642 | pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder); |
| 643 | { |
| 644 | OPEN_ELEMENT_FOR_SCOPE("bookmarklocation"); |
| 645 | WriteAttribute("name", "full-tree"); |
| 646 | WriteIntAttribute("foldercount", |
| 647 | num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder); |
| 648 | WriteIntAttribute("itemcount", |
| 649 | num_bookmarks_on_bookmark_bar + |
| 650 | num_bookmarks_in_other_bookmarks_folder); |
| 651 | } |
| 652 | { |
| 653 | OPEN_ELEMENT_FOR_SCOPE("bookmarklocation"); |
| 654 | WriteAttribute("name", "toolbar"); |
| 655 | WriteIntAttribute("foldercount", num_folders_on_bookmark_bar); |
| 656 | WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar); |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | { |
| 661 | OPEN_ELEMENT_FOR_SCOPE("keywords"); |
| 662 | WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords)); |
| 663 | } |
| 664 | |
| 665 | if (profile_metrics) |
| 666 | WriteAllProfilesMetrics(*profile_metrics); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | void MetricsLog::WriteAllProfilesMetrics( |
| 670 | const DictionaryValue& all_profiles_metrics) { |
viettrungluu@chromium.org | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 671 | const std::string profile_prefix(prefs::kProfilePrefix); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 672 | for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys(); |
| 673 | i != all_profiles_metrics.end_keys(); ++i) { |
viettrungluu@chromium.org | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 674 | const std::string& key_name = *i; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 675 | if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) { |
| 676 | DictionaryValue* profile; |
pkasting@chromium.org | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 677 | if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name, |
| 678 | &profile)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 679 | WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile); |
| 680 | } |
| 681 | } |
| 682 | } |
| 683 | |
viettrungluu@chromium.org | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 684 | void MetricsLog::WriteProfileMetrics(const std::string& profileidhash, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 685 | const DictionaryValue& profile_metrics) { |
| 686 | OPEN_ELEMENT_FOR_SCOPE("userprofile"); |
viettrungluu@chromium.org | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 687 | WriteAttribute("profileidhash", profileidhash); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 688 | for (DictionaryValue::key_iterator i = profile_metrics.begin_keys(); |
| 689 | i != profile_metrics.end_keys(); ++i) { |
| 690 | Value* value; |
pkasting@chromium.org | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 691 | if (profile_metrics.GetWithoutPathExpansion(*i, &value)) { |
viettrungluu@chromium.org | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 692 | DCHECK(*i != "id"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 693 | switch (value->GetType()) { |
| 694 | case Value::TYPE_STRING: { |
scherkus@chromium.org | 5e324b7 | 2008-12-18 00:07:59 | [diff] [blame] | 695 | std::string string_value; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 696 | if (value->GetAsString(&string_value)) { |
| 697 | OPEN_ELEMENT_FOR_SCOPE("profileparam"); |
viettrungluu@chromium.org | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 698 | WriteAttribute("name", *i); |
scherkus@chromium.org | 5e324b7 | 2008-12-18 00:07:59 | [diff] [blame] | 699 | WriteAttribute("value", string_value); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 700 | } |
| 701 | break; |
| 702 | } |
| 703 | |
| 704 | case Value::TYPE_BOOLEAN: { |
| 705 | bool bool_value; |
| 706 | if (value->GetAsBoolean(&bool_value)) { |
| 707 | OPEN_ELEMENT_FOR_SCOPE("profileparam"); |
viettrungluu@chromium.org | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 708 | WriteAttribute("name", *i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 709 | WriteIntAttribute("value", bool_value ? 1 : 0); |
| 710 | } |
| 711 | break; |
| 712 | } |
| 713 | |
| 714 | case Value::TYPE_INTEGER: { |
| 715 | int int_value; |
| 716 | if (value->GetAsInteger(&int_value)) { |
| 717 | OPEN_ELEMENT_FOR_SCOPE("profileparam"); |
viettrungluu@chromium.org | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 718 | WriteAttribute("name", *i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 719 | WriteIntAttribute("value", int_value); |
| 720 | } |
| 721 | break; |
| 722 | } |
| 723 | |
| 724 | default: |
| 725 | NOTREACHED(); |
| 726 | break; |
| 727 | } |
| 728 | } |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) { |
| 733 | DCHECK(!locked_); |
| 734 | |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 735 | // Write the XML version. |
pkasting@chromium.org | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 736 | OPEN_ELEMENT_FOR_SCOPE("uielement"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 737 | WriteAttribute("action", "autocomplete"); |
| 738 | WriteAttribute("targetidhash", ""); |
| 739 | // TODO(kochi): Properly track windows. |
| 740 | WriteIntAttribute("window", 0); |
mpearson@chromium.org | 6ebc316 | 2011-12-19 13:44:00 | [diff] [blame] | 741 | if (log.tab_id != -1) { |
| 742 | // If we know what tab the autocomplete URL was opened in, log it. |
| 743 | WriteIntAttribute("tab", static_cast<int>(log.tab_id)); |
| 744 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 745 | WriteCommonEventAttributes(); |
| 746 | |
pkasting@chromium.org | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 747 | { |
| 748 | OPEN_ELEMENT_FOR_SCOPE("autocomplete"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 749 | |
pkasting@chromium.org | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 750 | WriteIntAttribute("typedlength", static_cast<int>(log.text.length())); |
mpearson@chromium.org | 0fdc15d | 2012-01-24 22:32:08 | [diff] [blame] | 751 | std::vector<string16> terms; |
| 752 | WriteIntAttribute("numterms", |
| 753 | static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms))); |
pkasting@chromium.org | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 754 | WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index)); |
| 755 | WriteIntAttribute("completedlength", |
| 756 | static_cast<int>(log.inline_autocompleted_length)); |
mpearson@chromium.org | 9e34976 | 2012-01-31 03:24:36 | [diff] [blame] | 757 | if (log.elapsed_time_since_user_first_modified_omnibox != |
| 758 | base::TimeDelta::FromMilliseconds(-1)) { |
| 759 | // Only upload the typing duration if it is set/valid. |
| 760 | WriteInt64Attribute("typingduration", |
| 761 | log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds()); |
| 762 | } |
pkasting@chromium.org | 381e299 | 2008-12-16 01:41:00 | [diff] [blame] | 763 | const std::string input_type( |
| 764 | AutocompleteInput::TypeToString(log.input_type)); |
| 765 | if (!input_type.empty()) |
| 766 | WriteAttribute("inputtype", input_type); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 767 | |
pkasting@chromium.org | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 768 | for (AutocompleteResult::const_iterator i(log.result.begin()); |
| 769 | i != log.result.end(); ++i) { |
| 770 | OPEN_ELEMENT_FOR_SCOPE("autocompleteitem"); |
| 771 | if (i->provider) |
| 772 | WriteAttribute("provider", i->provider->name()); |
pkasting@chromium.org | 381e299 | 2008-12-16 01:41:00 | [diff] [blame] | 773 | const std::string result_type(AutocompleteMatch::TypeToString(i->type)); |
| 774 | if (!result_type.empty()) |
| 775 | WriteAttribute("resulttype", result_type); |
pkasting@chromium.org | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 776 | WriteIntAttribute("relevance", i->relevance); |
| 777 | WriteIntAttribute("isstarred", i->starred ? 1 : 0); |
| 778 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 779 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 780 | |
isherman@chromium.org | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 781 | // Write the protobuf version. |
| 782 | OmniboxEventProto* omnibox_event = uma_proto_.add_omnibox_event(); |
| 783 | omnibox_event->set_time(MetricsLogBase::GetCurrentTime()); |
| 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 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 801 | ++num_events_; |
| 802 | } |