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