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