[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] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 11 | #include "base/base64.h" |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 12 | #include "base/basictypes.h" |
[email protected] | 611ae29a | 2013-04-29 21:32:19 | [diff] [blame] | 13 | #include "base/bind.h" |
[email protected] | 5c8f89f69 | 2013-07-18 11:13:28 | [diff] [blame] | 14 | #include "base/cpu.h" |
[email protected] | 054c801 | 2011-11-16 00:12:42 | [diff] [blame] | 15 | #include "base/lazy_instance.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 16 | #include "base/memory/scoped_ptr.h" |
[email protected] | 3853a4c | 2013-02-11 17:15:57 | [diff] [blame] | 17 | #include "base/prefs/pref_registry_simple.h" |
| 18 | #include "base/prefs/pref_service.h" |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 19 | #include "base/profiler/alternate_timer.h" |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 20 | #include "base/sha1.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 21 | #include "base/strings/string_number_conversions.h" |
[email protected] | f9b29436 | 2013-06-10 20:22:31 | [diff] [blame] | 22 | #include "base/strings/string_util.h" |
[email protected] | 112158af | 2013-06-07 23:46:18 | [diff] [blame] | 23 | #include "base/strings/utf_string_conversions.h" |
[email protected] | fadf97f | 2008-09-18 12:18:14 | [diff] [blame] | 24 | #include "base/sys_info.h" |
[email protected] | 37f39e4 | 2010-01-06 17:35:17 | [diff] [blame] | 25 | #include "base/third_party/nspr/prtime.h" |
[email protected] | 8481347 | 2013-06-28 00:25:19 | [diff] [blame] | 26 | #include "base/time/time.h" |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 27 | #include "base/tracked_objects.h" |
[email protected] | 9f8bc2f | 2012-07-03 16:26:53 | [diff] [blame] | 28 | #include "chrome/browser/autocomplete/autocomplete_input.h" |
[email protected] | 9ac4009 | 2010-10-27 23:05:26 | [diff] [blame] | 29 | #include "chrome/browser/autocomplete/autocomplete_match.h" |
[email protected] | 30f5bc9 | 2012-06-26 04:14:55 | [diff] [blame] | 30 | #include "chrome/browser/autocomplete/autocomplete_provider.h" |
[email protected] | 73c2b163 | 2012-07-02 22:51:38 | [diff] [blame] | 31 | #include "chrome/browser/autocomplete/autocomplete_result.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 32 | #include "chrome/browser/browser_process.h" |
[email protected] | 24b9bb39 | 2013-01-29 20:29:29 | [diff] [blame] | 33 | #include "chrome/browser/google/google_util.h" |
[email protected] | b84ee6e | 2014-03-15 22:51:54 | [diff] [blame] | 34 | #include "chrome/browser/metrics/extension_metrics.h" |
[email protected] | 0fafc8d | 2013-06-01 00:09:50 | [diff] [blame] | 35 | #include "chrome/browser/omnibox/omnibox_log.h" |
[email protected] | 0f5e57f5 | 2012-09-20 20:53:18 | [diff] [blame] | 36 | #include "chrome/browser/plugins/plugin_prefs.h" |
[email protected] | 1008498 | 2011-08-19 17:56:56 | [diff] [blame] | 37 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | 1eeb5e0 | 2010-07-20 23:02:11 | [diff] [blame] | 38 | #include "chrome/common/chrome_version_info.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 39 | #include "chrome/common/pref_names.h" |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 40 | #include "chrome/installer/util/google_update_settings.h" |
[email protected] | 85791b0b | 2014-05-20 15:18:58 | [diff] [blame^] | 41 | #include "components/metrics/metrics_provider.h" |
[email protected] | 064107e | 2014-05-02 00:59:06 | [diff] [blame] | 42 | #include "components/metrics/proto/omnibox_event.pb.h" |
| 43 | #include "components/metrics/proto/profiler_event.pb.h" |
| 44 | #include "components/metrics/proto/system_profile.pb.h" |
[email protected] | d5d38325 | 2013-07-04 14:44:32 | [diff] [blame] | 45 | #include "components/nacl/common/nacl_process_type.h" |
[email protected] | b3610d4 | 2014-05-19 18:07:23 | [diff] [blame] | 46 | #include "components/variations/active_field_trials.h" |
[email protected] | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 47 | #include "content/public/browser/gpu_data_manager.h" |
[email protected] | 1a838cc | 2012-04-24 22:06:49 | [diff] [blame] | 48 | #include "content/public/common/content_client.h" |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 49 | #include "content/public/common/webplugininfo.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] | 761fa470 | 2013-07-02 15:25:15 | [diff] [blame] | 52 | #include "url/gurl.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 | |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 58 | #if defined(OS_WIN) |
[email protected] | 1bb25e0 | 2012-08-03 22:39:39 | [diff] [blame] | 59 | #include "base/win/metro.h" |
| 60 | |
| 61 | // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 62 | extern "C" IMAGE_DOS_HEADER __ImageBase; |
| 63 | #endif |
| 64 | |
[email protected] | afc03f0 | 2013-10-11 06:01:35 | [diff] [blame] | 65 | #if defined(OS_CHROMEOS) |
[email protected] | c9afed6e | 2014-02-03 22:12:29 | [diff] [blame] | 66 | #include "chrome/browser/metrics/metrics_log_chromeos.h" |
| 67 | #endif // OS_CHROMEOS |
[email protected] | afc03f0 | 2013-10-11 06:01:35 | [diff] [blame] | 68 | |
[email protected] | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 69 | using content::GpuDataManager; |
[email protected] | 064107e | 2014-05-02 00:59:06 | [diff] [blame] | 70 | using metrics::MetricsLogBase; |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 71 | using metrics::OmniboxEventProto; |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 72 | using metrics::ProfilerEventProto; |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 73 | using metrics::SystemProfileProto; |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 74 | using tracked_objects::ProcessDataSnapshot; |
[email protected] | b3610d4 | 2014-05-19 18:07:23 | [diff] [blame] | 75 | typedef variations::ActiveGroupId ActiveGroupId; |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 76 | typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo; |
[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 | |
[email protected] | 1f74e80 | 2014-03-29 03:08:35 | [diff] [blame] | 88 | return pref->GetString(prefs::kMetricsReportingEnabledTimestamp); |
[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] | 2c03c06b | 2013-12-11 20:45:02 | [diff] [blame] | 131 | case AutocompleteMatchType::SEARCH_SUGGEST_ENTITY: |
| 132 | return OmniboxEventProto::Suggestion::SEARCH_SUGGEST_ENTITY; |
| 133 | case AutocompleteMatchType::SEARCH_SUGGEST_INFINITE: |
| 134 | return OmniboxEventProto::Suggestion::SEARCH_SUGGEST_INFINITE; |
| 135 | case AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED: |
| 136 | return OmniboxEventProto::Suggestion::SEARCH_SUGGEST_PERSONALIZED; |
| 137 | case AutocompleteMatchType::SEARCH_SUGGEST_PROFILE: |
| 138 | return OmniboxEventProto::Suggestion::SEARCH_SUGGEST_PROFILE; |
[email protected] | b7f64d74 | 2013-05-21 04:04:04 | [diff] [blame] | 139 | case AutocompleteMatchType::SEARCH_OTHER_ENGINE: |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 140 | return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE; |
[email protected] | b7f64d74 | 2013-05-21 04:04:04 | [diff] [blame] | 141 | case AutocompleteMatchType::EXTENSION_APP: |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 142 | return OmniboxEventProto::Suggestion::EXTENSION_APP; |
[email protected] | b7f64d74 | 2013-05-21 04:04:04 | [diff] [blame] | 143 | case AutocompleteMatchType::BOOKMARK_TITLE: |
[email protected] | 2532060 | 2012-10-18 22:05:56 | [diff] [blame] | 144 | return OmniboxEventProto::Suggestion::BOOKMARK_TITLE; |
[email protected] | 78981d8c | 2014-05-09 15:05:47 | [diff] [blame] | 145 | case AutocompleteMatchType::NAVSUGGEST_PERSONALIZED: |
| 146 | return OmniboxEventProto::Suggestion::NAVSUGGEST_PERSONALIZED; |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 147 | default: |
| 148 | NOTREACHED(); |
| 149 | return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE; |
| 150 | } |
| 151 | } |
| 152 | |
[email protected] | 3c919d6a | 2013-07-28 18:35:52 | [diff] [blame] | 153 | OmniboxEventProto::PageClassification AsOmniboxEventPageClassification( |
| 154 | AutocompleteInput::PageClassification page_classification) { |
| 155 | switch (page_classification) { |
| 156 | case AutocompleteInput::INVALID_SPEC: |
| 157 | return OmniboxEventProto::INVALID_SPEC; |
[email protected] | 12b5cd05 | 2013-11-08 20:59:37 | [diff] [blame] | 158 | case AutocompleteInput::NTP: |
| 159 | return OmniboxEventProto::NTP; |
[email protected] | 3c919d6a | 2013-07-28 18:35:52 | [diff] [blame] | 160 | case AutocompleteInput::BLANK: |
| 161 | return OmniboxEventProto::BLANK; |
[email protected] | 0b1a111 | 2013-08-28 05:23:31 | [diff] [blame] | 162 | case AutocompleteInput::HOME_PAGE: |
| 163 | return OmniboxEventProto::HOME_PAGE; |
[email protected] | 3c919d6a | 2013-07-28 18:35:52 | [diff] [blame] | 164 | case AutocompleteInput::OTHER: |
| 165 | return OmniboxEventProto::OTHER; |
[email protected] | 3c919d6a | 2013-07-28 18:35:52 | [diff] [blame] | 166 | case AutocompleteInput::SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT: |
| 167 | return OmniboxEventProto:: |
| 168 | SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT; |
[email protected] | 12b5cd05 | 2013-11-08 20:59:37 | [diff] [blame] | 169 | case AutocompleteInput::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS: |
| 170 | return OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS; |
| 171 | case AutocompleteInput::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS: |
| 172 | return OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS; |
[email protected] | 2328ee2 | 2013-08-08 23:00:19 | [diff] [blame] | 173 | case AutocompleteInput::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT: |
| 174 | return OmniboxEventProto:: |
| 175 | SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT; |
[email protected] | 3c919d6a | 2013-07-28 18:35:52 | [diff] [blame] | 176 | } |
| 177 | return OmniboxEventProto::INVALID_SPEC; |
| 178 | } |
| 179 | |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 180 | ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType( |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 181 | int process_type) { |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 182 | switch (process_type) { |
| 183 | case content::PROCESS_TYPE_BROWSER: |
| 184 | return ProfilerEventProto::TrackedObject::BROWSER; |
| 185 | case content::PROCESS_TYPE_RENDERER: |
| 186 | return ProfilerEventProto::TrackedObject::RENDERER; |
| 187 | case content::PROCESS_TYPE_PLUGIN: |
| 188 | return ProfilerEventProto::TrackedObject::PLUGIN; |
| 189 | case content::PROCESS_TYPE_WORKER: |
| 190 | return ProfilerEventProto::TrackedObject::WORKER; |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 191 | case content::PROCESS_TYPE_UTILITY: |
| 192 | return ProfilerEventProto::TrackedObject::UTILITY; |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 193 | case content::PROCESS_TYPE_ZYGOTE: |
| 194 | return ProfilerEventProto::TrackedObject::ZYGOTE; |
| 195 | case content::PROCESS_TYPE_SANDBOX_HELPER: |
| 196 | return ProfilerEventProto::TrackedObject::SANDBOX_HELPER; |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 197 | case content::PROCESS_TYPE_GPU: |
| 198 | return ProfilerEventProto::TrackedObject::GPU; |
| 199 | case content::PROCESS_TYPE_PPAPI_PLUGIN: |
| 200 | return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN; |
| 201 | case content::PROCESS_TYPE_PPAPI_BROKER: |
| 202 | return ProfilerEventProto::TrackedObject::PPAPI_BROKER; |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 203 | case PROCESS_TYPE_NACL_LOADER: |
| 204 | return ProfilerEventProto::TrackedObject::NACL_LOADER; |
| 205 | case PROCESS_TYPE_NACL_BROKER: |
| 206 | return ProfilerEventProto::TrackedObject::NACL_BROKER; |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 207 | default: |
| 208 | NOTREACHED(); |
| 209 | return ProfilerEventProto::TrackedObject::UNKNOWN; |
| 210 | } |
| 211 | } |
| 212 | |
[email protected] | 064107e | 2014-05-02 00:59:06 | [diff] [blame] | 213 | SystemProfileProto::Channel AsProtobufChannel( |
| 214 | chrome::VersionInfo::Channel channel) { |
| 215 | switch (channel) { |
| 216 | case chrome::VersionInfo::CHANNEL_UNKNOWN: |
| 217 | return SystemProfileProto::CHANNEL_UNKNOWN; |
| 218 | case chrome::VersionInfo::CHANNEL_CANARY: |
| 219 | return SystemProfileProto::CHANNEL_CANARY; |
| 220 | case chrome::VersionInfo::CHANNEL_DEV: |
| 221 | return SystemProfileProto::CHANNEL_DEV; |
| 222 | case chrome::VersionInfo::CHANNEL_BETA: |
| 223 | return SystemProfileProto::CHANNEL_BETA; |
| 224 | case chrome::VersionInfo::CHANNEL_STABLE: |
| 225 | return SystemProfileProto::CHANNEL_STABLE; |
| 226 | default: |
| 227 | NOTREACHED(); |
| 228 | return SystemProfileProto::CHANNEL_UNKNOWN; |
| 229 | } |
| 230 | } |
| 231 | |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 232 | // Computes a SHA-1 hash of |data| and returns it as a hex string. |
| 233 | std::string ComputeSHA1(const std::string& data) { |
| 234 | const std::string sha1 = base::SHA1HashString(data); |
| 235 | return base::HexEncode(sha1.data(), sha1.size()); |
| 236 | } |
| 237 | |
[email protected] | 1d51882f | 2013-11-12 01:59:02 | [diff] [blame] | 238 | #if defined(ENABLE_PLUGINS) |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 239 | // Returns the plugin preferences corresponding for this user, if available. |
| 240 | // If multiple user profiles are loaded, returns the preferences corresponding |
| 241 | // to an arbitrary one of the profiles. |
| 242 | PluginPrefs* GetPluginPrefs() { |
| 243 | ProfileManager* profile_manager = g_browser_process->profile_manager(); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 244 | |
| 245 | if (!profile_manager) { |
| 246 | // The profile manager can be NULL when testing. |
| 247 | return NULL; |
| 248 | } |
| 249 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 250 | std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); |
| 251 | if (profiles.empty()) |
| 252 | return NULL; |
| 253 | |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 254 | return PluginPrefs::GetForProfile(profiles.front()).get(); |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 255 | } |
| 256 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 257 | // Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|. |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 258 | void SetPluginInfo(const content::WebPluginInfo& plugin_info, |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 259 | const PluginPrefs* plugin_prefs, |
| 260 | SystemProfileProto::Plugin* plugin) { |
[email protected] | 6778fed | 2013-12-24 20:09:37 | [diff] [blame] | 261 | plugin->set_name(base::UTF16ToUTF8(plugin_info.name)); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 262 | plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe()); |
[email protected] | 6778fed | 2013-12-24 20:09:37 | [diff] [blame] | 263 | plugin->set_version(base::UTF16ToUTF8(plugin_info.version)); |
[email protected] | 4e3ca1c29 | 2013-09-10 01:59:19 | [diff] [blame] | 264 | plugin->set_is_pepper(plugin_info.is_pepper_plugin()); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 265 | if (plugin_prefs) |
| 266 | plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info)); |
| 267 | } |
[email protected] | 1d51882f | 2013-11-12 01:59:02 | [diff] [blame] | 268 | #endif // defined(ENABLE_PLUGINS) |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 269 | |
[email protected] | 0c8b7ad | 2012-11-06 07:08:14 | [diff] [blame] | 270 | void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids, |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 271 | SystemProfileProto* system_profile) { |
[email protected] | 0c8b7ad | 2012-11-06 07:08:14 | [diff] [blame] | 272 | for (std::vector<ActiveGroupId>::const_iterator it = |
[email protected] | ad2461c | 2012-04-27 21:11:03 | [diff] [blame] | 273 | field_trial_ids.begin(); it != field_trial_ids.end(); ++it) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 274 | SystemProfileProto::FieldTrial* field_trial = |
| 275 | system_profile->add_field_trial(); |
| 276 | field_trial->set_name_id(it->name); |
| 277 | field_trial->set_group_id(it->group); |
| 278 | } |
| 279 | } |
| 280 | |
[email protected] | 0018f72 | 2014-02-08 03:08:51 | [diff] [blame] | 281 | // Maps a thread name by replacing trailing sequence of digits with "*". |
| 282 | // Examples: |
| 283 | // 1. "BrowserBlockingWorker1/23857" => "BrowserBlockingWorker1/*" |
| 284 | // 2. "Chrome_IOThread" => "Chrome_IOThread" |
| 285 | std::string MapThreadName(const std::string& thread_name) { |
| 286 | size_t i = thread_name.length(); |
| 287 | |
| 288 | while (i > 0 && isdigit(thread_name[i - 1])) { |
| 289 | --i; |
| 290 | } |
| 291 | |
| 292 | if (i == thread_name.length()) |
| 293 | return thread_name; |
| 294 | |
| 295 | return thread_name.substr(0, i) + '*'; |
| 296 | } |
| 297 | |
[email protected] | 87b9bf1 | 2014-04-03 15:25:00 | [diff] [blame] | 298 | // Normalizes a source filename (which is platform- and build-method-dependent) |
| 299 | // by extracting the last component of the full file name. |
| 300 | // Example: "c:\b\build\slave\win\build\src\chrome\app\chrome_main.cc" => |
| 301 | // "chrome_main.cc". |
| 302 | std::string NormalizeFileName(const std::string& file_name) { |
| 303 | const size_t offset = file_name.find_last_of("\\/"); |
| 304 | return offset != std::string::npos ? file_name.substr(offset + 1) : file_name; |
| 305 | } |
| 306 | |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 307 | void WriteProfilerData(const ProcessDataSnapshot& profiler_data, |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 308 | int process_type, |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 309 | ProfilerEventProto* performance_profile) { |
| 310 | for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it = |
| 311 | profiler_data.tasks.begin(); |
| 312 | it != profiler_data.tasks.end(); ++it) { |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 313 | const tracked_objects::DeathDataSnapshot& death_data = it->death_data; |
| 314 | ProfilerEventProto::TrackedObject* tracked_object = |
| 315 | performance_profile->add_tracked_object(); |
[email protected] | db7fec83 | 2013-07-18 09:41:41 | [diff] [blame] | 316 | tracked_object->set_birth_thread_name_hash( |
[email protected] | 0018f72 | 2014-02-08 03:08:51 | [diff] [blame] | 317 | MetricsLogBase::Hash(MapThreadName(it->birth.thread_name))); |
[email protected] | db7fec83 | 2013-07-18 09:41:41 | [diff] [blame] | 318 | tracked_object->set_exec_thread_name_hash( |
[email protected] | 0018f72 | 2014-02-08 03:08:51 | [diff] [blame] | 319 | MetricsLogBase::Hash(MapThreadName(it->death_thread_name))); |
[email protected] | db7fec83 | 2013-07-18 09:41:41 | [diff] [blame] | 320 | tracked_object->set_source_file_name_hash( |
[email protected] | 87b9bf1 | 2014-04-03 15:25:00 | [diff] [blame] | 321 | MetricsLogBase::Hash(NormalizeFileName(it->birth.location.file_name))); |
[email protected] | db7fec83 | 2013-07-18 09:41:41 | [diff] [blame] | 322 | tracked_object->set_source_function_name_hash( |
| 323 | MetricsLogBase::Hash(it->birth.location.function_name)); |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 324 | tracked_object->set_source_line_number(it->birth.location.line_number); |
| 325 | tracked_object->set_exec_count(death_data.count); |
| 326 | tracked_object->set_exec_time_total(death_data.run_duration_sum); |
| 327 | tracked_object->set_exec_time_sampled(death_data.run_duration_sample); |
| 328 | tracked_object->set_queue_time_total(death_data.queue_duration_sum); |
| 329 | tracked_object->set_queue_time_sampled(death_data.queue_duration_sample); |
| 330 | tracked_object->set_process_type(AsProtobufProcessType(process_type)); |
| 331 | tracked_object->set_process_id(profiler_data.process_id); |
| 332 | } |
| 333 | } |
| 334 | |
[email protected] | 59a7ae4e | 2012-10-01 23:54:44 | [diff] [blame] | 335 | #if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 336 | void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data, |
| 337 | ProductInfo* product_info) { |
| 338 | product_info->set_version(product_data.version); |
| 339 | product_info->set_last_update_success_timestamp( |
| 340 | product_data.last_success.ToTimeT()); |
| 341 | product_info->set_last_error(product_data.last_error_code); |
| 342 | product_info->set_last_extra_error(product_data.last_extra_code); |
| 343 | if (ProductInfo::InstallResult_IsValid(product_data.last_result)) { |
| 344 | product_info->set_last_result( |
| 345 | static_cast<ProductInfo::InstallResult>(product_data.last_result)); |
| 346 | } |
| 347 | } |
[email protected] | 59a7ae4e | 2012-10-01 23:54:44 | [diff] [blame] | 348 | #endif |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 349 | |
[email protected] | 76869ff | 2013-01-15 16:13:47 | [diff] [blame] | 350 | #if defined(OS_WIN) |
[email protected] | ffaf732 | 2013-05-15 00:26:11 | [diff] [blame] | 351 | struct ScreenDPIInformation { |
[email protected] | 76869ff | 2013-01-15 16:13:47 | [diff] [blame] | 352 | double max_dpi_x; |
| 353 | double max_dpi_y; |
| 354 | }; |
| 355 | |
| 356 | // Called once for each connected monitor. |
| 357 | BOOL CALLBACK GetMonitorDPICallback(HMONITOR, HDC hdc, LPRECT, LPARAM dwData) { |
| 358 | const double kMillimetersPerInch = 25.4; |
| 359 | ScreenDPIInformation* screen_info = |
| 360 | reinterpret_cast<ScreenDPIInformation*>(dwData); |
| 361 | // Size of screen, in mm. |
| 362 | DWORD size_x = GetDeviceCaps(hdc, HORZSIZE); |
| 363 | DWORD size_y = GetDeviceCaps(hdc, VERTSIZE); |
| 364 | double dpi_x = (size_x > 0) ? |
| 365 | GetDeviceCaps(hdc, HORZRES) / (size_x / kMillimetersPerInch) : 0; |
| 366 | double dpi_y = (size_y > 0) ? |
| 367 | GetDeviceCaps(hdc, VERTRES) / (size_y / kMillimetersPerInch) : 0; |
| 368 | screen_info->max_dpi_x = std::max(dpi_x, screen_info->max_dpi_x); |
| 369 | screen_info->max_dpi_y = std::max(dpi_y, screen_info->max_dpi_y); |
| 370 | return TRUE; |
| 371 | } |
| 372 | |
| 373 | void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) { |
| 374 | HDC desktop_dc = GetDC(NULL); |
| 375 | if (desktop_dc) { |
[email protected] | ffaf732 | 2013-05-15 00:26:11 | [diff] [blame] | 376 | ScreenDPIInformation si = {0, 0}; |
[email protected] | 76869ff | 2013-01-15 16:13:47 | [diff] [blame] | 377 | if (EnumDisplayMonitors(desktop_dc, NULL, GetMonitorDPICallback, |
| 378 | reinterpret_cast<LPARAM>(&si))) { |
| 379 | hardware->set_max_dpi_x(si.max_dpi_x); |
| 380 | hardware->set_max_dpi_y(si.max_dpi_y); |
| 381 | } |
| 382 | ReleaseDC(GetDesktopWindow(), desktop_dc); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | #endif // defined(OS_WIN) |
| 387 | |
[email protected] | 86573d1 | 2013-07-11 19:48:32 | [diff] [blame] | 388 | // Round a timestamp measured in seconds since epoch to one with a granularity |
| 389 | // of an hour. This can be used before uploaded potentially sensitive |
| 390 | // timestamps. |
| 391 | int64 RoundSecondsToHour(int64 time_in_seconds) { |
| 392 | return 3600 * (time_in_seconds / 3600); |
| 393 | } |
| 394 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 395 | } // namespace |
| 396 | |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 397 | GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {} |
| 398 | |
| 399 | GoogleUpdateMetrics::~GoogleUpdateMetrics() {} |
| 400 | |
[email protected] | 67f92bc3 | 2012-01-26 01:56:19 | [diff] [blame] | 401 | static base::LazyInstance<std::string>::Leaky |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 402 | g_version_extension = LAZY_INSTANCE_INITIALIZER; |
[email protected] | 054c801 | 2011-11-16 00:12:42 | [diff] [blame] | 403 | |
[email protected] | 9eae403 | 2014-04-09 19:15:19 | [diff] [blame] | 404 | MetricsLog::MetricsLog(const std::string& client_id, |
| 405 | int session_id, |
| 406 | LogType log_type) |
| 407 | : MetricsLogBase(client_id, session_id, log_type, |
| 408 | MetricsLog::GetVersionString()), |
[email protected] | b84ee6e | 2014-03-15 22:51:54 | [diff] [blame] | 409 | creation_time_(base::TimeTicks::Now()), |
| 410 | extension_metrics_(uma_proto()->client_id()) { |
[email protected] | 064107e | 2014-05-02 00:59:06 | [diff] [blame] | 411 | uma_proto()->mutable_system_profile()->set_channel( |
[email protected] | 1e6f9e2 | 2014-05-09 09:10:28 | [diff] [blame] | 412 | AsProtobufChannel(chrome::VersionInfo::GetChannel())); |
[email protected] | 064107e | 2014-05-02 00:59:06 | [diff] [blame] | 413 | |
[email protected] | afc03f0 | 2013-10-11 06:01:35 | [diff] [blame] | 414 | #if defined(OS_CHROMEOS) |
[email protected] | c9afed6e | 2014-02-03 22:12:29 | [diff] [blame] | 415 | metrics_log_chromeos_.reset(new MetricsLogChromeOS(uma_proto())); |
| 416 | #endif // OS_CHROMEOS |
[email protected] | afc03f0 | 2013-10-11 06:01:35 | [diff] [blame] | 417 | } |
[email protected] | 5ed7d457 | 2009-12-23 17:42:41 | [diff] [blame] | 418 | |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 419 | MetricsLog::~MetricsLog() {} |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 420 | |
| 421 | // static |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 422 | void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) { |
| 423 | registry->RegisterListPref(prefs::kStabilityPluginStats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 424 | } |
| 425 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 426 | // static |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 427 | std::string MetricsLog::GetVersionString() { |
[email protected] | 0211f57e | 2010-08-27 20:28:42 | [diff] [blame] | 428 | chrome::VersionInfo version_info; |
[email protected] | 30c9180 | 2010-12-18 00:40:17 | [diff] [blame] | 429 | if (!version_info.is_valid()) { |
| 430 | NOTREACHED() << "Unable to retrieve version info."; |
| 431 | return std::string(); |
| 432 | } |
| 433 | |
[email protected] | 0211f57e | 2010-08-27 20:28:42 | [diff] [blame] | 434 | std::string version = version_info.Version(); |
[email protected] | 054c801 | 2011-11-16 00:12:42 | [diff] [blame] | 435 | if (!version_extension().empty()) |
| 436 | version += version_extension(); |
[email protected] | 0211f57e | 2010-08-27 20:28:42 | [diff] [blame] | 437 | if (!version_info.IsOfficialBuild()) |
| 438 | version.append("-devel"); |
| 439 | return version; |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 440 | } |
| 441 | |
[email protected] | 054c801 | 2011-11-16 00:12:42 | [diff] [blame] | 442 | // static |
| 443 | void MetricsLog::set_version_extension(const std::string& extension) { |
| 444 | g_version_extension.Get() = extension; |
| 445 | } |
| 446 | |
| 447 | // static |
| 448 | const std::string& MetricsLog::version_extension() { |
| 449 | return g_version_extension.Get(); |
| 450 | } |
| 451 | |
[email protected] | 85791b0b | 2014-05-20 15:18:58 | [diff] [blame^] | 452 | void MetricsLog::RecordStabilityMetrics( |
| 453 | const std::vector<metrics::MetricsProvider*>& metrics_providers, |
| 454 | base::TimeDelta incremental_uptime, |
| 455 | base::TimeDelta uptime) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 456 | DCHECK(!locked()); |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 457 | DCHECK(HasEnvironment()); |
| 458 | DCHECK(!HasStabilityMetrics()); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 459 | |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 460 | PrefService* pref = GetPrefService(); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 461 | DCHECK(pref); |
| 462 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 463 | // Get stability attributes out of Local State, zeroing out stored values. |
| 464 | // NOTE: This could lead to some data loss if this report isn't successfully |
| 465 | // sent, but that's true for all the metrics. |
| 466 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 467 | WriteRequiredStabilityAttributes(pref); |
[email protected] | 250f7b66 | 2013-11-23 02:36:51 | [diff] [blame] | 468 | WritePluginStabilityElements(pref); |
[email protected] | 0edf876 | 2013-11-21 18:33:30 | [diff] [blame] | 469 | |
| 470 | // Record recent delta for critical stability metrics. We can't wait for a |
| 471 | // restart to gather these, as that delay biases our observation away from |
| 472 | // users that run happily for a looooong time. We send increments with each |
| 473 | // uma log upload, just as we send histogram data. |
[email protected] | 076961c | 2014-03-12 22:23:56 | [diff] [blame] | 474 | WriteRealtimeStabilityAttributes(pref, incremental_uptime, uptime); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 475 | |
[email protected] | 85791b0b | 2014-05-20 15:18:58 | [diff] [blame^] | 476 | SystemProfileProto::Stability* stability = |
| 477 | uma_proto()->mutable_system_profile()->mutable_stability(); |
| 478 | for (size_t i = 0; i < metrics_providers.size(); ++i) |
| 479 | metrics_providers[i]->ProvideStabilityMetrics(stability); |
| 480 | |
[email protected] | 0edf876 | 2013-11-21 18:33:30 | [diff] [blame] | 481 | // Omit some stats unless this is the initial stability log. |
[email protected] | 9eae403 | 2014-04-09 19:15:19 | [diff] [blame] | 482 | if (log_type() != INITIAL_STABILITY_LOG) |
[email protected] | 0edf876 | 2013-11-21 18:33:30 | [diff] [blame] | 483 | return; |
| 484 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 485 | int incomplete_shutdown_count = |
| 486 | pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount); |
[email protected] | e324f6b | 2012-02-28 05:43:37 | [diff] [blame] | 487 | pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 488 | int breakpad_registration_success_count = |
| 489 | pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess); |
[email protected] | e324f6b | 2012-02-28 05:43:37 | [diff] [blame] | 490 | pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 491 | int breakpad_registration_failure_count = |
| 492 | pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail); |
[email protected] | e324f6b | 2012-02-28 05:43:37 | [diff] [blame] | 493 | pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 494 | int debugger_present_count = |
| 495 | pref->GetInteger(prefs::kStabilityDebuggerPresent); |
[email protected] | e324f6b | 2012-02-28 05:43:37 | [diff] [blame] | 496 | pref->SetInteger(prefs::kStabilityDebuggerPresent, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 497 | int debugger_not_present_count = |
| 498 | pref->GetInteger(prefs::kStabilityDebuggerNotPresent); |
[email protected] | e324f6b | 2012-02-28 05:43:37 | [diff] [blame] | 499 | pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); |
[email protected] | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 500 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 501 | // TODO(jar): The following are all optional, so we *could* optimize them for |
| 502 | // values of zero (and not include them). |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 503 | stability->set_incomplete_shutdown_count(incomplete_shutdown_count); |
| 504 | stability->set_breakpad_registration_success_count( |
| 505 | breakpad_registration_success_count); |
| 506 | stability->set_breakpad_registration_failure_count( |
| 507 | breakpad_registration_failure_count); |
| 508 | stability->set_debugger_present_count(debugger_present_count); |
| 509 | stability->set_debugger_not_present_count(debugger_not_present_count); |
[email protected] | 0edf876 | 2013-11-21 18:33:30 | [diff] [blame] | 510 | } |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 511 | |
[email protected] | 85791b0b | 2014-05-20 15:18:58 | [diff] [blame^] | 512 | void MetricsLog::RecordGeneralMetrics( |
| 513 | const std::vector<metrics::MetricsProvider*>& metrics_providers) { |
| 514 | for (size_t i = 0; i < metrics_providers.size(); ++i) |
| 515 | metrics_providers[i]->ProvideGeneralMetrics(uma_proto()); |
| 516 | } |
| 517 | |
[email protected] | 0edf876 | 2013-11-21 18:33:30 | [diff] [blame] | 518 | PrefService* MetricsLog::GetPrefService() { |
| 519 | return g_browser_process->local_state(); |
| 520 | } |
| 521 | |
| 522 | gfx::Size MetricsLog::GetScreenSize() const { |
| 523 | return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel(); |
| 524 | } |
| 525 | |
| 526 | float MetricsLog::GetScreenDeviceScaleFactor() const { |
| 527 | return gfx::Screen::GetNativeScreen()-> |
| 528 | GetPrimaryDisplay().device_scale_factor(); |
| 529 | } |
| 530 | |
| 531 | int MetricsLog::GetScreenCount() const { |
| 532 | // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312 |
| 533 | return gfx::Screen::GetNativeScreen()->GetNumDisplays(); |
| 534 | } |
| 535 | |
| 536 | void MetricsLog::GetFieldTrialIds( |
| 537 | std::vector<ActiveGroupId>* field_trial_ids) const { |
[email protected] | b3610d4 | 2014-05-19 18:07:23 | [diff] [blame] | 538 | variations::GetFieldTrialActiveGroupIds(field_trial_ids); |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 539 | } |
| 540 | |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 541 | bool MetricsLog::HasEnvironment() const { |
| 542 | return uma_proto()->system_profile().has_uma_enabled_date(); |
| 543 | } |
| 544 | |
| 545 | bool MetricsLog::HasStabilityMetrics() const { |
| 546 | return uma_proto()->system_profile().stability().has_launch_count(); |
| 547 | } |
| 548 | |
[email protected] | 250f7b66 | 2013-11-23 02:36:51 | [diff] [blame] | 549 | void MetricsLog::WritePluginStabilityElements(PrefService* pref) { |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 550 | // Now log plugin stability info. |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 551 | const base::ListValue* plugin_stats_list = pref->GetList( |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 552 | prefs::kStabilityPluginStats); |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 553 | if (!plugin_stats_list) |
| 554 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 555 | |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 556 | #if defined(ENABLE_PLUGINS) |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 557 | SystemProfileProto::Stability* stability = |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 558 | uma_proto()->mutable_system_profile()->mutable_stability(); |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 559 | for (base::ListValue::const_iterator iter = plugin_stats_list->begin(); |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 560 | iter != plugin_stats_list->end(); ++iter) { |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 561 | if (!(*iter)->IsType(base::Value::TYPE_DICTIONARY)) { |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 562 | NOTREACHED(); |
| 563 | continue; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 564 | } |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 565 | base::DictionaryValue* plugin_dict = |
| 566 | static_cast<base::DictionaryValue*>(*iter); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 567 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 568 | // Note that this search is potentially a quadratic operation, but given the |
| 569 | // low number of plugins installed on a "reasonable" setup, this should be |
| 570 | // fine. |
| 571 | // TODO(isherman): Verify that this does not show up as a hotspot in |
| 572 | // profiler runs. |
[email protected] | 250f7b66 | 2013-11-23 02:36:51 | [diff] [blame] | 573 | const SystemProfileProto::Plugin* system_profile_plugin = NULL; |
[email protected] | f31a01a | 2013-07-13 02:51:11 | [diff] [blame] | 574 | std::string plugin_name; |
| 575 | plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name); |
[email protected] | 250f7b66 | 2013-11-23 02:36:51 | [diff] [blame] | 576 | const SystemProfileProto& system_profile = uma_proto()->system_profile(); |
| 577 | for (int i = 0; i < system_profile.plugin_size(); ++i) { |
| 578 | if (system_profile.plugin(i).name() == plugin_name) { |
| 579 | system_profile_plugin = &system_profile.plugin(i); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 580 | break; |
| 581 | } |
| 582 | } |
| 583 | |
[email protected] | 250f7b66 | 2013-11-23 02:36:51 | [diff] [blame] | 584 | if (!system_profile_plugin) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 585 | NOTREACHED(); |
| 586 | continue; |
| 587 | } |
| 588 | |
| 589 | SystemProfileProto::Stability::PluginStability* plugin_stability = |
| 590 | stability->add_plugin_stability(); |
[email protected] | 250f7b66 | 2013-11-23 02:36:51 | [diff] [blame] | 591 | *plugin_stability->mutable_plugin() = *system_profile_plugin; |
[email protected] | f31a01a | 2013-07-13 02:51:11 | [diff] [blame] | 592 | |
| 593 | int launches = 0; |
| 594 | plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches); |
| 595 | if (launches > 0) |
| 596 | plugin_stability->set_launch_count(launches); |
| 597 | |
| 598 | int instances = 0; |
| 599 | plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances); |
| 600 | if (instances > 0) |
| 601 | plugin_stability->set_instance_count(instances); |
| 602 | |
| 603 | int crashes = 0; |
| 604 | plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes); |
| 605 | if (crashes > 0) |
| 606 | plugin_stability->set_crash_count(crashes); |
| 607 | |
| 608 | int loading_errors = 0; |
| 609 | plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors, |
| 610 | &loading_errors); |
| 611 | if (loading_errors > 0) |
| 612 | plugin_stability->set_loading_error_count(loading_errors); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 613 | } |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 614 | #endif // defined(ENABLE_PLUGINS) |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 615 | |
| 616 | pref->ClearPref(prefs::kStabilityPluginStats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 617 | } |
| 618 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 619 | // The server refuses data that doesn't have certain values. crashcount and |
| 620 | // launchcount are currently "required" in the "stability" group. |
| 621 | // TODO(isherman): Stop writing these attributes specially once the migration to |
| 622 | // protobufs is complete. |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 623 | void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 624 | int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 625 | pref->SetInteger(prefs::kStabilityLaunchCount, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 626 | int crash_count = pref->GetInteger(prefs::kStabilityCrashCount); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 627 | pref->SetInteger(prefs::kStabilityCrashCount, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 628 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 629 | SystemProfileProto::Stability* stability = |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 630 | uma_proto()->mutable_system_profile()->mutable_stability(); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 631 | stability->set_launch_count(launch_count); |
| 632 | stability->set_crash_count(crash_count); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 633 | } |
| 634 | |
[email protected] | c68a2b9b | 2013-10-09 18:16:36 | [diff] [blame] | 635 | void MetricsLog::WriteRealtimeStabilityAttributes( |
| 636 | PrefService* pref, |
[email protected] | 076961c | 2014-03-12 22:23:56 | [diff] [blame] | 637 | base::TimeDelta incremental_uptime, |
| 638 | base::TimeDelta uptime) { |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 639 | // Update the stats which are critical for real-time stability monitoring. |
| 640 | // Since these are "optional," only list ones that are non-zero, as the counts |
[email protected] | 250f7b66 | 2013-11-23 02:36:51 | [diff] [blame] | 641 | // are aggregated (summed) server side. |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 642 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 643 | SystemProfileProto::Stability* stability = |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 644 | uma_proto()->mutable_system_profile()->mutable_stability(); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 645 | int count = pref->GetInteger(prefs::kStabilityPageLoadCount); |
| 646 | if (count) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 647 | stability->set_page_load_count(count); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 648 | pref->SetInteger(prefs::kStabilityPageLoadCount, 0); |
| 649 | } |
| 650 | |
| 651 | count = pref->GetInteger(prefs::kStabilityRendererCrashCount); |
| 652 | if (count) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 653 | stability->set_renderer_crash_count(count); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 654 | pref->SetInteger(prefs::kStabilityRendererCrashCount, 0); |
| 655 | } |
| 656 | |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 657 | count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount); |
| 658 | if (count) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 659 | stability->set_extension_renderer_crash_count(count); |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 660 | pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0); |
| 661 | } |
| 662 | |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 663 | count = pref->GetInteger(prefs::kStabilityRendererHangCount); |
| 664 | if (count) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 665 | stability->set_renderer_hang_count(count); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 666 | pref->SetInteger(prefs::kStabilityRendererHangCount, 0); |
| 667 | } |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 668 | |
| 669 | count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount); |
| 670 | if (count) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 671 | stability->set_child_process_crash_count(count); |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 672 | pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); |
| 673 | } |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 674 | |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 675 | #if defined(OS_CHROMEOS) |
[email protected] | c9afed6e | 2014-02-03 22:12:29 | [diff] [blame] | 676 | metrics_log_chromeos_->WriteRealtimeStabilityAttributes(pref); |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 677 | #endif // OS_CHROMEOS |
| 678 | |
[email protected] | 076961c | 2014-03-12 22:23:56 | [diff] [blame] | 679 | const uint64 incremental_uptime_sec = incremental_uptime.InSeconds(); |
| 680 | if (incremental_uptime_sec) |
| 681 | stability->set_incremental_uptime_sec(incremental_uptime_sec); |
| 682 | const uint64 uptime_sec = uptime.InSeconds(); |
[email protected] | c68a2b9b | 2013-10-09 18:16:36 | [diff] [blame] | 683 | if (uptime_sec) |
| 684 | stability->set_uptime_sec(uptime_sec); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 685 | } |
| 686 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 687 | void MetricsLog::WritePluginList( |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 688 | const std::vector<content::WebPluginInfo>& plugin_list) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 689 | DCHECK(!locked()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 690 | |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 691 | #if defined(ENABLE_PLUGINS) |
| 692 | PluginPrefs* plugin_prefs = GetPluginPrefs(); |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 693 | SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 694 | for (std::vector<content::WebPluginInfo>::const_iterator iter = |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 695 | plugin_list.begin(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 696 | iter != plugin_list.end(); ++iter) { |
[email protected] | 0eecc254 | 2013-06-23 04:22:02 | [diff] [blame] | 697 | SystemProfileProto::Plugin* plugin = system_profile->add_plugin(); |
| 698 | SetPluginInfo(*iter, plugin_prefs, plugin); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 699 | } |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 700 | #endif // defined(ENABLE_PLUGINS) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | void MetricsLog::RecordEnvironment( |
[email protected] | 85791b0b | 2014-05-20 15:18:58 | [diff] [blame^] | 704 | const std::vector<metrics::MetricsProvider*>& metrics_providers, |
[email protected] | c68a2b9b | 2013-10-09 18:16:36 | [diff] [blame] | 705 | const std::vector<content::WebPluginInfo>& plugin_list, |
| 706 | const GoogleUpdateMetrics& google_update_metrics, |
[email protected] | b3610d4 | 2014-05-19 18:07:23 | [diff] [blame] | 707 | const std::vector<variations::ActiveGroupId>& synthetic_trials) { |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 708 | DCHECK(!HasEnvironment()); |
| 709 | |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 710 | SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
[email protected] | 24b9bb39 | 2013-01-29 20:29:29 | [diff] [blame] | 711 | |
| 712 | std::string brand_code; |
| 713 | if (google_util::GetBrand(&brand_code)) |
| 714 | system_profile->set_brand_code(brand_code); |
| 715 | |
[email protected] | cc5d7f4 | 2012-10-30 00:30:09 | [diff] [blame] | 716 | int enabled_date; |
| 717 | bool success = base::StringToInt(GetMetricsEnabledDate(GetPrefService()), |
| 718 | &enabled_date); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 719 | DCHECK(success); |
[email protected] | 86573d1 | 2013-07-11 19:48:32 | [diff] [blame] | 720 | |
| 721 | // Reduce granularity of the enabled_date field to nearest hour. |
| 722 | system_profile->set_uma_enabled_date(RoundSecondsToHour(enabled_date)); |
| 723 | |
| 724 | int64 install_date = GetPrefService()->GetInt64(prefs::kInstallDate); |
| 725 | |
| 726 | // Reduce granularity of the install_date field to nearest hour. |
| 727 | system_profile->set_install_date(RoundSecondsToHour(install_date)); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 728 | |
| 729 | system_profile->set_application_locale( |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 730 | g_browser_process->GetApplicationLocale()); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 731 | |
| 732 | SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware(); |
[email protected] | 0b6a4fb | 2012-10-16 01:58:21 | [diff] [blame] | 733 | hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture()); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 734 | hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB()); |
| 735 | #if defined(OS_WIN) |
| 736 | hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase)); |
| 737 | #endif |
| 738 | |
[email protected] | 74b299e | 2013-01-29 01:24:42 | [diff] [blame] | 739 | SystemProfileProto::Network* network = system_profile->mutable_network(); |
| 740 | network->set_connection_type_is_ambiguous( |
[email protected] | 5eae204c | 2013-02-13 15:53:42 | [diff] [blame] | 741 | network_observer_.connection_type_is_ambiguous()); |
| 742 | network->set_connection_type(network_observer_.connection_type()); |
| 743 | network->set_wifi_phy_layer_protocol_is_ambiguous( |
| 744 | network_observer_.wifi_phy_layer_protocol_is_ambiguous()); |
| 745 | network->set_wifi_phy_layer_protocol( |
| 746 | network_observer_.wifi_phy_layer_protocol()); |
| 747 | network_observer_.Reset(); |
[email protected] | 74b299e | 2013-01-29 01:24:42 | [diff] [blame] | 748 | |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 749 | SystemProfileProto::OS* os = system_profile->mutable_os(); |
[email protected] | 1bb25e0 | 2012-08-03 22:39:39 | [diff] [blame] | 750 | std::string os_name = base::SysInfo::OperatingSystemName(); |
| 751 | #if defined(OS_WIN) |
| 752 | // TODO(mad): This only checks whether the main process is a Metro process at |
| 753 | // upload time; not whether the collected metrics were all gathered from |
| 754 | // Metro. This is ok as an approximation for now, since users will rarely be |
| 755 | // switching from Metro to Desktop mode; but we should re-evaluate whether we |
| 756 | // can distinguish metrics more cleanly in the future: http://crbug.com/140568 |
| 757 | if (base::win::IsMetroProcess()) |
| 758 | os_name += " (Metro)"; |
| 759 | #endif |
| 760 | os->set_name(os_name); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 761 | os->set_version(base::SysInfo::OperatingSystemVersion()); |
[email protected] | 5106b3a | 2012-10-03 20:10:44 | [diff] [blame] | 762 | #if defined(OS_ANDROID) |
| 763 | os->set_fingerprint( |
| 764 | base::android::BuildInfo::GetInstance()->android_build_fp()); |
| 765 | #endif |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 766 | |
[email protected] | 5c8f89f69 | 2013-07-18 11:13:28 | [diff] [blame] | 767 | base::CPU cpu_info; |
| 768 | SystemProfileProto::Hardware::CPU* cpu = hardware->mutable_cpu(); |
| 769 | cpu->set_vendor_name(cpu_info.vendor_name()); |
| 770 | cpu->set_signature(cpu_info.signature()); |
| 771 | |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 772 | const gpu::GPUInfo& gpu_info = |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 773 | GpuDataManager::GetInstance()->GetGPUInfo(); |
| 774 | SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu(); |
[email protected] | a094e2c | 2012-05-10 23:02:42 | [diff] [blame] | 775 | gpu->set_vendor_id(gpu_info.gpu.vendor_id); |
| 776 | gpu->set_device_id(gpu_info.gpu.device_id); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 777 | gpu->set_driver_version(gpu_info.driver_version); |
| 778 | gpu->set_driver_date(gpu_info.driver_date); |
| 779 | SystemProfileProto::Hardware::Graphics::PerformanceStatistics* |
| 780 | gpu_performance = gpu->mutable_performance_statistics(); |
| 781 | gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics); |
| 782 | gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming); |
| 783 | gpu_performance->set_overall_score(gpu_info.performance_stats.overall); |
[email protected] | d6bdfae | 2013-01-18 20:23:01 | [diff] [blame] | 784 | gpu->set_gl_vendor(gpu_info.gl_vendor); |
| 785 | gpu->set_gl_renderer(gpu_info.gl_renderer); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 786 | |
| 787 | const gfx::Size display_size = GetScreenSize(); |
| 788 | hardware->set_primary_screen_width(display_size.width()); |
| 789 | hardware->set_primary_screen_height(display_size.height()); |
[email protected] | aa9641797 | 2012-08-22 03:16:44 | [diff] [blame] | 790 | hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor()); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 791 | hardware->set_screen_count(GetScreenCount()); |
| 792 | |
[email protected] | 76869ff | 2013-01-15 16:13:47 | [diff] [blame] | 793 | #if defined(OS_WIN) |
| 794 | WriteScreenDPIInformationProto(hardware); |
| 795 | #endif |
| 796 | |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 797 | WriteGoogleUpdateProto(google_update_metrics); |
| 798 | |
[email protected] | 0eecc254 | 2013-06-23 04:22:02 | [diff] [blame] | 799 | WritePluginList(plugin_list); |
[email protected] | b84ee6e | 2014-03-15 22:51:54 | [diff] [blame] | 800 | extension_metrics_.WriteExtensionList(uma_proto()->mutable_system_profile()); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 801 | |
[email protected] | 0c8b7ad | 2012-11-06 07:08:14 | [diff] [blame] | 802 | std::vector<ActiveGroupId> field_trial_ids; |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 803 | GetFieldTrialIds(&field_trial_ids); |
| 804 | WriteFieldTrials(field_trial_ids, system_profile); |
[email protected] | 6067756 | 2013-11-17 15:52:55 | [diff] [blame] | 805 | WriteFieldTrials(synthetic_trials, system_profile); |
[email protected] | f65859e | 2013-02-04 20:00:25 | [diff] [blame] | 806 | |
| 807 | #if defined(OS_CHROMEOS) |
[email protected] | c9afed6e | 2014-02-03 22:12:29 | [diff] [blame] | 808 | metrics_log_chromeos_->LogChromeOSMetrics(); |
| 809 | #endif // OS_CHROMEOS |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 810 | |
[email protected] | 85791b0b | 2014-05-20 15:18:58 | [diff] [blame^] | 811 | for (size_t i = 0; i < metrics_providers.size(); ++i) |
| 812 | metrics_providers[i]->ProvideSystemProfileMetrics(system_profile); |
| 813 | |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 814 | std::string serialied_system_profile; |
| 815 | std::string base64_system_profile; |
[email protected] | 33fca12 | 2013-12-11 01:48:50 | [diff] [blame] | 816 | if (system_profile->SerializeToString(&serialied_system_profile)) { |
| 817 | base::Base64Encode(serialied_system_profile, &base64_system_profile); |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 818 | PrefService* local_state = GetPrefService(); |
| 819 | local_state->SetString(prefs::kStabilitySavedSystemProfile, |
| 820 | base64_system_profile); |
| 821 | local_state->SetString(prefs::kStabilitySavedSystemProfileHash, |
| 822 | ComputeSHA1(serialied_system_profile)); |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | bool MetricsLog::LoadSavedEnvironmentFromPrefs() { |
| 827 | PrefService* local_state = GetPrefService(); |
| 828 | const std::string base64_system_profile = |
| 829 | local_state->GetString(prefs::kStabilitySavedSystemProfile); |
| 830 | if (base64_system_profile.empty()) |
| 831 | return false; |
| 832 | |
| 833 | const std::string system_profile_hash = |
| 834 | local_state->GetString(prefs::kStabilitySavedSystemProfileHash); |
| 835 | local_state->ClearPref(prefs::kStabilitySavedSystemProfile); |
| 836 | local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash); |
| 837 | |
| 838 | SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
| 839 | std::string serialied_system_profile; |
| 840 | return base::Base64Decode(base64_system_profile, &serialied_system_profile) && |
| 841 | ComputeSHA1(serialied_system_profile) == system_profile_hash && |
| 842 | system_profile->ParseFromString(serialied_system_profile); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 843 | } |
| 844 | |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 845 | void MetricsLog::RecordProfilerData( |
| 846 | const tracked_objects::ProcessDataSnapshot& process_data, |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 847 | int process_type) { |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 848 | DCHECK(!locked()); |
| 849 | |
[email protected] | 8f82968 | 2012-04-27 00:36:49 | [diff] [blame] | 850 | if (tracked_objects::GetTimeSourceType() != |
| 851 | tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) { |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 852 | // We currently only support the default time source, wall clock time. |
| 853 | return; |
| 854 | } |
| 855 | |
| 856 | ProfilerEventProto* profile; |
| 857 | if (!uma_proto()->profiler_event_size()) { |
| 858 | // For the first process's data, add a new field to the protocol buffer. |
| 859 | profile = uma_proto()->add_profiler_event(); |
| 860 | profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE); |
| 861 | profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME); |
| 862 | } else { |
| 863 | // For the remaining calls, re-use the existing field. |
| 864 | profile = uma_proto()->mutable_profiler_event(0); |
| 865 | } |
| 866 | |
| 867 | WriteProfilerData(process_data, process_type, profile); |
| 868 | } |
| 869 | |
[email protected] | 0fafc8d | 2013-06-01 00:09:50 | [diff] [blame] | 870 | void MetricsLog::RecordOmniboxOpenedURL(const OmniboxLog& log) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 871 | DCHECK(!locked()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 872 | |
[email protected] | 8790210c | 2013-12-02 05:29:53 | [diff] [blame] | 873 | std::vector<base::string16> terms; |
[email protected] | 6595631 | 2012-04-19 21:28:12 | [diff] [blame] | 874 | const int num_terms = |
[email protected] | 8790210c | 2013-12-02 05:29:53 | [diff] [blame] | 875 | static_cast<int>(Tokenize(log.text, base::kWhitespaceUTF16, &terms)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 876 | |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 877 | OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event(); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 878 | omnibox_event->set_time(MetricsLogBase::GetCurrentTime()); |
| 879 | if (log.tab_id != -1) { |
| 880 | // If we know what tab the autocomplete URL was opened in, log it. |
| 881 | omnibox_event->set_tab_id(log.tab_id); |
| 882 | } |
| 883 | omnibox_event->set_typed_length(log.text.length()); |
[email protected] | 660fe8f3 | 2012-05-03 20:01:08 | [diff] [blame] | 884 | omnibox_event->set_just_deleted_text(log.just_deleted_text); |
[email protected] | 6595631 | 2012-04-19 21:28:12 | [diff] [blame] | 885 | omnibox_event->set_num_typed_terms(num_terms); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 886 | omnibox_event->set_selected_index(log.selected_index); |
[email protected] | 439f1e3 | 2013-12-09 20:09:09 | [diff] [blame] | 887 | if (log.completed_length != base::string16::npos) |
[email protected] | 62b3ef5 | 2013-01-18 00:13:02 | [diff] [blame] | 888 | omnibox_event->set_completed_length(log.completed_length); |
[email protected] | a015141 | 2014-05-01 18:55:02 | [diff] [blame] | 889 | const base::TimeDelta default_time_delta = |
| 890 | base::TimeDelta::FromMilliseconds(-1); |
[email protected] | 6595631 | 2012-04-19 21:28:12 | [diff] [blame] | 891 | if (log.elapsed_time_since_user_first_modified_omnibox != |
[email protected] | a015141 | 2014-05-01 18:55:02 | [diff] [blame] | 892 | default_time_delta) { |
[email protected] | 6595631 | 2012-04-19 21:28:12 | [diff] [blame] | 893 | // Only upload the typing duration if it is set/valid. |
| 894 | omnibox_event->set_typing_duration_ms( |
| 895 | log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds()); |
| 896 | } |
[email protected] | a015141 | 2014-05-01 18:55:02 | [diff] [blame] | 897 | if (log.elapsed_time_since_last_change_to_default_match != |
| 898 | default_time_delta) { |
| 899 | omnibox_event->set_duration_since_last_default_match_update_ms( |
| 900 | log.elapsed_time_since_last_change_to_default_match.InMilliseconds()); |
| 901 | } |
[email protected] | ee90253 | 2012-05-01 23:54:49 | [diff] [blame] | 902 | omnibox_event->set_current_page_classification( |
[email protected] | 3c919d6a | 2013-07-28 18:35:52 | [diff] [blame] | 903 | AsOmniboxEventPageClassification(log.current_page_classification)); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 904 | omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type)); |
[email protected] | a015141 | 2014-05-01 18:55:02 | [diff] [blame] | 905 | // We consider a paste-and-search/paste-and-go action to have a closed popup |
| 906 | // (as explained in omnibox_event.proto) even if it was not, because such |
| 907 | // actions ignore the contents of the popup so it doesn't matter that it was |
| 908 | // open. |
| 909 | const bool consider_popup_open = log.is_popup_open && !log.is_paste_and_go; |
| 910 | omnibox_event->set_is_popup_open(consider_popup_open); |
| 911 | omnibox_event->set_is_paste_and_go(log.is_paste_and_go); |
| 912 | if (consider_popup_open) { |
| 913 | omnibox_event->set_is_top_result_hidden_in_dropdown( |
| 914 | log.result.ShouldHideTopMatch()); |
| 915 | } |
[email protected] | 1fce7dd4 | 2013-08-06 02:29:17 | [diff] [blame] | 916 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 917 | for (AutocompleteResult::const_iterator i(log.result.begin()); |
| 918 | i != log.result.end(); ++i) { |
| 919 | OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion(); |
[email protected] | 0e9e878 | 2012-05-15 23:01:51 | [diff] [blame] | 920 | suggestion->set_provider(i->provider->AsOmniboxEventProviderType()); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 921 | suggestion->set_result_type(AsOmniboxEventResultType(i->type)); |
| 922 | suggestion->set_relevance(i->relevance); |
[email protected] | cf6256f | 2012-06-12 23:36:01 | [diff] [blame] | 923 | if (i->typed_count != -1) |
| 924 | suggestion->set_typed_count(i->typed_count); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 925 | suggestion->set_is_starred(i->starred); |
| 926 | } |
[email protected] | 0e9e878 | 2012-05-15 23:01:51 | [diff] [blame] | 927 | for (ProvidersInfo::const_iterator i(log.providers_info.begin()); |
| 928 | i != log.providers_info.end(); ++i) { |
| 929 | OmniboxEventProto::ProviderInfo* provider_info = |
| 930 | omnibox_event->add_provider_info(); |
| 931 | provider_info->CopyFrom(*i); |
| 932 | } |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 933 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 934 | ++num_events_; |
| 935 | } |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 936 | |
| 937 | void MetricsLog::WriteGoogleUpdateProto( |
| 938 | const GoogleUpdateMetrics& google_update_metrics) { |
| 939 | #if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) |
| 940 | SystemProfileProto::GoogleUpdate* google_update = |
| 941 | uma_proto()->mutable_system_profile()->mutable_google_update(); |
| 942 | |
| 943 | google_update->set_is_system_install(google_update_metrics.is_system_install); |
| 944 | |
| 945 | if (!google_update_metrics.last_started_au.is_null()) { |
| 946 | google_update->set_last_automatic_start_timestamp( |
| 947 | google_update_metrics.last_started_au.ToTimeT()); |
| 948 | } |
| 949 | |
| 950 | if (!google_update_metrics.last_checked.is_null()) { |
| 951 | google_update->set_last_update_check_timestamp( |
| 952 | google_update_metrics.last_checked.ToTimeT()); |
| 953 | } |
| 954 | |
| 955 | if (!google_update_metrics.google_update_data.version.empty()) { |
| 956 | ProductDataToProto(google_update_metrics.google_update_data, |
| 957 | google_update->mutable_google_update_status()); |
| 958 | } |
| 959 | |
| 960 | if (!google_update_metrics.product_data.version.empty()) { |
| 961 | ProductDataToProto(google_update_metrics.product_data, |
| 962 | google_update->mutable_client_status()); |
| 963 | } |
| 964 | #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) |
| 965 | } |