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