[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] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 15 | #include "base/memory/scoped_ptr.h" |
[email protected] | 3853a4c | 2013-02-11 17:15:57 | [diff] [blame] | 16 | #include "base/prefs/pref_registry_simple.h" |
| 17 | #include "base/prefs/pref_service.h" |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 18 | #include "base/profiler/alternate_timer.h" |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 19 | #include "base/sha1.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" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 27 | #include "chrome/browser/browser_process.h" |
[email protected] | b84ee6e | 2014-03-15 22:51:54 | [diff] [blame] | 28 | #include "chrome/browser/metrics/extension_metrics.h" |
[email protected] | 0f5e57f5 | 2012-09-20 20:53:18 | [diff] [blame] | 29 | #include "chrome/browser/plugins/plugin_prefs.h" |
[email protected] | 1008498 | 2011-08-19 17:56:56 | [diff] [blame] | 30 | #include "chrome/browser/profiles/profile_manager.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 31 | #include "chrome/common/pref_names.h" |
[email protected] | 85791b0b | 2014-05-20 15:18:58 | [diff] [blame] | 32 | #include "components/metrics/metrics_provider.h" |
[email protected] | 09dee82d | 2014-05-22 14:00:53 | [diff] [blame^] | 33 | #include "components/metrics/metrics_service_client.h" |
[email protected] | 064107e | 2014-05-02 00:59:06 | [diff] [blame] | 34 | #include "components/metrics/proto/profiler_event.pb.h" |
| 35 | #include "components/metrics/proto/system_profile.pb.h" |
[email protected] | d5d38325 | 2013-07-04 14:44:32 | [diff] [blame] | 36 | #include "components/nacl/common/nacl_process_type.h" |
[email protected] | b3610d4 | 2014-05-19 18:07:23 | [diff] [blame] | 37 | #include "components/variations/active_field_trials.h" |
[email protected] | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 38 | #include "content/public/browser/gpu_data_manager.h" |
[email protected] | 1a838cc | 2012-04-24 22:06:49 | [diff] [blame] | 39 | #include "content/public/common/content_client.h" |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 40 | #include "content/public/common/webplugininfo.h" |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 41 | #include "gpu/config/gpu_info.h" |
[email protected] | 6b7d954ff | 2011-10-25 00:39:35 | [diff] [blame] | 42 | #include "ui/gfx/screen.h" |
[email protected] | 761fa470 | 2013-07-02 15:25:15 | [diff] [blame] | 43 | #include "url/gurl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 44 | |
[email protected] | 5106b3a | 2012-10-03 20:10:44 | [diff] [blame] | 45 | #if defined(OS_ANDROID) |
| 46 | #include "base/android/build_info.h" |
| 47 | #endif |
| 48 | |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 49 | #if defined(OS_WIN) |
[email protected] | 1bb25e0 | 2012-08-03 22:39:39 | [diff] [blame] | 50 | #include "base/win/metro.h" |
| 51 | |
| 52 | // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 53 | extern "C" IMAGE_DOS_HEADER __ImageBase; |
| 54 | #endif |
| 55 | |
[email protected] | afc03f0 | 2013-10-11 06:01:35 | [diff] [blame] | 56 | #if defined(OS_CHROMEOS) |
[email protected] | c9afed6e | 2014-02-03 22:12:29 | [diff] [blame] | 57 | #include "chrome/browser/metrics/metrics_log_chromeos.h" |
| 58 | #endif // OS_CHROMEOS |
[email protected] | afc03f0 | 2013-10-11 06:01:35 | [diff] [blame] | 59 | |
[email protected] | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 60 | using content::GpuDataManager; |
[email protected] | 064107e | 2014-05-02 00:59:06 | [diff] [blame] | 61 | using metrics::MetricsLogBase; |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 62 | using metrics::ProfilerEventProto; |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 63 | using metrics::SystemProfileProto; |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 64 | using tracked_objects::ProcessDataSnapshot; |
[email protected] | b3610d4 | 2014-05-19 18:07:23 | [diff] [blame] | 65 | typedef variations::ActiveGroupId ActiveGroupId; |
[email protected] | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 66 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 67 | namespace { |
| 68 | |
| 69 | // Returns the date at which the current metrics client ID was created as |
[email protected] | ca5ac4b | 2012-12-14 07:46:40 | [diff] [blame] | 70 | // a string containing seconds since the epoch, or "0" if none was found. |
[email protected] | cc5d7f4 | 2012-10-30 00:30:09 | [diff] [blame] | 71 | std::string GetMetricsEnabledDate(PrefService* pref) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 72 | if (!pref) { |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 73 | NOTREACHED(); |
| 74 | return "0"; |
| 75 | } |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 76 | |
[email protected] | 1f74e80 | 2014-03-29 03:08:35 | [diff] [blame] | 77 | return pref->GetString(prefs::kMetricsReportingEnabledTimestamp); |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 78 | } |
| 79 | |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 80 | ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType( |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 81 | int process_type) { |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 82 | switch (process_type) { |
| 83 | case content::PROCESS_TYPE_BROWSER: |
| 84 | return ProfilerEventProto::TrackedObject::BROWSER; |
| 85 | case content::PROCESS_TYPE_RENDERER: |
| 86 | return ProfilerEventProto::TrackedObject::RENDERER; |
| 87 | case content::PROCESS_TYPE_PLUGIN: |
| 88 | return ProfilerEventProto::TrackedObject::PLUGIN; |
| 89 | case content::PROCESS_TYPE_WORKER: |
| 90 | return ProfilerEventProto::TrackedObject::WORKER; |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 91 | case content::PROCESS_TYPE_UTILITY: |
| 92 | return ProfilerEventProto::TrackedObject::UTILITY; |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 93 | case content::PROCESS_TYPE_ZYGOTE: |
| 94 | return ProfilerEventProto::TrackedObject::ZYGOTE; |
| 95 | case content::PROCESS_TYPE_SANDBOX_HELPER: |
| 96 | return ProfilerEventProto::TrackedObject::SANDBOX_HELPER; |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 97 | case content::PROCESS_TYPE_GPU: |
| 98 | return ProfilerEventProto::TrackedObject::GPU; |
| 99 | case content::PROCESS_TYPE_PPAPI_PLUGIN: |
| 100 | return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN; |
| 101 | case content::PROCESS_TYPE_PPAPI_BROKER: |
| 102 | return ProfilerEventProto::TrackedObject::PPAPI_BROKER; |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 103 | case PROCESS_TYPE_NACL_LOADER: |
| 104 | return ProfilerEventProto::TrackedObject::NACL_LOADER; |
| 105 | case PROCESS_TYPE_NACL_BROKER: |
| 106 | return ProfilerEventProto::TrackedObject::NACL_BROKER; |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 107 | default: |
| 108 | NOTREACHED(); |
| 109 | return ProfilerEventProto::TrackedObject::UNKNOWN; |
| 110 | } |
| 111 | } |
| 112 | |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 113 | // Computes a SHA-1 hash of |data| and returns it as a hex string. |
| 114 | std::string ComputeSHA1(const std::string& data) { |
| 115 | const std::string sha1 = base::SHA1HashString(data); |
| 116 | return base::HexEncode(sha1.data(), sha1.size()); |
| 117 | } |
| 118 | |
[email protected] | 1d51882f | 2013-11-12 01:59:02 | [diff] [blame] | 119 | #if defined(ENABLE_PLUGINS) |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 120 | // Returns the plugin preferences corresponding for this user, if available. |
| 121 | // If multiple user profiles are loaded, returns the preferences corresponding |
| 122 | // to an arbitrary one of the profiles. |
| 123 | PluginPrefs* GetPluginPrefs() { |
| 124 | ProfileManager* profile_manager = g_browser_process->profile_manager(); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 125 | |
| 126 | if (!profile_manager) { |
| 127 | // The profile manager can be NULL when testing. |
| 128 | return NULL; |
| 129 | } |
| 130 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 131 | std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); |
| 132 | if (profiles.empty()) |
| 133 | return NULL; |
| 134 | |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 135 | return PluginPrefs::GetForProfile(profiles.front()).get(); |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 136 | } |
| 137 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 138 | // Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|. |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 139 | void SetPluginInfo(const content::WebPluginInfo& plugin_info, |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 140 | const PluginPrefs* plugin_prefs, |
| 141 | SystemProfileProto::Plugin* plugin) { |
[email protected] | 6778fed | 2013-12-24 20:09:37 | [diff] [blame] | 142 | plugin->set_name(base::UTF16ToUTF8(plugin_info.name)); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 143 | plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe()); |
[email protected] | 6778fed | 2013-12-24 20:09:37 | [diff] [blame] | 144 | plugin->set_version(base::UTF16ToUTF8(plugin_info.version)); |
[email protected] | 4e3ca1c29 | 2013-09-10 01:59:19 | [diff] [blame] | 145 | plugin->set_is_pepper(plugin_info.is_pepper_plugin()); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 146 | if (plugin_prefs) |
| 147 | plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info)); |
| 148 | } |
[email protected] | 1d51882f | 2013-11-12 01:59:02 | [diff] [blame] | 149 | #endif // defined(ENABLE_PLUGINS) |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 150 | |
[email protected] | 0c8b7ad | 2012-11-06 07:08:14 | [diff] [blame] | 151 | void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids, |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 152 | SystemProfileProto* system_profile) { |
[email protected] | 0c8b7ad | 2012-11-06 07:08:14 | [diff] [blame] | 153 | for (std::vector<ActiveGroupId>::const_iterator it = |
[email protected] | ad2461c | 2012-04-27 21:11:03 | [diff] [blame] | 154 | field_trial_ids.begin(); it != field_trial_ids.end(); ++it) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 155 | SystemProfileProto::FieldTrial* field_trial = |
| 156 | system_profile->add_field_trial(); |
| 157 | field_trial->set_name_id(it->name); |
| 158 | field_trial->set_group_id(it->group); |
| 159 | } |
| 160 | } |
| 161 | |
[email protected] | 0018f72 | 2014-02-08 03:08:51 | [diff] [blame] | 162 | // Maps a thread name by replacing trailing sequence of digits with "*". |
| 163 | // Examples: |
| 164 | // 1. "BrowserBlockingWorker1/23857" => "BrowserBlockingWorker1/*" |
| 165 | // 2. "Chrome_IOThread" => "Chrome_IOThread" |
| 166 | std::string MapThreadName(const std::string& thread_name) { |
| 167 | size_t i = thread_name.length(); |
| 168 | |
| 169 | while (i > 0 && isdigit(thread_name[i - 1])) { |
| 170 | --i; |
| 171 | } |
| 172 | |
| 173 | if (i == thread_name.length()) |
| 174 | return thread_name; |
| 175 | |
| 176 | return thread_name.substr(0, i) + '*'; |
| 177 | } |
| 178 | |
[email protected] | 87b9bf1 | 2014-04-03 15:25:00 | [diff] [blame] | 179 | // Normalizes a source filename (which is platform- and build-method-dependent) |
| 180 | // by extracting the last component of the full file name. |
| 181 | // Example: "c:\b\build\slave\win\build\src\chrome\app\chrome_main.cc" => |
| 182 | // "chrome_main.cc". |
| 183 | std::string NormalizeFileName(const std::string& file_name) { |
| 184 | const size_t offset = file_name.find_last_of("\\/"); |
| 185 | return offset != std::string::npos ? file_name.substr(offset + 1) : file_name; |
| 186 | } |
| 187 | |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 188 | void WriteProfilerData(const ProcessDataSnapshot& profiler_data, |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 189 | int process_type, |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 190 | ProfilerEventProto* performance_profile) { |
| 191 | for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it = |
| 192 | profiler_data.tasks.begin(); |
| 193 | it != profiler_data.tasks.end(); ++it) { |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 194 | const tracked_objects::DeathDataSnapshot& death_data = it->death_data; |
| 195 | ProfilerEventProto::TrackedObject* tracked_object = |
| 196 | performance_profile->add_tracked_object(); |
[email protected] | db7fec83 | 2013-07-18 09:41:41 | [diff] [blame] | 197 | tracked_object->set_birth_thread_name_hash( |
[email protected] | 0018f72 | 2014-02-08 03:08:51 | [diff] [blame] | 198 | MetricsLogBase::Hash(MapThreadName(it->birth.thread_name))); |
[email protected] | db7fec83 | 2013-07-18 09:41:41 | [diff] [blame] | 199 | tracked_object->set_exec_thread_name_hash( |
[email protected] | 0018f72 | 2014-02-08 03:08:51 | [diff] [blame] | 200 | MetricsLogBase::Hash(MapThreadName(it->death_thread_name))); |
[email protected] | db7fec83 | 2013-07-18 09:41:41 | [diff] [blame] | 201 | tracked_object->set_source_file_name_hash( |
[email protected] | 87b9bf1 | 2014-04-03 15:25:00 | [diff] [blame] | 202 | MetricsLogBase::Hash(NormalizeFileName(it->birth.location.file_name))); |
[email protected] | db7fec83 | 2013-07-18 09:41:41 | [diff] [blame] | 203 | tracked_object->set_source_function_name_hash( |
| 204 | MetricsLogBase::Hash(it->birth.location.function_name)); |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 205 | tracked_object->set_source_line_number(it->birth.location.line_number); |
| 206 | tracked_object->set_exec_count(death_data.count); |
| 207 | tracked_object->set_exec_time_total(death_data.run_duration_sum); |
| 208 | tracked_object->set_exec_time_sampled(death_data.run_duration_sample); |
| 209 | tracked_object->set_queue_time_total(death_data.queue_duration_sum); |
| 210 | tracked_object->set_queue_time_sampled(death_data.queue_duration_sample); |
| 211 | tracked_object->set_process_type(AsProtobufProcessType(process_type)); |
| 212 | tracked_object->set_process_id(profiler_data.process_id); |
| 213 | } |
| 214 | } |
| 215 | |
[email protected] | 76869ff | 2013-01-15 16:13:47 | [diff] [blame] | 216 | #if defined(OS_WIN) |
[email protected] | ffaf732 | 2013-05-15 00:26:11 | [diff] [blame] | 217 | struct ScreenDPIInformation { |
[email protected] | 76869ff | 2013-01-15 16:13:47 | [diff] [blame] | 218 | double max_dpi_x; |
| 219 | double max_dpi_y; |
| 220 | }; |
| 221 | |
| 222 | // Called once for each connected monitor. |
| 223 | BOOL CALLBACK GetMonitorDPICallback(HMONITOR, HDC hdc, LPRECT, LPARAM dwData) { |
| 224 | const double kMillimetersPerInch = 25.4; |
| 225 | ScreenDPIInformation* screen_info = |
| 226 | reinterpret_cast<ScreenDPIInformation*>(dwData); |
| 227 | // Size of screen, in mm. |
| 228 | DWORD size_x = GetDeviceCaps(hdc, HORZSIZE); |
| 229 | DWORD size_y = GetDeviceCaps(hdc, VERTSIZE); |
| 230 | double dpi_x = (size_x > 0) ? |
| 231 | GetDeviceCaps(hdc, HORZRES) / (size_x / kMillimetersPerInch) : 0; |
| 232 | double dpi_y = (size_y > 0) ? |
| 233 | GetDeviceCaps(hdc, VERTRES) / (size_y / kMillimetersPerInch) : 0; |
| 234 | screen_info->max_dpi_x = std::max(dpi_x, screen_info->max_dpi_x); |
| 235 | screen_info->max_dpi_y = std::max(dpi_y, screen_info->max_dpi_y); |
| 236 | return TRUE; |
| 237 | } |
| 238 | |
| 239 | void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) { |
| 240 | HDC desktop_dc = GetDC(NULL); |
| 241 | if (desktop_dc) { |
[email protected] | ffaf732 | 2013-05-15 00:26:11 | [diff] [blame] | 242 | ScreenDPIInformation si = {0, 0}; |
[email protected] | 76869ff | 2013-01-15 16:13:47 | [diff] [blame] | 243 | if (EnumDisplayMonitors(desktop_dc, NULL, GetMonitorDPICallback, |
| 244 | reinterpret_cast<LPARAM>(&si))) { |
| 245 | hardware->set_max_dpi_x(si.max_dpi_x); |
| 246 | hardware->set_max_dpi_y(si.max_dpi_y); |
| 247 | } |
| 248 | ReleaseDC(GetDesktopWindow(), desktop_dc); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | #endif // defined(OS_WIN) |
| 253 | |
[email protected] | 86573d1 | 2013-07-11 19:48:32 | [diff] [blame] | 254 | // Round a timestamp measured in seconds since epoch to one with a granularity |
| 255 | // of an hour. This can be used before uploaded potentially sensitive |
| 256 | // timestamps. |
| 257 | int64 RoundSecondsToHour(int64 time_in_seconds) { |
| 258 | return 3600 * (time_in_seconds / 3600); |
| 259 | } |
| 260 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 261 | } // namespace |
| 262 | |
[email protected] | 9eae403 | 2014-04-09 19:15:19 | [diff] [blame] | 263 | MetricsLog::MetricsLog(const std::string& client_id, |
| 264 | int session_id, |
[email protected] | 09dee82d | 2014-05-22 14:00:53 | [diff] [blame^] | 265 | LogType log_type, |
| 266 | metrics::MetricsServiceClient* client) |
| 267 | : MetricsLogBase(client_id, |
| 268 | session_id, |
| 269 | log_type, |
| 270 | client->GetVersionString()), |
| 271 | client_(client), |
[email protected] | b84ee6e | 2014-03-15 22:51:54 | [diff] [blame] | 272 | creation_time_(base::TimeTicks::Now()), |
| 273 | extension_metrics_(uma_proto()->client_id()) { |
[email protected] | 09dee82d | 2014-05-22 14:00:53 | [diff] [blame^] | 274 | uma_proto()->mutable_system_profile()->set_channel(client_->GetChannel()); |
[email protected] | 064107e | 2014-05-02 00:59:06 | [diff] [blame] | 275 | |
[email protected] | afc03f0 | 2013-10-11 06:01:35 | [diff] [blame] | 276 | #if defined(OS_CHROMEOS) |
[email protected] | c9afed6e | 2014-02-03 22:12:29 | [diff] [blame] | 277 | metrics_log_chromeos_.reset(new MetricsLogChromeOS(uma_proto())); |
| 278 | #endif // OS_CHROMEOS |
[email protected] | afc03f0 | 2013-10-11 06:01:35 | [diff] [blame] | 279 | } |
[email protected] | 5ed7d457 | 2009-12-23 17:42:41 | [diff] [blame] | 280 | |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 281 | MetricsLog::~MetricsLog() {} |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 282 | |
| 283 | // static |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 284 | void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) { |
| 285 | registry->RegisterListPref(prefs::kStabilityPluginStats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 286 | } |
| 287 | |
[email protected] | 85791b0b | 2014-05-20 15:18:58 | [diff] [blame] | 288 | void MetricsLog::RecordStabilityMetrics( |
| 289 | const std::vector<metrics::MetricsProvider*>& metrics_providers, |
| 290 | base::TimeDelta incremental_uptime, |
| 291 | base::TimeDelta uptime) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 292 | DCHECK(!locked()); |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 293 | DCHECK(HasEnvironment()); |
| 294 | DCHECK(!HasStabilityMetrics()); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 295 | |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 296 | PrefService* pref = GetPrefService(); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 297 | DCHECK(pref); |
| 298 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 299 | // Get stability attributes out of Local State, zeroing out stored values. |
| 300 | // NOTE: This could lead to some data loss if this report isn't successfully |
| 301 | // sent, but that's true for all the metrics. |
| 302 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 303 | WriteRequiredStabilityAttributes(pref); |
[email protected] | 250f7b66 | 2013-11-23 02:36:51 | [diff] [blame] | 304 | WritePluginStabilityElements(pref); |
[email protected] | 0edf876 | 2013-11-21 18:33:30 | [diff] [blame] | 305 | |
| 306 | // Record recent delta for critical stability metrics. We can't wait for a |
| 307 | // restart to gather these, as that delay biases our observation away from |
| 308 | // users that run happily for a looooong time. We send increments with each |
| 309 | // uma log upload, just as we send histogram data. |
[email protected] | 076961c | 2014-03-12 22:23:56 | [diff] [blame] | 310 | WriteRealtimeStabilityAttributes(pref, incremental_uptime, uptime); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 311 | |
[email protected] | 85791b0b | 2014-05-20 15:18:58 | [diff] [blame] | 312 | SystemProfileProto::Stability* stability = |
| 313 | uma_proto()->mutable_system_profile()->mutable_stability(); |
| 314 | for (size_t i = 0; i < metrics_providers.size(); ++i) |
| 315 | metrics_providers[i]->ProvideStabilityMetrics(stability); |
| 316 | |
[email protected] | 0edf876 | 2013-11-21 18:33:30 | [diff] [blame] | 317 | // Omit some stats unless this is the initial stability log. |
[email protected] | 9eae403 | 2014-04-09 19:15:19 | [diff] [blame] | 318 | if (log_type() != INITIAL_STABILITY_LOG) |
[email protected] | 0edf876 | 2013-11-21 18:33:30 | [diff] [blame] | 319 | return; |
| 320 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 321 | int incomplete_shutdown_count = |
| 322 | pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount); |
[email protected] | e324f6b | 2012-02-28 05:43:37 | [diff] [blame] | 323 | pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 324 | int breakpad_registration_success_count = |
| 325 | pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess); |
[email protected] | e324f6b | 2012-02-28 05:43:37 | [diff] [blame] | 326 | pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 327 | int breakpad_registration_failure_count = |
| 328 | pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail); |
[email protected] | e324f6b | 2012-02-28 05:43:37 | [diff] [blame] | 329 | pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 330 | int debugger_present_count = |
| 331 | pref->GetInteger(prefs::kStabilityDebuggerPresent); |
[email protected] | e324f6b | 2012-02-28 05:43:37 | [diff] [blame] | 332 | pref->SetInteger(prefs::kStabilityDebuggerPresent, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 333 | int debugger_not_present_count = |
| 334 | pref->GetInteger(prefs::kStabilityDebuggerNotPresent); |
[email protected] | e324f6b | 2012-02-28 05:43:37 | [diff] [blame] | 335 | pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); |
[email protected] | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 336 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 337 | // TODO(jar): The following are all optional, so we *could* optimize them for |
| 338 | // values of zero (and not include them). |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 339 | stability->set_incomplete_shutdown_count(incomplete_shutdown_count); |
| 340 | stability->set_breakpad_registration_success_count( |
| 341 | breakpad_registration_success_count); |
| 342 | stability->set_breakpad_registration_failure_count( |
| 343 | breakpad_registration_failure_count); |
| 344 | stability->set_debugger_present_count(debugger_present_count); |
| 345 | stability->set_debugger_not_present_count(debugger_not_present_count); |
[email protected] | 0edf876 | 2013-11-21 18:33:30 | [diff] [blame] | 346 | } |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 347 | |
[email protected] | 85791b0b | 2014-05-20 15:18:58 | [diff] [blame] | 348 | void MetricsLog::RecordGeneralMetrics( |
| 349 | const std::vector<metrics::MetricsProvider*>& metrics_providers) { |
| 350 | for (size_t i = 0; i < metrics_providers.size(); ++i) |
| 351 | metrics_providers[i]->ProvideGeneralMetrics(uma_proto()); |
| 352 | } |
| 353 | |
[email protected] | 0edf876 | 2013-11-21 18:33:30 | [diff] [blame] | 354 | PrefService* MetricsLog::GetPrefService() { |
| 355 | return g_browser_process->local_state(); |
| 356 | } |
| 357 | |
| 358 | gfx::Size MetricsLog::GetScreenSize() const { |
| 359 | return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel(); |
| 360 | } |
| 361 | |
| 362 | float MetricsLog::GetScreenDeviceScaleFactor() const { |
| 363 | return gfx::Screen::GetNativeScreen()-> |
| 364 | GetPrimaryDisplay().device_scale_factor(); |
| 365 | } |
| 366 | |
| 367 | int MetricsLog::GetScreenCount() const { |
| 368 | // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312 |
| 369 | return gfx::Screen::GetNativeScreen()->GetNumDisplays(); |
| 370 | } |
| 371 | |
| 372 | void MetricsLog::GetFieldTrialIds( |
| 373 | std::vector<ActiveGroupId>* field_trial_ids) const { |
[email protected] | b3610d4 | 2014-05-19 18:07:23 | [diff] [blame] | 374 | variations::GetFieldTrialActiveGroupIds(field_trial_ids); |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 375 | } |
| 376 | |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 377 | bool MetricsLog::HasEnvironment() const { |
| 378 | return uma_proto()->system_profile().has_uma_enabled_date(); |
| 379 | } |
| 380 | |
| 381 | bool MetricsLog::HasStabilityMetrics() const { |
| 382 | return uma_proto()->system_profile().stability().has_launch_count(); |
| 383 | } |
| 384 | |
[email protected] | 250f7b66 | 2013-11-23 02:36:51 | [diff] [blame] | 385 | void MetricsLog::WritePluginStabilityElements(PrefService* pref) { |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 386 | // Now log plugin stability info. |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 387 | const base::ListValue* plugin_stats_list = pref->GetList( |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 388 | prefs::kStabilityPluginStats); |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 389 | if (!plugin_stats_list) |
| 390 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 391 | |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 392 | #if defined(ENABLE_PLUGINS) |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 393 | SystemProfileProto::Stability* stability = |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 394 | uma_proto()->mutable_system_profile()->mutable_stability(); |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 395 | for (base::ListValue::const_iterator iter = plugin_stats_list->begin(); |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 396 | iter != plugin_stats_list->end(); ++iter) { |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 397 | if (!(*iter)->IsType(base::Value::TYPE_DICTIONARY)) { |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 398 | NOTREACHED(); |
| 399 | continue; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 400 | } |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 401 | base::DictionaryValue* plugin_dict = |
| 402 | static_cast<base::DictionaryValue*>(*iter); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 403 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 404 | // Note that this search is potentially a quadratic operation, but given the |
| 405 | // low number of plugins installed on a "reasonable" setup, this should be |
| 406 | // fine. |
| 407 | // TODO(isherman): Verify that this does not show up as a hotspot in |
| 408 | // profiler runs. |
[email protected] | 250f7b66 | 2013-11-23 02:36:51 | [diff] [blame] | 409 | const SystemProfileProto::Plugin* system_profile_plugin = NULL; |
[email protected] | f31a01a | 2013-07-13 02:51:11 | [diff] [blame] | 410 | std::string plugin_name; |
| 411 | plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name); |
[email protected] | 250f7b66 | 2013-11-23 02:36:51 | [diff] [blame] | 412 | const SystemProfileProto& system_profile = uma_proto()->system_profile(); |
| 413 | for (int i = 0; i < system_profile.plugin_size(); ++i) { |
| 414 | if (system_profile.plugin(i).name() == plugin_name) { |
| 415 | system_profile_plugin = &system_profile.plugin(i); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 416 | break; |
| 417 | } |
| 418 | } |
| 419 | |
[email protected] | 250f7b66 | 2013-11-23 02:36:51 | [diff] [blame] | 420 | if (!system_profile_plugin) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 421 | NOTREACHED(); |
| 422 | continue; |
| 423 | } |
| 424 | |
| 425 | SystemProfileProto::Stability::PluginStability* plugin_stability = |
| 426 | stability->add_plugin_stability(); |
[email protected] | 250f7b66 | 2013-11-23 02:36:51 | [diff] [blame] | 427 | *plugin_stability->mutable_plugin() = *system_profile_plugin; |
[email protected] | f31a01a | 2013-07-13 02:51:11 | [diff] [blame] | 428 | |
| 429 | int launches = 0; |
| 430 | plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches); |
| 431 | if (launches > 0) |
| 432 | plugin_stability->set_launch_count(launches); |
| 433 | |
| 434 | int instances = 0; |
| 435 | plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances); |
| 436 | if (instances > 0) |
| 437 | plugin_stability->set_instance_count(instances); |
| 438 | |
| 439 | int crashes = 0; |
| 440 | plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes); |
| 441 | if (crashes > 0) |
| 442 | plugin_stability->set_crash_count(crashes); |
| 443 | |
| 444 | int loading_errors = 0; |
| 445 | plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors, |
| 446 | &loading_errors); |
| 447 | if (loading_errors > 0) |
| 448 | plugin_stability->set_loading_error_count(loading_errors); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 449 | } |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 450 | #endif // defined(ENABLE_PLUGINS) |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 451 | |
| 452 | pref->ClearPref(prefs::kStabilityPluginStats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 453 | } |
| 454 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 455 | // The server refuses data that doesn't have certain values. crashcount and |
| 456 | // launchcount are currently "required" in the "stability" group. |
| 457 | // TODO(isherman): Stop writing these attributes specially once the migration to |
| 458 | // protobufs is complete. |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 459 | void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 460 | int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 461 | pref->SetInteger(prefs::kStabilityLaunchCount, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 462 | int crash_count = pref->GetInteger(prefs::kStabilityCrashCount); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 463 | pref->SetInteger(prefs::kStabilityCrashCount, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 464 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 465 | SystemProfileProto::Stability* stability = |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 466 | uma_proto()->mutable_system_profile()->mutable_stability(); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 467 | stability->set_launch_count(launch_count); |
| 468 | stability->set_crash_count(crash_count); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 469 | } |
| 470 | |
[email protected] | c68a2b9b | 2013-10-09 18:16:36 | [diff] [blame] | 471 | void MetricsLog::WriteRealtimeStabilityAttributes( |
| 472 | PrefService* pref, |
[email protected] | 076961c | 2014-03-12 22:23:56 | [diff] [blame] | 473 | base::TimeDelta incremental_uptime, |
| 474 | base::TimeDelta uptime) { |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 475 | // Update the stats which are critical for real-time stability monitoring. |
| 476 | // 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] | 477 | // are aggregated (summed) server side. |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 478 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 479 | SystemProfileProto::Stability* stability = |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 480 | uma_proto()->mutable_system_profile()->mutable_stability(); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 481 | int count = pref->GetInteger(prefs::kStabilityPageLoadCount); |
| 482 | if (count) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 483 | stability->set_page_load_count(count); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 484 | pref->SetInteger(prefs::kStabilityPageLoadCount, 0); |
| 485 | } |
| 486 | |
| 487 | count = pref->GetInteger(prefs::kStabilityRendererCrashCount); |
| 488 | if (count) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 489 | stability->set_renderer_crash_count(count); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 490 | pref->SetInteger(prefs::kStabilityRendererCrashCount, 0); |
| 491 | } |
| 492 | |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 493 | count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount); |
| 494 | if (count) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 495 | stability->set_extension_renderer_crash_count(count); |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 496 | pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0); |
| 497 | } |
| 498 | |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 499 | count = pref->GetInteger(prefs::kStabilityRendererHangCount); |
| 500 | if (count) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 501 | stability->set_renderer_hang_count(count); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 502 | pref->SetInteger(prefs::kStabilityRendererHangCount, 0); |
| 503 | } |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 504 | |
| 505 | count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount); |
| 506 | if (count) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 507 | stability->set_child_process_crash_count(count); |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 508 | pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); |
| 509 | } |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 510 | |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 511 | #if defined(OS_CHROMEOS) |
[email protected] | c9afed6e | 2014-02-03 22:12:29 | [diff] [blame] | 512 | metrics_log_chromeos_->WriteRealtimeStabilityAttributes(pref); |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 513 | #endif // OS_CHROMEOS |
| 514 | |
[email protected] | 076961c | 2014-03-12 22:23:56 | [diff] [blame] | 515 | const uint64 incremental_uptime_sec = incremental_uptime.InSeconds(); |
| 516 | if (incremental_uptime_sec) |
| 517 | stability->set_incremental_uptime_sec(incremental_uptime_sec); |
| 518 | const uint64 uptime_sec = uptime.InSeconds(); |
[email protected] | c68a2b9b | 2013-10-09 18:16:36 | [diff] [blame] | 519 | if (uptime_sec) |
| 520 | stability->set_uptime_sec(uptime_sec); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 521 | } |
| 522 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 523 | void MetricsLog::WritePluginList( |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 524 | const std::vector<content::WebPluginInfo>& plugin_list) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 525 | DCHECK(!locked()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 526 | |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 527 | #if defined(ENABLE_PLUGINS) |
| 528 | PluginPrefs* plugin_prefs = GetPluginPrefs(); |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 529 | SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 530 | for (std::vector<content::WebPluginInfo>::const_iterator iter = |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 531 | plugin_list.begin(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 532 | iter != plugin_list.end(); ++iter) { |
[email protected] | 0eecc254 | 2013-06-23 04:22:02 | [diff] [blame] | 533 | SystemProfileProto::Plugin* plugin = system_profile->add_plugin(); |
| 534 | SetPluginInfo(*iter, plugin_prefs, plugin); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 535 | } |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 536 | #endif // defined(ENABLE_PLUGINS) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | void MetricsLog::RecordEnvironment( |
[email protected] | 85791b0b | 2014-05-20 15:18:58 | [diff] [blame] | 540 | const std::vector<metrics::MetricsProvider*>& metrics_providers, |
[email protected] | c68a2b9b | 2013-10-09 18:16:36 | [diff] [blame] | 541 | const std::vector<content::WebPluginInfo>& plugin_list, |
[email protected] | b3610d4 | 2014-05-19 18:07:23 | [diff] [blame] | 542 | const std::vector<variations::ActiveGroupId>& synthetic_trials) { |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 543 | DCHECK(!HasEnvironment()); |
| 544 | |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 545 | SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
[email protected] | 24b9bb39 | 2013-01-29 20:29:29 | [diff] [blame] | 546 | |
| 547 | std::string brand_code; |
[email protected] | 09dee82d | 2014-05-22 14:00:53 | [diff] [blame^] | 548 | if (client_->GetBrand(&brand_code)) |
[email protected] | 24b9bb39 | 2013-01-29 20:29:29 | [diff] [blame] | 549 | system_profile->set_brand_code(brand_code); |
| 550 | |
[email protected] | cc5d7f4 | 2012-10-30 00:30:09 | [diff] [blame] | 551 | int enabled_date; |
| 552 | bool success = base::StringToInt(GetMetricsEnabledDate(GetPrefService()), |
| 553 | &enabled_date); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 554 | DCHECK(success); |
[email protected] | 86573d1 | 2013-07-11 19:48:32 | [diff] [blame] | 555 | |
| 556 | // Reduce granularity of the enabled_date field to nearest hour. |
| 557 | system_profile->set_uma_enabled_date(RoundSecondsToHour(enabled_date)); |
| 558 | |
| 559 | int64 install_date = GetPrefService()->GetInt64(prefs::kInstallDate); |
| 560 | |
| 561 | // Reduce granularity of the install_date field to nearest hour. |
| 562 | system_profile->set_install_date(RoundSecondsToHour(install_date)); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 563 | |
[email protected] | 09dee82d | 2014-05-22 14:00:53 | [diff] [blame^] | 564 | system_profile->set_application_locale(client_->GetApplicationLocale()); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 565 | |
| 566 | SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware(); |
[email protected] | 0b6a4fb | 2012-10-16 01:58:21 | [diff] [blame] | 567 | hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture()); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 568 | hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB()); |
| 569 | #if defined(OS_WIN) |
| 570 | hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase)); |
| 571 | #endif |
| 572 | |
[email protected] | 74b299e | 2013-01-29 01:24:42 | [diff] [blame] | 573 | SystemProfileProto::Network* network = system_profile->mutable_network(); |
| 574 | network->set_connection_type_is_ambiguous( |
[email protected] | 5eae204c | 2013-02-13 15:53:42 | [diff] [blame] | 575 | network_observer_.connection_type_is_ambiguous()); |
| 576 | network->set_connection_type(network_observer_.connection_type()); |
| 577 | network->set_wifi_phy_layer_protocol_is_ambiguous( |
| 578 | network_observer_.wifi_phy_layer_protocol_is_ambiguous()); |
| 579 | network->set_wifi_phy_layer_protocol( |
| 580 | network_observer_.wifi_phy_layer_protocol()); |
| 581 | network_observer_.Reset(); |
[email protected] | 74b299e | 2013-01-29 01:24:42 | [diff] [blame] | 582 | |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 583 | SystemProfileProto::OS* os = system_profile->mutable_os(); |
[email protected] | 1bb25e0 | 2012-08-03 22:39:39 | [diff] [blame] | 584 | std::string os_name = base::SysInfo::OperatingSystemName(); |
| 585 | #if defined(OS_WIN) |
| 586 | // TODO(mad): This only checks whether the main process is a Metro process at |
| 587 | // upload time; not whether the collected metrics were all gathered from |
| 588 | // Metro. This is ok as an approximation for now, since users will rarely be |
| 589 | // switching from Metro to Desktop mode; but we should re-evaluate whether we |
| 590 | // can distinguish metrics more cleanly in the future: http://crbug.com/140568 |
| 591 | if (base::win::IsMetroProcess()) |
| 592 | os_name += " (Metro)"; |
| 593 | #endif |
| 594 | os->set_name(os_name); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 595 | os->set_version(base::SysInfo::OperatingSystemVersion()); |
[email protected] | 5106b3a | 2012-10-03 20:10:44 | [diff] [blame] | 596 | #if defined(OS_ANDROID) |
| 597 | os->set_fingerprint( |
| 598 | base::android::BuildInfo::GetInstance()->android_build_fp()); |
| 599 | #endif |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 600 | |
[email protected] | 5c8f89f69 | 2013-07-18 11:13:28 | [diff] [blame] | 601 | base::CPU cpu_info; |
| 602 | SystemProfileProto::Hardware::CPU* cpu = hardware->mutable_cpu(); |
| 603 | cpu->set_vendor_name(cpu_info.vendor_name()); |
| 604 | cpu->set_signature(cpu_info.signature()); |
| 605 | |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 606 | const gpu::GPUInfo& gpu_info = |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 607 | GpuDataManager::GetInstance()->GetGPUInfo(); |
| 608 | SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu(); |
[email protected] | a094e2c | 2012-05-10 23:02:42 | [diff] [blame] | 609 | gpu->set_vendor_id(gpu_info.gpu.vendor_id); |
| 610 | gpu->set_device_id(gpu_info.gpu.device_id); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 611 | gpu->set_driver_version(gpu_info.driver_version); |
| 612 | gpu->set_driver_date(gpu_info.driver_date); |
| 613 | SystemProfileProto::Hardware::Graphics::PerformanceStatistics* |
| 614 | gpu_performance = gpu->mutable_performance_statistics(); |
| 615 | gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics); |
| 616 | gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming); |
| 617 | gpu_performance->set_overall_score(gpu_info.performance_stats.overall); |
[email protected] | d6bdfae | 2013-01-18 20:23:01 | [diff] [blame] | 618 | gpu->set_gl_vendor(gpu_info.gl_vendor); |
| 619 | gpu->set_gl_renderer(gpu_info.gl_renderer); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 620 | |
| 621 | const gfx::Size display_size = GetScreenSize(); |
| 622 | hardware->set_primary_screen_width(display_size.width()); |
| 623 | hardware->set_primary_screen_height(display_size.height()); |
[email protected] | aa9641797 | 2012-08-22 03:16:44 | [diff] [blame] | 624 | hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor()); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 625 | hardware->set_screen_count(GetScreenCount()); |
| 626 | |
[email protected] | 76869ff | 2013-01-15 16:13:47 | [diff] [blame] | 627 | #if defined(OS_WIN) |
| 628 | WriteScreenDPIInformationProto(hardware); |
| 629 | #endif |
| 630 | |
[email protected] | 0eecc254 | 2013-06-23 04:22:02 | [diff] [blame] | 631 | WritePluginList(plugin_list); |
[email protected] | b84ee6e | 2014-03-15 22:51:54 | [diff] [blame] | 632 | extension_metrics_.WriteExtensionList(uma_proto()->mutable_system_profile()); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 633 | |
[email protected] | 0c8b7ad | 2012-11-06 07:08:14 | [diff] [blame] | 634 | std::vector<ActiveGroupId> field_trial_ids; |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 635 | GetFieldTrialIds(&field_trial_ids); |
| 636 | WriteFieldTrials(field_trial_ids, system_profile); |
[email protected] | 6067756 | 2013-11-17 15:52:55 | [diff] [blame] | 637 | WriteFieldTrials(synthetic_trials, system_profile); |
[email protected] | f65859e | 2013-02-04 20:00:25 | [diff] [blame] | 638 | |
| 639 | #if defined(OS_CHROMEOS) |
[email protected] | c9afed6e | 2014-02-03 22:12:29 | [diff] [blame] | 640 | metrics_log_chromeos_->LogChromeOSMetrics(); |
| 641 | #endif // OS_CHROMEOS |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 642 | |
[email protected] | 85791b0b | 2014-05-20 15:18:58 | [diff] [blame] | 643 | for (size_t i = 0; i < metrics_providers.size(); ++i) |
| 644 | metrics_providers[i]->ProvideSystemProfileMetrics(system_profile); |
| 645 | |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 646 | std::string serialied_system_profile; |
| 647 | std::string base64_system_profile; |
[email protected] | 33fca12 | 2013-12-11 01:48:50 | [diff] [blame] | 648 | if (system_profile->SerializeToString(&serialied_system_profile)) { |
| 649 | base::Base64Encode(serialied_system_profile, &base64_system_profile); |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 650 | PrefService* local_state = GetPrefService(); |
| 651 | local_state->SetString(prefs::kStabilitySavedSystemProfile, |
| 652 | base64_system_profile); |
| 653 | local_state->SetString(prefs::kStabilitySavedSystemProfileHash, |
| 654 | ComputeSHA1(serialied_system_profile)); |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | bool MetricsLog::LoadSavedEnvironmentFromPrefs() { |
| 659 | PrefService* local_state = GetPrefService(); |
| 660 | const std::string base64_system_profile = |
| 661 | local_state->GetString(prefs::kStabilitySavedSystemProfile); |
| 662 | if (base64_system_profile.empty()) |
| 663 | return false; |
| 664 | |
| 665 | const std::string system_profile_hash = |
| 666 | local_state->GetString(prefs::kStabilitySavedSystemProfileHash); |
| 667 | local_state->ClearPref(prefs::kStabilitySavedSystemProfile); |
| 668 | local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash); |
| 669 | |
| 670 | SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
| 671 | std::string serialied_system_profile; |
| 672 | return base::Base64Decode(base64_system_profile, &serialied_system_profile) && |
| 673 | ComputeSHA1(serialied_system_profile) == system_profile_hash && |
| 674 | system_profile->ParseFromString(serialied_system_profile); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 675 | } |
| 676 | |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 677 | void MetricsLog::RecordProfilerData( |
| 678 | const tracked_objects::ProcessDataSnapshot& process_data, |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 679 | int process_type) { |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 680 | DCHECK(!locked()); |
| 681 | |
[email protected] | 8f82968 | 2012-04-27 00:36:49 | [diff] [blame] | 682 | if (tracked_objects::GetTimeSourceType() != |
| 683 | tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) { |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 684 | // We currently only support the default time source, wall clock time. |
| 685 | return; |
| 686 | } |
| 687 | |
| 688 | ProfilerEventProto* profile; |
| 689 | if (!uma_proto()->profiler_event_size()) { |
| 690 | // For the first process's data, add a new field to the protocol buffer. |
| 691 | profile = uma_proto()->add_profiler_event(); |
| 692 | profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE); |
| 693 | profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME); |
| 694 | } else { |
| 695 | // For the remaining calls, re-use the existing field. |
| 696 | profile = uma_proto()->mutable_profiler_event(0); |
| 697 | } |
| 698 | |
| 699 | WriteProfilerData(process_data, process_type, profile); |
| 700 | } |