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