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