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