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