[email protected] | 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 | |
[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] | 054c801 | 2011-11-16 00:12:42 | [diff] [blame] | 12 | #include "base/lazy_instance.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 13 | #include "base/memory/scoped_ptr.h" |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 14 | #include "base/perftimer.h" |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [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" |
[email protected] | fadf97f | 2008-09-18 12:18:14 | [diff] [blame] | 17 | #include "base/sys_info.h" |
[email protected] | 37f39e4 | 2010-01-06 17:35:17 | [diff] [blame] | 18 | #include "base/third_party/nspr/prtime.h" |
[email protected] | 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" |
[email protected] | 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" |
[email protected] | 1008498 | 2011-08-19 17:56:56 | [diff] [blame] | 24 | #include "chrome/browser/plugin_prefs.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 25 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 1008498 | 2011-08-19 17:56:56 | [diff] [blame] | 26 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | 1eeb5e0 | 2010-07-20 23:02:11 | [diff] [blame] | 27 | #include "chrome/common/chrome_version_info.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 28 | #include "chrome/common/logging_chrome.h" |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 29 | #include "chrome/common/metrics/proto/omnibox_event.pb.h" |
| 30 | #include "chrome/common/metrics/proto/system_profile.pb.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 31 | #include "chrome/common/pref_names.h" |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 32 | #include "content/public/browser/content_browser_client.h" |
[email protected] | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 33 | #include "content/public/browser/gpu_data_manager.h" |
| 34 | #include "content/public/common/gpu_info.h" |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 35 | #include "content/public/common/content_client.h" |
[email protected] | 46072d4 | 2008-07-28 14:49:35 | [diff] [blame] | 36 | #include "googleurl/src/gurl.h" |
[email protected] | 6b7d954ff | 2011-10-25 00:39:35 | [diff] [blame] | 37 | #include "ui/gfx/screen.h" |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 38 | #include "webkit/plugins/webplugininfo.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 39 | |
| 40 | #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name) |
| 41 | |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 42 | // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx |
| 43 | #if defined(OS_WIN) |
| 44 | extern "C" IMAGE_DOS_HEADER __ImageBase; |
| 45 | #endif |
| 46 | |
[email protected] | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 47 | using content::GpuDataManager; |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 48 | using metrics::OmniboxEventProto; |
| 49 | using metrics::SystemProfileProto; |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 50 | typedef base::FieldTrial::NameGroupId NameGroupId; |
[email protected] | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 51 | |
[email protected] | 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. |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 56 | std::string GetInstallDate(PrefService* pref) { |
| 57 | if (!pref) { |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 58 | NOTREACHED(); |
| 59 | return "0"; |
| 60 | } |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 61 | |
| 62 | return pref->GetString(prefs::kMetricsClientIDTimestamp); |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 63 | } |
| 64 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 65 | OmniboxEventProto::InputType AsOmniboxEventInputType( |
| 66 | AutocompleteInput::Type type) { |
| 67 | switch (type) { |
| 68 | case AutocompleteInput::INVALID: |
| 69 | return OmniboxEventProto::INVALID; |
| 70 | case AutocompleteInput::UNKNOWN: |
| 71 | return OmniboxEventProto::UNKNOWN; |
| 72 | case AutocompleteInput::REQUESTED_URL: |
| 73 | return OmniboxEventProto::REQUESTED_URL; |
| 74 | case AutocompleteInput::URL: |
| 75 | return OmniboxEventProto::URL; |
| 76 | case AutocompleteInput::QUERY: |
| 77 | return OmniboxEventProto::QUERY; |
| 78 | case AutocompleteInput::FORCED_QUERY: |
| 79 | return OmniboxEventProto::FORCED_QUERY; |
| 80 | default: |
| 81 | NOTREACHED(); |
| 82 | return OmniboxEventProto::INVALID; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | OmniboxEventProto::Suggestion::ProviderType AsOmniboxEventProviderType( |
| 87 | const AutocompleteProvider* provider) { |
| 88 | if (!provider) |
| 89 | return OmniboxEventProto::Suggestion::UNKNOWN_PROVIDER; |
| 90 | |
| 91 | const std::string& name = provider->name(); |
| 92 | if (name == "HistoryURL") |
| 93 | return OmniboxEventProto::Suggestion::URL; |
| 94 | if (name == "HistoryContents") |
| 95 | return OmniboxEventProto::Suggestion::HISTORY_CONTENTS; |
| 96 | if (name == "HistoryQuickProvider") |
| 97 | return OmniboxEventProto::Suggestion::HISTORY_QUICK; |
| 98 | if (name == "Search") |
| 99 | return OmniboxEventProto::Suggestion::SEARCH; |
| 100 | if (name == "Keyword") |
| 101 | return OmniboxEventProto::Suggestion::KEYWORD; |
| 102 | if (name == "Builtin") |
| 103 | return OmniboxEventProto::Suggestion::BUILTIN; |
| 104 | if (name == "ShortcutsProvider") |
| 105 | return OmniboxEventProto::Suggestion::SHORTCUTS; |
| 106 | if (name == "ExtensionApps") |
| 107 | return OmniboxEventProto::Suggestion::EXTENSION_APPS; |
| 108 | |
| 109 | NOTREACHED(); |
| 110 | return OmniboxEventProto::Suggestion::UNKNOWN_PROVIDER; |
| 111 | } |
| 112 | |
| 113 | OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType( |
| 114 | AutocompleteMatch::Type type) { |
| 115 | switch (type) { |
| 116 | case AutocompleteMatch::URL_WHAT_YOU_TYPED: |
| 117 | return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED; |
| 118 | case AutocompleteMatch::HISTORY_URL: |
| 119 | return OmniboxEventProto::Suggestion::HISTORY_URL; |
| 120 | case AutocompleteMatch::HISTORY_TITLE: |
| 121 | return OmniboxEventProto::Suggestion::HISTORY_TITLE; |
| 122 | case AutocompleteMatch::HISTORY_BODY: |
| 123 | return OmniboxEventProto::Suggestion::HISTORY_BODY; |
| 124 | case AutocompleteMatch::HISTORY_KEYWORD: |
| 125 | return OmniboxEventProto::Suggestion::HISTORY_KEYWORD; |
| 126 | case AutocompleteMatch::NAVSUGGEST: |
| 127 | return OmniboxEventProto::Suggestion::NAVSUGGEST; |
| 128 | case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: |
| 129 | return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED; |
| 130 | case AutocompleteMatch::SEARCH_HISTORY: |
| 131 | return OmniboxEventProto::Suggestion::SEARCH_HISTORY; |
| 132 | case AutocompleteMatch::SEARCH_SUGGEST: |
| 133 | return OmniboxEventProto::Suggestion::SEARCH_SUGGEST; |
| 134 | case AutocompleteMatch::SEARCH_OTHER_ENGINE: |
| 135 | return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE; |
| 136 | case AutocompleteMatch::EXTENSION_APP: |
| 137 | return OmniboxEventProto::Suggestion::EXTENSION_APP; |
| 138 | default: |
| 139 | NOTREACHED(); |
| 140 | return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE; |
| 141 | } |
| 142 | } |
| 143 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 144 | // Returns the plugin preferences corresponding for this user, if available. |
| 145 | // If multiple user profiles are loaded, returns the preferences corresponding |
| 146 | // to an arbitrary one of the profiles. |
| 147 | PluginPrefs* GetPluginPrefs() { |
| 148 | ProfileManager* profile_manager = g_browser_process->profile_manager(); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 149 | |
| 150 | if (!profile_manager) { |
| 151 | // The profile manager can be NULL when testing. |
| 152 | return NULL; |
| 153 | } |
| 154 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 155 | std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); |
| 156 | if (profiles.empty()) |
| 157 | return NULL; |
| 158 | |
| 159 | return PluginPrefs::GetForProfile(profiles.front()); |
| 160 | } |
| 161 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 162 | // Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|. |
| 163 | void SetPluginInfo(const webkit::WebPluginInfo& plugin_info, |
| 164 | const PluginPrefs* plugin_prefs, |
| 165 | SystemProfileProto::Plugin* plugin) { |
| 166 | plugin->set_name(UTF16ToUTF8(plugin_info.name)); |
| 167 | plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe()); |
| 168 | plugin->set_version(UTF16ToUTF8(plugin_info.version)); |
| 169 | if (plugin_prefs) |
| 170 | plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info)); |
| 171 | } |
| 172 | |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 173 | void WriteFieldTrials(const std::vector<NameGroupId>& field_trial_ids, |
| 174 | SystemProfileProto* system_profile) { |
| 175 | for (std::vector<NameGroupId>::const_iterator it = field_trial_ids.begin(); |
| 176 | it != field_trial_ids.end(); ++it) { |
| 177 | SystemProfileProto::FieldTrial* field_trial = |
| 178 | system_profile->add_field_trial(); |
| 179 | field_trial->set_name_id(it->name); |
| 180 | field_trial->set_group_id(it->group); |
| 181 | } |
| 182 | } |
| 183 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 184 | } // namespace |
| 185 | |
[email protected] | 67f92bc3 | 2012-01-26 01:56:19 | [diff] [blame] | 186 | static base::LazyInstance<std::string>::Leaky |
[email protected] | 054c801 | 2011-11-16 00:12:42 | [diff] [blame] | 187 | g_version_extension = LAZY_INSTANCE_INITIALIZER; |
| 188 | |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 189 | MetricsLog::MetricsLog(const std::string& client_id, int session_id) |
| 190 | : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {} |
[email protected] | 5ed7d457 | 2009-12-23 17:42:41 | [diff] [blame] | 191 | |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 192 | MetricsLog::~MetricsLog() {} |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 193 | |
| 194 | // static |
| 195 | void MetricsLog::RegisterPrefs(PrefService* local_state) { |
| 196 | local_state->RegisterListPref(prefs::kStabilityPluginStats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 197 | } |
| 198 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 199 | // static |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 200 | int64 MetricsLog::GetIncrementalUptime(PrefService* pref) { |
| 201 | base::TimeTicks now = base::TimeTicks::Now(); |
| 202 | static base::TimeTicks last_updated_time(now); |
| 203 | int64 incremental_time = (now - last_updated_time).InSeconds(); |
| 204 | last_updated_time = now; |
| 205 | |
| 206 | if (incremental_time > 0) { |
| 207 | int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec); |
| 208 | metrics_uptime += incremental_time; |
| 209 | pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime); |
| 210 | } |
| 211 | |
| 212 | return incremental_time; |
| 213 | } |
| 214 | |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 215 | // static |
| 216 | std::string MetricsLog::GetVersionString() { |
[email protected] | 0211f57e | 2010-08-27 20:28:42 | [diff] [blame] | 217 | chrome::VersionInfo version_info; |
[email protected] | 30c9180 | 2010-12-18 00:40:17 | [diff] [blame] | 218 | if (!version_info.is_valid()) { |
| 219 | NOTREACHED() << "Unable to retrieve version info."; |
| 220 | return std::string(); |
| 221 | } |
| 222 | |
[email protected] | 0211f57e | 2010-08-27 20:28:42 | [diff] [blame] | 223 | std::string version = version_info.Version(); |
[email protected] | 054c801 | 2011-11-16 00:12:42 | [diff] [blame] | 224 | if (!version_extension().empty()) |
| 225 | version += version_extension(); |
[email protected] | 0211f57e | 2010-08-27 20:28:42 | [diff] [blame] | 226 | if (!version_info.IsOfficialBuild()) |
| 227 | version.append("-devel"); |
| 228 | return version; |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 229 | } |
| 230 | |
[email protected] | 054c801 | 2011-11-16 00:12:42 | [diff] [blame] | 231 | // static |
| 232 | void MetricsLog::set_version_extension(const std::string& extension) { |
| 233 | g_version_extension.Get() = extension; |
| 234 | } |
| 235 | |
| 236 | // static |
| 237 | const std::string& MetricsLog::version_extension() { |
| 238 | return g_version_extension.Get(); |
| 239 | } |
| 240 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 241 | void MetricsLog::RecordIncrementalStabilityElements( |
| 242 | const std::vector<webkit::WebPluginInfo>& plugin_list) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 243 | DCHECK(!locked()); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 244 | |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 245 | PrefService* pref = GetPrefService(); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 246 | DCHECK(pref); |
| 247 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 248 | OPEN_ELEMENT_FOR_SCOPE("profile"); |
| 249 | WriteCommonEventAttributes(); |
| 250 | |
[email protected] | 9958a32 | 2011-03-08 20:04:17 | [diff] [blame] | 251 | WriteInstallElement(); |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 252 | |
| 253 | { |
| 254 | OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements. |
| 255 | WriteRequiredStabilityAttributes(pref); |
| 256 | WriteRealtimeStabilityAttributes(pref); |
| 257 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 258 | WritePluginStabilityElements(plugin_list, pref); |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 259 | } |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 260 | } |
| 261 | |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 262 | PrefService* MetricsLog::GetPrefService() { |
| 263 | return g_browser_process->local_state(); |
| 264 | } |
| 265 | |
| 266 | gfx::Size MetricsLog::GetScreenSize() const { |
| 267 | return gfx::Screen::GetPrimaryMonitorSize(); |
| 268 | } |
| 269 | |
| 270 | int MetricsLog::GetScreenCount() const { |
| 271 | return gfx::Screen::GetNumMonitors(); |
| 272 | } |
| 273 | |
| 274 | |
| 275 | void MetricsLog::GetFieldTrialIds( |
| 276 | std::vector<NameGroupId>* field_trial_ids) const { |
| 277 | base::FieldTrialList::GetFieldTrialNameGroupIds(field_trial_ids); |
| 278 | } |
| 279 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 280 | void MetricsLog::WriteStabilityElement( |
| 281 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
| 282 | PrefService* pref) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 283 | DCHECK(!locked()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 284 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 285 | // Get stability attributes out of Local State, zeroing out stored values. |
| 286 | // NOTE: This could lead to some data loss if this report isn't successfully |
| 287 | // sent, but that's true for all the metrics. |
| 288 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 289 | OPEN_ELEMENT_FOR_SCOPE("stability"); |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 290 | WriteRequiredStabilityAttributes(pref); |
| 291 | WriteRealtimeStabilityAttributes(pref); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 292 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 293 | int incomplete_shutdown_count = |
| 294 | pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount); |
[email protected] | e324f6b | 2012-02-28 05:43:37 | [diff] [blame] | 295 | pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 296 | int breakpad_registration_success_count = |
| 297 | pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess); |
[email protected] | e324f6b | 2012-02-28 05:43:37 | [diff] [blame] | 298 | pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 299 | int breakpad_registration_failure_count = |
| 300 | pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail); |
[email protected] | e324f6b | 2012-02-28 05:43:37 | [diff] [blame] | 301 | pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 302 | int debugger_present_count = |
| 303 | pref->GetInteger(prefs::kStabilityDebuggerPresent); |
[email protected] | e324f6b | 2012-02-28 05:43:37 | [diff] [blame] | 304 | pref->SetInteger(prefs::kStabilityDebuggerPresent, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 305 | int debugger_not_present_count = |
| 306 | pref->GetInteger(prefs::kStabilityDebuggerNotPresent); |
[email protected] | e324f6b | 2012-02-28 05:43:37 | [diff] [blame] | 307 | pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); |
[email protected] | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 308 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 309 | // TODO(jar): The following are all optional, so we *could* optimize them for |
| 310 | // values of zero (and not include them). |
| 311 | |
| 312 | // Write the XML version. |
| 313 | WriteIntAttribute("incompleteshutdowncount", incomplete_shutdown_count); |
| 314 | WriteIntAttribute("breakpadregistrationok", |
| 315 | breakpad_registration_success_count); |
| 316 | WriteIntAttribute("breakpadregistrationfail", |
| 317 | breakpad_registration_failure_count); |
| 318 | WriteIntAttribute("debuggerpresent", debugger_present_count); |
| 319 | WriteIntAttribute("debuggernotpresent", debugger_not_present_count); |
| 320 | |
| 321 | // Write the protobuf version. |
| 322 | SystemProfileProto::Stability* stability = |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 323 | uma_proto()->mutable_system_profile()->mutable_stability(); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 324 | stability->set_incomplete_shutdown_count(incomplete_shutdown_count); |
| 325 | stability->set_breakpad_registration_success_count( |
| 326 | breakpad_registration_success_count); |
| 327 | stability->set_breakpad_registration_failure_count( |
| 328 | breakpad_registration_failure_count); |
| 329 | stability->set_debugger_present_count(debugger_present_count); |
| 330 | stability->set_debugger_not_present_count(debugger_not_present_count); |
| 331 | |
| 332 | WritePluginStabilityElements(plugin_list, pref); |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 333 | } |
| 334 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 335 | void MetricsLog::WritePluginStabilityElements( |
| 336 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
| 337 | PrefService* pref) { |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 338 | // Now log plugin stability info. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 339 | const ListValue* plugin_stats_list = pref->GetList( |
| 340 | prefs::kStabilityPluginStats); |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 341 | if (!plugin_stats_list) |
| 342 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 343 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 344 | OPEN_ELEMENT_FOR_SCOPE("plugins"); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 345 | SystemProfileProto::Stability* stability = |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 346 | uma_proto()->mutable_system_profile()->mutable_stability(); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 347 | PluginPrefs* plugin_prefs = GetPluginPrefs(); |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 348 | for (ListValue::const_iterator iter = plugin_stats_list->begin(); |
| 349 | iter != plugin_stats_list->end(); ++iter) { |
| 350 | if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) { |
| 351 | NOTREACHED(); |
| 352 | continue; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 353 | } |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 354 | DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 355 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 356 | std::string plugin_name; |
| 357 | plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name); |
| 358 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 359 | std::string base64_name_hash; |
| 360 | uint64 numeric_name_hash_ignored; |
| 361 | CreateHashes(plugin_name, &base64_name_hash, &numeric_name_hash_ignored); |
| 362 | |
| 363 | // Write the XML verison. |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 364 | OPEN_ELEMENT_FOR_SCOPE("pluginstability"); |
| 365 | // Use "filename" instead of "name", otherwise we need to update the |
| 366 | // UMA servers. |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 367 | WriteAttribute("filename", base64_name_hash); |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 368 | |
| 369 | int launches = 0; |
| 370 | plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches); |
| 371 | WriteIntAttribute("launchcount", launches); |
| 372 | |
| 373 | int instances = 0; |
| 374 | plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances); |
| 375 | WriteIntAttribute("instancecount", instances); |
| 376 | |
| 377 | int crashes = 0; |
| 378 | plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes); |
| 379 | WriteIntAttribute("crashcount", crashes); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 380 | |
| 381 | // Write the protobuf version. |
| 382 | // Note that this search is potentially a quadratic operation, but given the |
| 383 | // low number of plugins installed on a "reasonable" setup, this should be |
| 384 | // fine. |
| 385 | // TODO(isherman): Verify that this does not show up as a hotspot in |
| 386 | // profiler runs. |
| 387 | const webkit::WebPluginInfo* plugin_info = NULL; |
| 388 | const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name); |
| 389 | for (std::vector<webkit::WebPluginInfo>::const_iterator iter = |
| 390 | plugin_list.begin(); |
| 391 | iter != plugin_list.end(); ++iter) { |
| 392 | if (iter->name == plugin_name_utf16) { |
| 393 | plugin_info = &(*iter); |
| 394 | break; |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | if (!plugin_info) { |
| 399 | NOTREACHED(); |
| 400 | continue; |
| 401 | } |
| 402 | |
| 403 | SystemProfileProto::Stability::PluginStability* plugin_stability = |
| 404 | stability->add_plugin_stability(); |
| 405 | SetPluginInfo(*plugin_info, plugin_prefs, |
| 406 | plugin_stability->mutable_plugin()); |
| 407 | plugin_stability->set_launch_count(launches); |
| 408 | plugin_stability->set_instance_count(instances); |
| 409 | plugin_stability->set_crash_count(crashes); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 410 | } |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 411 | |
| 412 | pref->ClearPref(prefs::kStabilityPluginStats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 413 | } |
| 414 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 415 | // The server refuses data that doesn't have certain values. crashcount and |
| 416 | // launchcount are currently "required" in the "stability" group. |
| 417 | // TODO(isherman): Stop writing these attributes specially once the migration to |
| 418 | // protobufs is complete. |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 419 | void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 420 | int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 421 | pref->SetInteger(prefs::kStabilityLaunchCount, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 422 | int crash_count = pref->GetInteger(prefs::kStabilityCrashCount); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 423 | pref->SetInteger(prefs::kStabilityCrashCount, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 424 | |
| 425 | // Write the XML version. |
| 426 | WriteIntAttribute("launchcount", launch_count); |
| 427 | WriteIntAttribute("crashcount", crash_count); |
| 428 | |
| 429 | // Write the protobuf version. |
| 430 | SystemProfileProto::Stability* stability = |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 431 | uma_proto()->mutable_system_profile()->mutable_stability(); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 432 | stability->set_launch_count(launch_count); |
| 433 | stability->set_crash_count(crash_count); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 434 | } |
| 435 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 436 | void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) { |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 437 | // Update the stats which are critical for real-time stability monitoring. |
| 438 | // Since these are "optional," only list ones that are non-zero, as the counts |
| 439 | // are aggergated (summed) server side. |
| 440 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 441 | SystemProfileProto::Stability* stability = |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 442 | uma_proto()->mutable_system_profile()->mutable_stability(); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 443 | int count = pref->GetInteger(prefs::kStabilityPageLoadCount); |
| 444 | if (count) { |
| 445 | WriteIntAttribute("pageloadcount", count); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 446 | stability->set_page_load_count(count); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 447 | pref->SetInteger(prefs::kStabilityPageLoadCount, 0); |
| 448 | } |
| 449 | |
| 450 | count = pref->GetInteger(prefs::kStabilityRendererCrashCount); |
| 451 | if (count) { |
| 452 | WriteIntAttribute("renderercrashcount", count); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 453 | stability->set_renderer_crash_count(count); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 454 | pref->SetInteger(prefs::kStabilityRendererCrashCount, 0); |
| 455 | } |
| 456 | |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 457 | count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount); |
| 458 | if (count) { |
| 459 | WriteIntAttribute("extensionrenderercrashcount", count); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 460 | stability->set_extension_renderer_crash_count(count); |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 461 | pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0); |
| 462 | } |
| 463 | |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 464 | count = pref->GetInteger(prefs::kStabilityRendererHangCount); |
| 465 | if (count) { |
| 466 | WriteIntAttribute("rendererhangcount", count); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 467 | stability->set_renderer_hang_count(count); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 468 | pref->SetInteger(prefs::kStabilityRendererHangCount, 0); |
| 469 | } |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 470 | |
| 471 | count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount); |
| 472 | if (count) { |
| 473 | WriteIntAttribute("childprocesscrashcount", count); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 474 | stability->set_child_process_crash_count(count); |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 475 | pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); |
| 476 | } |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 477 | |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 478 | #if defined(OS_CHROMEOS) |
| 479 | count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount); |
| 480 | if (count) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 481 | stability->set_other_user_crash_count(count); |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 482 | pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0); |
| 483 | } |
| 484 | |
| 485 | count = pref->GetInteger(prefs::kStabilityKernelCrashCount); |
| 486 | if (count) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 487 | stability->set_kernel_crash_count(count); |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 488 | pref->SetInteger(prefs::kStabilityKernelCrashCount, 0); |
| 489 | } |
| 490 | |
| 491 | count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount); |
| 492 | if (count) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 493 | stability->set_unclean_system_shutdown_count(count); |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 494 | pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0); |
| 495 | } |
| 496 | #endif // OS_CHROMEOS |
| 497 | |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 498 | int64 recent_duration = GetIncrementalUptime(pref); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 499 | if (recent_duration) { |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 500 | WriteInt64Attribute("uptimesec", recent_duration); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 501 | stability->set_uptime_sec(recent_duration); |
| 502 | } |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 503 | } |
| 504 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 505 | void MetricsLog::WritePluginList( |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 506 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
| 507 | bool write_as_xml) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 508 | DCHECK(!locked()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 509 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 510 | PluginPrefs* plugin_prefs = GetPluginPrefs(); |
[email protected] | 1008498 | 2011-08-19 17:56:56 | [diff] [blame] | 511 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 512 | OPEN_ELEMENT_FOR_SCOPE("plugins"); |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 513 | SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 514 | for (std::vector<webkit::WebPluginInfo>::const_iterator iter = |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 515 | plugin_list.begin(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 516 | iter != plugin_list.end(); ++iter) { |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 517 | if (write_as_xml) { |
| 518 | std::string base64_name_hash; |
| 519 | uint64 numeric_hash_ignored; |
| 520 | CreateHashes(UTF16ToUTF8(iter->name), &base64_name_hash, |
| 521 | &numeric_hash_ignored); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 522 | |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 523 | std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe(); |
| 524 | std::string base64_filename_hash; |
| 525 | CreateHashes(filename_bytes, &base64_filename_hash, |
| 526 | &numeric_hash_ignored); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 527 | |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 528 | // Write the XML version. |
| 529 | OPEN_ELEMENT_FOR_SCOPE("plugin"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 530 | |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 531 | // Plugin name and filename are hashed for the privacy of those |
| 532 | // testing unreleased new extensions. |
| 533 | WriteAttribute("name", base64_name_hash); |
| 534 | WriteAttribute("filename", base64_filename_hash); |
| 535 | WriteAttribute("version", UTF16ToUTF8(iter->version)); |
| 536 | if (plugin_prefs) |
| 537 | WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter)); |
| 538 | } else { |
| 539 | // Write the protobuf version. |
| 540 | SystemProfileProto::Plugin* plugin = system_profile->add_plugin(); |
| 541 | SetPluginInfo(*iter, plugin_prefs, plugin); |
| 542 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 543 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 544 | } |
| 545 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 546 | void MetricsLog::WriteInstallElement() { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 547 | // Write the XML version. |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 548 | // We'll write the protobuf version in RecordEnvironmentProto(). |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 549 | OPEN_ELEMENT_FOR_SCOPE("install"); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 550 | WriteAttribute("installdate", GetInstallDate(GetPrefService())); |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 551 | WriteIntAttribute("buildid", 0); // We're using appversion instead. |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 552 | } |
| 553 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 554 | void MetricsLog::RecordEnvironment( |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 555 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 556 | const DictionaryValue* profile_metrics) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 557 | DCHECK(!locked()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 558 | |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 559 | PrefService* pref = GetPrefService(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 560 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 561 | OPEN_ELEMENT_FOR_SCOPE("profile"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 562 | WriteCommonEventAttributes(); |
| 563 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 564 | WriteInstallElement(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 565 | |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 566 | // Write the XML version. |
| 567 | // We'll write the protobuf version in RecordEnvironmentProto(). |
| 568 | bool write_as_xml = true; |
| 569 | WritePluginList(plugin_list, write_as_xml); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 570 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 571 | WriteStabilityElement(plugin_list, pref); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 572 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 573 | { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 574 | // Write the XML version. |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 575 | // We'll write the protobuf version in RecordEnvironmentProto(). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 576 | OPEN_ELEMENT_FOR_SCOPE("cpu"); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 577 | WriteAttribute("arch", base::SysInfo::CPUArchitecture()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 581 | // Write the XML version. |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 582 | // We'll write the protobuf version in RecordEnvironmentProto(). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 583 | OPEN_ELEMENT_FOR_SCOPE("memory"); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 584 | WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB()); |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 585 | #if defined(OS_WIN) |
| 586 | WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase)); |
| 587 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 591 | // Write the XML version. |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 592 | // We'll write the protobuf version in RecordEnvironmentProto(). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 593 | OPEN_ELEMENT_FOR_SCOPE("os"); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 594 | WriteAttribute("name", base::SysInfo::OperatingSystemName()); |
| 595 | WriteAttribute("version", base::SysInfo::OperatingSystemVersion()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | { |
[email protected] | e8c287c87 | 2010-07-20 00:49:42 | [diff] [blame] | 599 | OPEN_ELEMENT_FOR_SCOPE("gpu"); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 600 | const content::GPUInfo& gpu_info = |
| 601 | GpuDataManager::GetInstance()->GetGPUInfo(); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 602 | |
| 603 | // Write the XML version. |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 604 | // We'll write the protobuf version in RecordEnvironmentProto(). |
[email protected] | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 605 | WriteIntAttribute("vendorid", gpu_info.vendor_id); |
| 606 | WriteIntAttribute("deviceid", gpu_info.device_id); |
[email protected] | e8c287c87 | 2010-07-20 00:49:42 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 610 | const gfx::Size display_size = GetScreenSize(); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 611 | |
| 612 | // Write the XML version. |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 613 | // We'll write the protobuf version in RecordEnvironmentProto(). |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 614 | OPEN_ELEMENT_FOR_SCOPE("display"); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 615 | WriteIntAttribute("xsize", display_size.width()); |
| 616 | WriteIntAttribute("ysize", display_size.height()); |
| 617 | WriteIntAttribute("screens", GetScreenCount()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | { |
| 621 | OPEN_ELEMENT_FOR_SCOPE("bookmarks"); |
| 622 | int num_bookmarks_on_bookmark_bar = |
| 623 | pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar); |
| 624 | int num_folders_on_bookmark_bar = |
| 625 | pref->GetInteger(prefs::kNumFoldersOnBookmarkBar); |
| 626 | int num_bookmarks_in_other_bookmarks_folder = |
| 627 | pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder); |
| 628 | int num_folders_in_other_bookmarks_folder = |
| 629 | pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder); |
| 630 | { |
| 631 | OPEN_ELEMENT_FOR_SCOPE("bookmarklocation"); |
| 632 | WriteAttribute("name", "full-tree"); |
| 633 | WriteIntAttribute("foldercount", |
| 634 | num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder); |
| 635 | WriteIntAttribute("itemcount", |
| 636 | num_bookmarks_on_bookmark_bar + |
| 637 | num_bookmarks_in_other_bookmarks_folder); |
| 638 | } |
| 639 | { |
| 640 | OPEN_ELEMENT_FOR_SCOPE("bookmarklocation"); |
| 641 | WriteAttribute("name", "toolbar"); |
| 642 | WriteIntAttribute("foldercount", num_folders_on_bookmark_bar); |
| 643 | WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar); |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | { |
| 648 | OPEN_ELEMENT_FOR_SCOPE("keywords"); |
| 649 | WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords)); |
| 650 | } |
| 651 | |
| 652 | if (profile_metrics) |
| 653 | WriteAllProfilesMetrics(*profile_metrics); |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 654 | |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 655 | RecordEnvironmentProto(plugin_list); |
| 656 | } |
| 657 | |
| 658 | void MetricsLog::RecordEnvironmentProto( |
| 659 | const std::vector<webkit::WebPluginInfo>& plugin_list) { |
| 660 | SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
| 661 | int install_date; |
| 662 | bool success = base::StringToInt(GetInstallDate(GetPrefService()), |
| 663 | &install_date); |
| 664 | DCHECK(success); |
| 665 | system_profile->set_install_date(install_date); |
| 666 | |
| 667 | system_profile->set_application_locale( |
| 668 | content::GetContentClient()->browser()->GetApplicationLocale()); |
| 669 | |
| 670 | SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware(); |
| 671 | hardware->set_cpu_architecture(base::SysInfo::CPUArchitecture()); |
| 672 | hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB()); |
| 673 | #if defined(OS_WIN) |
| 674 | hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase)); |
| 675 | #endif |
| 676 | |
| 677 | SystemProfileProto::OS* os = system_profile->mutable_os(); |
| 678 | os->set_name(base::SysInfo::OperatingSystemName()); |
| 679 | os->set_version(base::SysInfo::OperatingSystemVersion()); |
| 680 | |
| 681 | const content::GPUInfo& gpu_info = |
| 682 | GpuDataManager::GetInstance()->GetGPUInfo(); |
| 683 | SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu(); |
| 684 | gpu->set_vendor_id(gpu_info.vendor_id); |
| 685 | gpu->set_device_id(gpu_info.device_id); |
| 686 | gpu->set_driver_version(gpu_info.driver_version); |
| 687 | gpu->set_driver_date(gpu_info.driver_date); |
| 688 | SystemProfileProto::Hardware::Graphics::PerformanceStatistics* |
| 689 | gpu_performance = gpu->mutable_performance_statistics(); |
| 690 | gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics); |
| 691 | gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming); |
| 692 | gpu_performance->set_overall_score(gpu_info.performance_stats.overall); |
| 693 | |
| 694 | const gfx::Size display_size = GetScreenSize(); |
| 695 | hardware->set_primary_screen_width(display_size.width()); |
| 696 | hardware->set_primary_screen_height(display_size.height()); |
| 697 | hardware->set_screen_count(GetScreenCount()); |
| 698 | |
| 699 | bool write_as_xml = false; |
| 700 | WritePluginList(plugin_list, write_as_xml); |
| 701 | |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 702 | std::vector<NameGroupId> field_trial_ids; |
| 703 | GetFieldTrialIds(&field_trial_ids); |
| 704 | WriteFieldTrials(field_trial_ids, system_profile); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | void MetricsLog::WriteAllProfilesMetrics( |
| 708 | const DictionaryValue& all_profiles_metrics) { |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 709 | const std::string profile_prefix(prefs::kProfilePrefix); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 710 | for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys(); |
| 711 | i != all_profiles_metrics.end_keys(); ++i) { |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 712 | const std::string& key_name = *i; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 713 | if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) { |
| 714 | DictionaryValue* profile; |
[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 715 | if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name, |
| 716 | &profile)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 717 | WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile); |
| 718 | } |
| 719 | } |
| 720 | } |
| 721 | |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 722 | void MetricsLog::WriteProfileMetrics(const std::string& profileidhash, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 723 | const DictionaryValue& profile_metrics) { |
| 724 | OPEN_ELEMENT_FOR_SCOPE("userprofile"); |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 725 | WriteAttribute("profileidhash", profileidhash); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 726 | for (DictionaryValue::key_iterator i = profile_metrics.begin_keys(); |
| 727 | i != profile_metrics.end_keys(); ++i) { |
| 728 | Value* value; |
[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 729 | if (profile_metrics.GetWithoutPathExpansion(*i, &value)) { |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 730 | DCHECK(*i != "id"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 731 | switch (value->GetType()) { |
| 732 | case Value::TYPE_STRING: { |
[email protected] | 5e324b7 | 2008-12-18 00:07:59 | [diff] [blame] | 733 | std::string string_value; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 734 | if (value->GetAsString(&string_value)) { |
| 735 | OPEN_ELEMENT_FOR_SCOPE("profileparam"); |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 736 | WriteAttribute("name", *i); |
[email protected] | 5e324b7 | 2008-12-18 00:07:59 | [diff] [blame] | 737 | WriteAttribute("value", string_value); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 738 | } |
| 739 | break; |
| 740 | } |
| 741 | |
| 742 | case Value::TYPE_BOOLEAN: { |
| 743 | bool bool_value; |
| 744 | if (value->GetAsBoolean(&bool_value)) { |
| 745 | OPEN_ELEMENT_FOR_SCOPE("profileparam"); |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 746 | WriteAttribute("name", *i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 747 | WriteIntAttribute("value", bool_value ? 1 : 0); |
| 748 | } |
| 749 | break; |
| 750 | } |
| 751 | |
| 752 | case Value::TYPE_INTEGER: { |
| 753 | int int_value; |
| 754 | if (value->GetAsInteger(&int_value)) { |
| 755 | OPEN_ELEMENT_FOR_SCOPE("profileparam"); |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 756 | WriteAttribute("name", *i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 757 | WriteIntAttribute("value", int_value); |
| 758 | } |
| 759 | break; |
| 760 | } |
| 761 | |
| 762 | default: |
| 763 | NOTREACHED(); |
| 764 | break; |
| 765 | } |
| 766 | } |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 771 | DCHECK(!locked()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 772 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 773 | // Write the XML version. |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 774 | OPEN_ELEMENT_FOR_SCOPE("uielement"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 775 | WriteAttribute("action", "autocomplete"); |
| 776 | WriteAttribute("targetidhash", ""); |
| 777 | // TODO(kochi): Properly track windows. |
| 778 | WriteIntAttribute("window", 0); |
[email protected] | 6ebc316 | 2011-12-19 13:44:00 | [diff] [blame] | 779 | if (log.tab_id != -1) { |
| 780 | // If we know what tab the autocomplete URL was opened in, log it. |
| 781 | WriteIntAttribute("tab", static_cast<int>(log.tab_id)); |
| 782 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 783 | WriteCommonEventAttributes(); |
| 784 | |
[email protected] | 6595631 | 2012-04-19 21:28:12 | [diff] [blame^] | 785 | std::vector<string16> terms; |
| 786 | const int num_terms = |
| 787 | static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms)); |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 788 | { |
| 789 | OPEN_ELEMENT_FOR_SCOPE("autocomplete"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 790 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 791 | WriteIntAttribute("typedlength", static_cast<int>(log.text.length())); |
[email protected] | 6595631 | 2012-04-19 21:28:12 | [diff] [blame^] | 792 | WriteIntAttribute("numterms", num_terms); |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 793 | WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index)); |
| 794 | WriteIntAttribute("completedlength", |
| 795 | static_cast<int>(log.inline_autocompleted_length)); |
[email protected] | 9e34976 | 2012-01-31 03:24:36 | [diff] [blame] | 796 | if (log.elapsed_time_since_user_first_modified_omnibox != |
| 797 | base::TimeDelta::FromMilliseconds(-1)) { |
| 798 | // Only upload the typing duration if it is set/valid. |
| 799 | WriteInt64Attribute("typingduration", |
| 800 | log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds()); |
| 801 | } |
[email protected] | 381e299 | 2008-12-16 01:41:00 | [diff] [blame] | 802 | const std::string input_type( |
| 803 | AutocompleteInput::TypeToString(log.input_type)); |
| 804 | if (!input_type.empty()) |
| 805 | WriteAttribute("inputtype", input_type); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 806 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 807 | for (AutocompleteResult::const_iterator i(log.result.begin()); |
| 808 | i != log.result.end(); ++i) { |
| 809 | OPEN_ELEMENT_FOR_SCOPE("autocompleteitem"); |
| 810 | if (i->provider) |
| 811 | WriteAttribute("provider", i->provider->name()); |
[email protected] | 381e299 | 2008-12-16 01:41:00 | [diff] [blame] | 812 | const std::string result_type(AutocompleteMatch::TypeToString(i->type)); |
| 813 | if (!result_type.empty()) |
| 814 | WriteAttribute("resulttype", result_type); |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 815 | WriteIntAttribute("relevance", i->relevance); |
| 816 | WriteIntAttribute("isstarred", i->starred ? 1 : 0); |
| 817 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 818 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 819 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 820 | // Write the protobuf version. |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 821 | OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event(); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 822 | omnibox_event->set_time(MetricsLogBase::GetCurrentTime()); |
| 823 | if (log.tab_id != -1) { |
| 824 | // If we know what tab the autocomplete URL was opened in, log it. |
| 825 | omnibox_event->set_tab_id(log.tab_id); |
| 826 | } |
| 827 | omnibox_event->set_typed_length(log.text.length()); |
[email protected] | 6595631 | 2012-04-19 21:28:12 | [diff] [blame^] | 828 | omnibox_event->set_num_typed_terms(num_terms); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 829 | omnibox_event->set_selected_index(log.selected_index); |
| 830 | omnibox_event->set_completed_length(log.inline_autocompleted_length); |
[email protected] | 6595631 | 2012-04-19 21:28:12 | [diff] [blame^] | 831 | if (log.elapsed_time_since_user_first_modified_omnibox != |
| 832 | base::TimeDelta::FromMilliseconds(-1)) { |
| 833 | // Only upload the typing duration if it is set/valid. |
| 834 | omnibox_event->set_typing_duration_ms( |
| 835 | log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds()); |
| 836 | } |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 837 | omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type)); |
| 838 | for (AutocompleteResult::const_iterator i(log.result.begin()); |
| 839 | i != log.result.end(); ++i) { |
| 840 | OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion(); |
| 841 | suggestion->set_provider(AsOmniboxEventProviderType(i->provider)); |
| 842 | suggestion->set_result_type(AsOmniboxEventResultType(i->type)); |
| 843 | suggestion->set_relevance(i->relevance); |
| 844 | suggestion->set_is_starred(i->starred); |
| 845 | } |
| 846 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 847 | ++num_events_; |
| 848 | } |