blob: eb8f9d2e53614f832bea0e79dd1aea538fd09d05 [file] [log] [blame]
[email protected]1df44b72012-01-19 05:20:341// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]cd1adc22009-01-16 01:29:225#include "chrome/browser/metrics/metrics_log.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]76869ff2013-01-15 16:13:477#include <algorithm>
[email protected]1eeb5e02010-07-20 23:02:118#include <string>
9#include <vector>
10
[email protected]0f2f7792013-11-28 16:09:1411#include "base/base64.h"
[email protected]d1be67b2008-11-19 20:28:3812#include "base/basictypes.h"
[email protected]611ae29a2013-04-29 21:32:1913#include "base/bind.h"
[email protected]5c8f89f692013-07-18 11:13:2814#include "base/cpu.h"
[email protected]054c8012011-11-16 00:12:4215#include "base/lazy_instance.h"
[email protected]3b63f8f42011-03-28 01:54:1516#include "base/memory/scoped_ptr.h"
[email protected]3853a4c2013-02-11 17:15:5717#include "base/prefs/pref_registry_simple.h"
18#include "base/prefs/pref_service.h"
[email protected]ed0fd002012-04-25 23:10:3419#include "base/profiler/alternate_timer.h"
[email protected]0f2f7792013-11-28 16:09:1420#include "base/sha1.h"
[email protected]3ea1b182013-02-08 22:38:4121#include "base/strings/string_number_conversions.h"
[email protected]f9b294362013-06-10 20:22:3122#include "base/strings/string_util.h"
[email protected]112158af2013-06-07 23:46:1823#include "base/strings/utf_string_conversions.h"
[email protected]fadf97f2008-09-18 12:18:1424#include "base/sys_info.h"
[email protected]37f39e42010-01-06 17:35:1725#include "base/third_party/nspr/prtime.h"
[email protected]84813472013-06-28 00:25:1926#include "base/time/time.h"
[email protected]ed0fd002012-04-25 23:10:3427#include "base/tracked_objects.h"
[email protected]9f8bc2f2012-07-03 16:26:5328#include "chrome/browser/autocomplete/autocomplete_input.h"
[email protected]9ac40092010-10-27 23:05:2629#include "chrome/browser/autocomplete/autocomplete_match.h"
[email protected]30f5bc92012-06-26 04:14:5530#include "chrome/browser/autocomplete/autocomplete_provider.h"
[email protected]73c2b1632012-07-02 22:51:3831#include "chrome/browser/autocomplete/autocomplete_result.h"
initial.commit09911bf2008-07-26 23:55:2932#include "chrome/browser/browser_process.h"
[email protected]24b9bb392013-01-29 20:29:2933#include "chrome/browser/google/google_util.h"
[email protected]b84ee6e2014-03-15 22:51:5434#include "chrome/browser/metrics/extension_metrics.h"
[email protected]0fafc8d2013-06-01 00:09:5035#include "chrome/browser/omnibox/omnibox_log.h"
[email protected]0f5e57f52012-09-20 20:53:1836#include "chrome/browser/plugins/plugin_prefs.h"
[email protected]10084982011-08-19 17:56:5637#include "chrome/browser/profiles/profile_manager.h"
[email protected]1eeb5e02010-07-20 23:02:1138#include "chrome/common/chrome_version_info.h"
initial.commit09911bf2008-07-26 23:55:2939#include "chrome/common/logging_chrome.h"
[email protected]fe58acc22012-02-29 01:29:5840#include "chrome/common/metrics/proto/omnibox_event.pb.h"
[email protected]ed0fd002012-04-25 23:10:3441#include "chrome/common/metrics/proto/profiler_event.pb.h"
[email protected]fe58acc22012-02-29 01:29:5842#include "chrome/common/metrics/proto/system_profile.pb.h"
[email protected]cf265dc02012-08-15 01:01:1643#include "chrome/common/metrics/variations/variations_util.h"
initial.commit09911bf2008-07-26 23:55:2944#include "chrome/common/pref_names.h"
[email protected]197c0772012-05-14 23:50:5145#include "chrome/installer/util/google_update_settings.h"
[email protected]d5d383252013-07-04 14:44:3246#include "components/nacl/common/nacl_process_type.h"
[email protected]79078df2012-02-16 01:22:3247#include "content/public/browser/gpu_data_manager.h"
[email protected]1a838cc2012-04-24 22:06:4948#include "content/public/common/content_client.h"
[email protected]d7bd3e52013-07-21 04:29:2049#include "content/public/common/webplugininfo.h"
[email protected]d7b5cc72013-05-23 20:05:0050#include "gpu/config/gpu_info.h"
[email protected]6b7d954ff2011-10-25 00:39:3551#include "ui/gfx/screen.h"
[email protected]761fa4702013-07-02 15:25:1552#include "url/gurl.h"
initial.commit09911bf2008-07-26 23:55:2953
[email protected]5106b3a2012-10-03 20:10:4454#if defined(OS_ANDROID)
55#include "base/android/build_info.h"
56#endif
57
[email protected]d1be67b2008-11-19 20:28:3858#if defined(OS_WIN)
[email protected]1bb25e02012-08-03 22:39:3959#include "base/win/metro.h"
60
61// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
[email protected]d1be67b2008-11-19 20:28:3862extern "C" IMAGE_DOS_HEADER __ImageBase;
63#endif
64
[email protected]afc03f02013-10-11 06:01:3565#if defined(OS_CHROMEOS)
[email protected]c9afed6e2014-02-03 22:12:2966#include "chrome/browser/metrics/metrics_log_chromeos.h"
67#endif // OS_CHROMEOS
[email protected]afc03f02013-10-11 06:01:3568
[email protected]79078df2012-02-16 01:22:3269using content::GpuDataManager;
[email protected]fe58acc22012-02-29 01:29:5870using metrics::OmniboxEventProto;
[email protected]ed0fd002012-04-25 23:10:3471using metrics::ProfilerEventProto;
[email protected]fe58acc22012-02-29 01:29:5872using metrics::SystemProfileProto;
[email protected]ed0fd002012-04-25 23:10:3473using tracked_objects::ProcessDataSnapshot;
[email protected]0c8b7ad2012-11-06 07:08:1474typedef chrome_variations::ActiveGroupId ActiveGroupId;
[email protected]197c0772012-05-14 23:50:5175typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo;
[email protected]79078df2012-02-16 01:22:3276
[email protected]1df44b72012-01-19 05:20:3477namespace {
78
79// Returns the date at which the current metrics client ID was created as
[email protected]ca5ac4b2012-12-14 07:46:4080// a string containing seconds since the epoch, or "0" if none was found.
[email protected]cc5d7f42012-10-30 00:30:0981std::string GetMetricsEnabledDate(PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:3482 if (!pref) {
[email protected]1df44b72012-01-19 05:20:3483 NOTREACHED();
84 return "0";
85 }
[email protected]767c9d92012-03-02 16:04:3486
[email protected]1f74e802014-03-29 03:08:3587 return pref->GetString(prefs::kMetricsReportingEnabledTimestamp);
[email protected]1df44b72012-01-19 05:20:3488}
89
[email protected]fe58acc22012-02-29 01:29:5890OmniboxEventProto::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]fe58acc22012-02-29 01:29:5897 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]fe58acc22012-02-29 01:29:58109OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
110 AutocompleteMatch::Type type) {
111 switch (type) {
[email protected]b7f64d742013-05-21 04:04:04112 case AutocompleteMatchType::URL_WHAT_YOU_TYPED:
[email protected]fe58acc22012-02-29 01:29:58113 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
[email protected]b7f64d742013-05-21 04:04:04114 case AutocompleteMatchType::HISTORY_URL:
[email protected]fe58acc22012-02-29 01:29:58115 return OmniboxEventProto::Suggestion::HISTORY_URL;
[email protected]b7f64d742013-05-21 04:04:04116 case AutocompleteMatchType::HISTORY_TITLE:
[email protected]fe58acc22012-02-29 01:29:58117 return OmniboxEventProto::Suggestion::HISTORY_TITLE;
[email protected]b7f64d742013-05-21 04:04:04118 case AutocompleteMatchType::HISTORY_BODY:
[email protected]fe58acc22012-02-29 01:29:58119 return OmniboxEventProto::Suggestion::HISTORY_BODY;
[email protected]b7f64d742013-05-21 04:04:04120 case AutocompleteMatchType::HISTORY_KEYWORD:
[email protected]fe58acc22012-02-29 01:29:58121 return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
[email protected]b7f64d742013-05-21 04:04:04122 case AutocompleteMatchType::NAVSUGGEST:
[email protected]fe58acc22012-02-29 01:29:58123 return OmniboxEventProto::Suggestion::NAVSUGGEST;
[email protected]b7f64d742013-05-21 04:04:04124 case AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED:
[email protected]fe58acc22012-02-29 01:29:58125 return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
[email protected]b7f64d742013-05-21 04:04:04126 case AutocompleteMatchType::SEARCH_HISTORY:
[email protected]fe58acc22012-02-29 01:29:58127 return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
[email protected]b7f64d742013-05-21 04:04:04128 case AutocompleteMatchType::SEARCH_SUGGEST:
[email protected]fe58acc22012-02-29 01:29:58129 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
[email protected]2c03c06b2013-12-11 20:45:02130 case AutocompleteMatchType::SEARCH_SUGGEST_ENTITY:
131 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST_ENTITY;
132 case AutocompleteMatchType::SEARCH_SUGGEST_INFINITE:
133 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST_INFINITE;
134 case AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED:
135 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST_PERSONALIZED;
136 case AutocompleteMatchType::SEARCH_SUGGEST_PROFILE:
137 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST_PROFILE;
[email protected]b7f64d742013-05-21 04:04:04138 case AutocompleteMatchType::SEARCH_OTHER_ENGINE:
[email protected]fe58acc22012-02-29 01:29:58139 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
[email protected]b7f64d742013-05-21 04:04:04140 case AutocompleteMatchType::EXTENSION_APP:
[email protected]fe58acc22012-02-29 01:29:58141 return OmniboxEventProto::Suggestion::EXTENSION_APP;
[email protected]b7f64d742013-05-21 04:04:04142 case AutocompleteMatchType::BOOKMARK_TITLE:
[email protected]25320602012-10-18 22:05:56143 return OmniboxEventProto::Suggestion::BOOKMARK_TITLE;
[email protected]fe58acc22012-02-29 01:29:58144 default:
145 NOTREACHED();
146 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
147 }
148}
149
[email protected]3c919d6a2013-07-28 18:35:52150OmniboxEventProto::PageClassification AsOmniboxEventPageClassification(
151 AutocompleteInput::PageClassification page_classification) {
152 switch (page_classification) {
153 case AutocompleteInput::INVALID_SPEC:
154 return OmniboxEventProto::INVALID_SPEC;
[email protected]12b5cd052013-11-08 20:59:37155 case AutocompleteInput::NTP:
156 return OmniboxEventProto::NTP;
[email protected]3c919d6a2013-07-28 18:35:52157 case AutocompleteInput::BLANK:
158 return OmniboxEventProto::BLANK;
[email protected]0b1a1112013-08-28 05:23:31159 case AutocompleteInput::HOME_PAGE:
160 return OmniboxEventProto::HOME_PAGE;
[email protected]3c919d6a2013-07-28 18:35:52161 case AutocompleteInput::OTHER:
162 return OmniboxEventProto::OTHER;
[email protected]3c919d6a2013-07-28 18:35:52163 case AutocompleteInput::SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT:
164 return OmniboxEventProto::
165 SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT;
[email protected]12b5cd052013-11-08 20:59:37166 case AutocompleteInput::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS:
167 return OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS;
168 case AutocompleteInput::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS:
169 return OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS;
[email protected]2328ee22013-08-08 23:00:19170 case AutocompleteInput::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT:
171 return OmniboxEventProto::
172 SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT;
[email protected]3c919d6a2013-07-28 18:35:52173 }
174 return OmniboxEventProto::INVALID_SPEC;
175}
176
[email protected]ed0fd002012-04-25 23:10:34177ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType(
[email protected]f3b357692013-03-22 05:16:13178 int process_type) {
[email protected]ed0fd002012-04-25 23:10:34179 switch (process_type) {
180 case content::PROCESS_TYPE_BROWSER:
181 return ProfilerEventProto::TrackedObject::BROWSER;
182 case content::PROCESS_TYPE_RENDERER:
183 return ProfilerEventProto::TrackedObject::RENDERER;
184 case content::PROCESS_TYPE_PLUGIN:
185 return ProfilerEventProto::TrackedObject::PLUGIN;
186 case content::PROCESS_TYPE_WORKER:
187 return ProfilerEventProto::TrackedObject::WORKER;
[email protected]ed0fd002012-04-25 23:10:34188 case content::PROCESS_TYPE_UTILITY:
189 return ProfilerEventProto::TrackedObject::UTILITY;
[email protected]ed0fd002012-04-25 23:10:34190 case content::PROCESS_TYPE_ZYGOTE:
191 return ProfilerEventProto::TrackedObject::ZYGOTE;
192 case content::PROCESS_TYPE_SANDBOX_HELPER:
193 return ProfilerEventProto::TrackedObject::SANDBOX_HELPER;
[email protected]ed0fd002012-04-25 23:10:34194 case content::PROCESS_TYPE_GPU:
195 return ProfilerEventProto::TrackedObject::GPU;
196 case content::PROCESS_TYPE_PPAPI_PLUGIN:
197 return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN;
198 case content::PROCESS_TYPE_PPAPI_BROKER:
199 return ProfilerEventProto::TrackedObject::PPAPI_BROKER;
[email protected]f3b357692013-03-22 05:16:13200 case PROCESS_TYPE_NACL_LOADER:
201 return ProfilerEventProto::TrackedObject::NACL_LOADER;
202 case PROCESS_TYPE_NACL_BROKER:
203 return ProfilerEventProto::TrackedObject::NACL_BROKER;
[email protected]ed0fd002012-04-25 23:10:34204 default:
205 NOTREACHED();
206 return ProfilerEventProto::TrackedObject::UNKNOWN;
207 }
208}
209
[email protected]0f2f7792013-11-28 16:09:14210// Computes a SHA-1 hash of |data| and returns it as a hex string.
211std::string ComputeSHA1(const std::string& data) {
212 const std::string sha1 = base::SHA1HashString(data);
213 return base::HexEncode(sha1.data(), sha1.size());
214}
215
[email protected]1d51882f2013-11-12 01:59:02216#if defined(ENABLE_PLUGINS)
[email protected]1df44b72012-01-19 05:20:34217// Returns the plugin preferences corresponding for this user, if available.
218// If multiple user profiles are loaded, returns the preferences corresponding
219// to an arbitrary one of the profiles.
220PluginPrefs* GetPluginPrefs() {
221 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]fe58acc22012-02-29 01:29:58222
223 if (!profile_manager) {
224 // The profile manager can be NULL when testing.
225 return NULL;
226 }
227
[email protected]1df44b72012-01-19 05:20:34228 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
229 if (profiles.empty())
230 return NULL;
231
[email protected]cadac622013-06-11 16:46:36232 return PluginPrefs::GetForProfile(profiles.front()).get();
[email protected]1df44b72012-01-19 05:20:34233}
234
[email protected]fe58acc22012-02-29 01:29:58235// Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
[email protected]d7bd3e52013-07-21 04:29:20236void SetPluginInfo(const content::WebPluginInfo& plugin_info,
[email protected]fe58acc22012-02-29 01:29:58237 const PluginPrefs* plugin_prefs,
238 SystemProfileProto::Plugin* plugin) {
[email protected]6778fed2013-12-24 20:09:37239 plugin->set_name(base::UTF16ToUTF8(plugin_info.name));
[email protected]fe58acc22012-02-29 01:29:58240 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
[email protected]6778fed2013-12-24 20:09:37241 plugin->set_version(base::UTF16ToUTF8(plugin_info.version));
[email protected]4e3ca1c292013-09-10 01:59:19242 plugin->set_is_pepper(plugin_info.is_pepper_plugin());
[email protected]fe58acc22012-02-29 01:29:58243 if (plugin_prefs)
244 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
245}
[email protected]1d51882f2013-11-12 01:59:02246#endif // defined(ENABLE_PLUGINS)
[email protected]fe58acc22012-02-29 01:29:58247
[email protected]0c8b7ad2012-11-06 07:08:14248void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids,
[email protected]767c9d92012-03-02 16:04:34249 SystemProfileProto* system_profile) {
[email protected]0c8b7ad2012-11-06 07:08:14250 for (std::vector<ActiveGroupId>::const_iterator it =
[email protected]ad2461c2012-04-27 21:11:03251 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
[email protected]767c9d92012-03-02 16:04:34252 SystemProfileProto::FieldTrial* field_trial =
253 system_profile->add_field_trial();
254 field_trial->set_name_id(it->name);
255 field_trial->set_group_id(it->group);
256 }
257}
258
[email protected]0018f722014-02-08 03:08:51259// Maps a thread name by replacing trailing sequence of digits with "*".
260// Examples:
261// 1. "BrowserBlockingWorker1/23857" => "BrowserBlockingWorker1/*"
262// 2. "Chrome_IOThread" => "Chrome_IOThread"
263std::string MapThreadName(const std::string& thread_name) {
264 size_t i = thread_name.length();
265
266 while (i > 0 && isdigit(thread_name[i - 1])) {
267 --i;
268 }
269
270 if (i == thread_name.length())
271 return thread_name;
272
273 return thread_name.substr(0, i) + '*';
274}
275
[email protected]87b9bf12014-04-03 15:25:00276// Normalizes a source filename (which is platform- and build-method-dependent)
277// by extracting the last component of the full file name.
278// Example: "c:\b\build\slave\win\build\src\chrome\app\chrome_main.cc" =>
279// "chrome_main.cc".
280std::string NormalizeFileName(const std::string& file_name) {
281 const size_t offset = file_name.find_last_of("\\/");
282 return offset != std::string::npos ? file_name.substr(offset + 1) : file_name;
283}
284
[email protected]ed0fd002012-04-25 23:10:34285void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
[email protected]f3b357692013-03-22 05:16:13286 int process_type,
[email protected]ed0fd002012-04-25 23:10:34287 ProfilerEventProto* performance_profile) {
288 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it =
289 profiler_data.tasks.begin();
290 it != profiler_data.tasks.end(); ++it) {
[email protected]ed0fd002012-04-25 23:10:34291 const tracked_objects::DeathDataSnapshot& death_data = it->death_data;
292 ProfilerEventProto::TrackedObject* tracked_object =
293 performance_profile->add_tracked_object();
[email protected]db7fec832013-07-18 09:41:41294 tracked_object->set_birth_thread_name_hash(
[email protected]0018f722014-02-08 03:08:51295 MetricsLogBase::Hash(MapThreadName(it->birth.thread_name)));
[email protected]db7fec832013-07-18 09:41:41296 tracked_object->set_exec_thread_name_hash(
[email protected]0018f722014-02-08 03:08:51297 MetricsLogBase::Hash(MapThreadName(it->death_thread_name)));
[email protected]db7fec832013-07-18 09:41:41298 tracked_object->set_source_file_name_hash(
[email protected]87b9bf12014-04-03 15:25:00299 MetricsLogBase::Hash(NormalizeFileName(it->birth.location.file_name)));
[email protected]db7fec832013-07-18 09:41:41300 tracked_object->set_source_function_name_hash(
301 MetricsLogBase::Hash(it->birth.location.function_name));
[email protected]ed0fd002012-04-25 23:10:34302 tracked_object->set_source_line_number(it->birth.location.line_number);
303 tracked_object->set_exec_count(death_data.count);
304 tracked_object->set_exec_time_total(death_data.run_duration_sum);
305 tracked_object->set_exec_time_sampled(death_data.run_duration_sample);
306 tracked_object->set_queue_time_total(death_data.queue_duration_sum);
307 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample);
308 tracked_object->set_process_type(AsProtobufProcessType(process_type));
309 tracked_object->set_process_id(profiler_data.process_id);
310 }
311}
312
[email protected]59a7ae4e2012-10-01 23:54:44313#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
[email protected]197c0772012-05-14 23:50:51314void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data,
315 ProductInfo* product_info) {
316 product_info->set_version(product_data.version);
317 product_info->set_last_update_success_timestamp(
318 product_data.last_success.ToTimeT());
319 product_info->set_last_error(product_data.last_error_code);
320 product_info->set_last_extra_error(product_data.last_extra_code);
321 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) {
322 product_info->set_last_result(
323 static_cast<ProductInfo::InstallResult>(product_data.last_result));
324 }
325}
[email protected]59a7ae4e2012-10-01 23:54:44326#endif
[email protected]197c0772012-05-14 23:50:51327
[email protected]76869ff2013-01-15 16:13:47328#if defined(OS_WIN)
[email protected]ffaf7322013-05-15 00:26:11329struct ScreenDPIInformation {
[email protected]76869ff2013-01-15 16:13:47330 double max_dpi_x;
331 double max_dpi_y;
332};
333
334// Called once for each connected monitor.
335BOOL CALLBACK GetMonitorDPICallback(HMONITOR, HDC hdc, LPRECT, LPARAM dwData) {
336 const double kMillimetersPerInch = 25.4;
337 ScreenDPIInformation* screen_info =
338 reinterpret_cast<ScreenDPIInformation*>(dwData);
339 // Size of screen, in mm.
340 DWORD size_x = GetDeviceCaps(hdc, HORZSIZE);
341 DWORD size_y = GetDeviceCaps(hdc, VERTSIZE);
342 double dpi_x = (size_x > 0) ?
343 GetDeviceCaps(hdc, HORZRES) / (size_x / kMillimetersPerInch) : 0;
344 double dpi_y = (size_y > 0) ?
345 GetDeviceCaps(hdc, VERTRES) / (size_y / kMillimetersPerInch) : 0;
346 screen_info->max_dpi_x = std::max(dpi_x, screen_info->max_dpi_x);
347 screen_info->max_dpi_y = std::max(dpi_y, screen_info->max_dpi_y);
348 return TRUE;
349}
350
351void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) {
352 HDC desktop_dc = GetDC(NULL);
353 if (desktop_dc) {
[email protected]ffaf7322013-05-15 00:26:11354 ScreenDPIInformation si = {0, 0};
[email protected]76869ff2013-01-15 16:13:47355 if (EnumDisplayMonitors(desktop_dc, NULL, GetMonitorDPICallback,
356 reinterpret_cast<LPARAM>(&si))) {
357 hardware->set_max_dpi_x(si.max_dpi_x);
358 hardware->set_max_dpi_y(si.max_dpi_y);
359 }
360 ReleaseDC(GetDesktopWindow(), desktop_dc);
361 }
362}
363
364#endif // defined(OS_WIN)
365
[email protected]86573d12013-07-11 19:48:32366// Round a timestamp measured in seconds since epoch to one with a granularity
367// of an hour. This can be used before uploaded potentially sensitive
368// timestamps.
369int64 RoundSecondsToHour(int64 time_in_seconds) {
370 return 3600 * (time_in_seconds / 3600);
371}
372
[email protected]1df44b72012-01-19 05:20:34373} // namespace
374
[email protected]197c0772012-05-14 23:50:51375GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {}
376
377GoogleUpdateMetrics::~GoogleUpdateMetrics() {}
378
[email protected]67f92bc32012-01-26 01:56:19379static base::LazyInstance<std::string>::Leaky
[email protected]0f2f7792013-11-28 16:09:14380 g_version_extension = LAZY_INSTANCE_INITIALIZER;
[email protected]054c8012011-11-16 00:12:42381
[email protected]1226abb2010-06-10 18:01:28382MetricsLog::MetricsLog(const std::string& client_id, int session_id)
[email protected]60677562013-11-17 15:52:55383 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()),
[email protected]b84ee6e2014-03-15 22:51:54384 creation_time_(base::TimeTicks::Now()),
385 extension_metrics_(uma_proto()->client_id()) {
[email protected]afc03f02013-10-11 06:01:35386#if defined(OS_CHROMEOS)
[email protected]c9afed6e2014-02-03 22:12:29387 metrics_log_chromeos_.reset(new MetricsLogChromeOS(uma_proto()));
388#endif // OS_CHROMEOS
[email protected]afc03f02013-10-11 06:01:35389}
[email protected]5ed7d4572009-12-23 17:42:41390
[email protected]1226abb2010-06-10 18:01:28391MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:29392
393// static
[email protected]b1de2c72013-02-06 02:45:47394void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) {
395 registry->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29396}
397
[email protected]1df44b72012-01-19 05:20:34398// static
[email protected]1226abb2010-06-10 18:01:28399std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:42400 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:17401 if (!version_info.is_valid()) {
402 NOTREACHED() << "Unable to retrieve version info.";
403 return std::string();
404 }
405
[email protected]0211f57e2010-08-27 20:28:42406 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:42407 if (!version_extension().empty())
408 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:42409 if (!version_info.IsOfficialBuild())
410 version.append("-devel");
411 return version;
[email protected]1226abb2010-06-10 18:01:28412}
413
[email protected]054c8012011-11-16 00:12:42414// static
415void MetricsLog::set_version_extension(const std::string& extension) {
416 g_version_extension.Get() = extension;
417}
418
419// static
420const std::string& MetricsLog::version_extension() {
421 return g_version_extension.Get();
422}
423
[email protected]076961c2014-03-12 22:23:56424void MetricsLog::RecordStabilityMetrics(base::TimeDelta incremental_uptime,
425 base::TimeDelta uptime,
426 LogType log_type) {
[email protected]0edf8762013-11-21 18:33:30427 DCHECK_NE(NO_LOG, log_type);
[email protected]767c9d92012-03-02 16:04:34428 DCHECK(!locked());
[email protected]0f2f7792013-11-28 16:09:14429 DCHECK(HasEnvironment());
430 DCHECK(!HasStabilityMetrics());
[email protected]0b33f80b2008-12-17 21:34:36431
[email protected]767c9d92012-03-02 16:04:34432 PrefService* pref = GetPrefService();
[email protected]0b33f80b2008-12-17 21:34:36433 DCHECK(pref);
434
initial.commit09911bf2008-07-26 23:55:29435 // Get stability attributes out of Local State, zeroing out stored values.
436 // NOTE: This could lead to some data loss if this report isn't successfully
437 // sent, but that's true for all the metrics.
438
[email protected]147bbc0b2009-01-06 19:37:40439 WriteRequiredStabilityAttributes(pref);
[email protected]250f7b662013-11-23 02:36:51440 WritePluginStabilityElements(pref);
[email protected]0edf8762013-11-21 18:33:30441
442 // Record recent delta for critical stability metrics. We can't wait for a
443 // restart to gather these, as that delay biases our observation away from
444 // users that run happily for a looooong time. We send increments with each
445 // uma log upload, just as we send histogram data.
[email protected]076961c2014-03-12 22:23:56446 WriteRealtimeStabilityAttributes(pref, incremental_uptime, uptime);
initial.commit09911bf2008-07-26 23:55:29447
[email protected]0edf8762013-11-21 18:33:30448 // Omit some stats unless this is the initial stability log.
449 if (log_type != INITIAL_LOG)
450 return;
451
[email protected]fe58acc22012-02-29 01:29:58452 int incomplete_shutdown_count =
453 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
[email protected]e324f6b2012-02-28 05:43:37454 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58455 int breakpad_registration_success_count =
456 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
[email protected]e324f6b2012-02-28 05:43:37457 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58458 int breakpad_registration_failure_count =
459 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
[email protected]e324f6b2012-02-28 05:43:37460 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58461 int debugger_present_count =
462 pref->GetInteger(prefs::kStabilityDebuggerPresent);
[email protected]e324f6b2012-02-28 05:43:37463 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58464 int debugger_not_present_count =
465 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
[email protected]e324f6b2012-02-28 05:43:37466 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31467
[email protected]fe58acc22012-02-29 01:29:58468 // TODO(jar): The following are all optional, so we *could* optimize them for
469 // values of zero (and not include them).
[email protected]fe58acc22012-02-29 01:29:58470 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34471 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58472 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
473 stability->set_breakpad_registration_success_count(
474 breakpad_registration_success_count);
475 stability->set_breakpad_registration_failure_count(
476 breakpad_registration_failure_count);
477 stability->set_debugger_present_count(debugger_present_count);
478 stability->set_debugger_not_present_count(debugger_not_present_count);
[email protected]0edf8762013-11-21 18:33:30479}
[email protected]fe58acc22012-02-29 01:29:58480
[email protected]0edf8762013-11-21 18:33:30481PrefService* MetricsLog::GetPrefService() {
482 return g_browser_process->local_state();
483}
484
485gfx::Size MetricsLog::GetScreenSize() const {
486 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel();
487}
488
489float MetricsLog::GetScreenDeviceScaleFactor() const {
490 return gfx::Screen::GetNativeScreen()->
491 GetPrimaryDisplay().device_scale_factor();
492}
493
494int MetricsLog::GetScreenCount() const {
495 // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312
496 return gfx::Screen::GetNativeScreen()->GetNumDisplays();
497}
498
499void MetricsLog::GetFieldTrialIds(
500 std::vector<ActiveGroupId>* field_trial_ids) const {
501 chrome_variations::GetFieldTrialActiveGroupIds(field_trial_ids);
[email protected]147bbc0b2009-01-06 19:37:40502}
503
[email protected]0f2f7792013-11-28 16:09:14504bool MetricsLog::HasEnvironment() const {
505 return uma_proto()->system_profile().has_uma_enabled_date();
506}
507
508bool MetricsLog::HasStabilityMetrics() const {
509 return uma_proto()->system_profile().stability().has_launch_count();
510}
511
[email protected]250f7b662013-11-23 02:36:51512void MetricsLog::WritePluginStabilityElements(PrefService* pref) {
[email protected]147bbc0b2009-01-06 19:37:40513 // Now log plugin stability info.
[email protected]cb1078de2013-12-23 20:04:22514 const base::ListValue* plugin_stats_list = pref->GetList(
initial.commit09911bf2008-07-26 23:55:29515 prefs::kStabilityPluginStats);
[email protected]1df44b72012-01-19 05:20:34516 if (!plugin_stats_list)
517 return;
initial.commit09911bf2008-07-26 23:55:29518
[email protected]ebd71962012-12-20 02:56:55519#if defined(ENABLE_PLUGINS)
[email protected]fe58acc22012-02-29 01:29:58520 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34521 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]cb1078de2013-12-23 20:04:22522 for (base::ListValue::const_iterator iter = plugin_stats_list->begin();
[email protected]1df44b72012-01-19 05:20:34523 iter != plugin_stats_list->end(); ++iter) {
[email protected]cb1078de2013-12-23 20:04:22524 if (!(*iter)->IsType(base::Value::TYPE_DICTIONARY)) {
[email protected]1df44b72012-01-19 05:20:34525 NOTREACHED();
526 continue;
initial.commit09911bf2008-07-26 23:55:29527 }
[email protected]cb1078de2013-12-23 20:04:22528 base::DictionaryValue* plugin_dict =
529 static_cast<base::DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29530
[email protected]fe58acc22012-02-29 01:29:58531 // Note that this search is potentially a quadratic operation, but given the
532 // low number of plugins installed on a "reasonable" setup, this should be
533 // fine.
534 // TODO(isherman): Verify that this does not show up as a hotspot in
535 // profiler runs.
[email protected]250f7b662013-11-23 02:36:51536 const SystemProfileProto::Plugin* system_profile_plugin = NULL;
[email protected]f31a01a2013-07-13 02:51:11537 std::string plugin_name;
538 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
[email protected]250f7b662013-11-23 02:36:51539 const SystemProfileProto& system_profile = uma_proto()->system_profile();
540 for (int i = 0; i < system_profile.plugin_size(); ++i) {
541 if (system_profile.plugin(i).name() == plugin_name) {
542 system_profile_plugin = &system_profile.plugin(i);
[email protected]fe58acc22012-02-29 01:29:58543 break;
544 }
545 }
546
[email protected]250f7b662013-11-23 02:36:51547 if (!system_profile_plugin) {
[email protected]fe58acc22012-02-29 01:29:58548 NOTREACHED();
549 continue;
550 }
551
552 SystemProfileProto::Stability::PluginStability* plugin_stability =
553 stability->add_plugin_stability();
[email protected]250f7b662013-11-23 02:36:51554 *plugin_stability->mutable_plugin() = *system_profile_plugin;
[email protected]f31a01a2013-07-13 02:51:11555
556 int launches = 0;
557 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
558 if (launches > 0)
559 plugin_stability->set_launch_count(launches);
560
561 int instances = 0;
562 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
563 if (instances > 0)
564 plugin_stability->set_instance_count(instances);
565
566 int crashes = 0;
567 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
568 if (crashes > 0)
569 plugin_stability->set_crash_count(crashes);
570
571 int loading_errors = 0;
572 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors,
573 &loading_errors);
574 if (loading_errors > 0)
575 plugin_stability->set_loading_error_count(loading_errors);
initial.commit09911bf2008-07-26 23:55:29576 }
[email protected]ebd71962012-12-20 02:56:55577#endif // defined(ENABLE_PLUGINS)
[email protected]1df44b72012-01-19 05:20:34578
579 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29580}
581
[email protected]fe58acc22012-02-29 01:29:58582// The server refuses data that doesn't have certain values. crashcount and
583// launchcount are currently "required" in the "stability" group.
584// TODO(isherman): Stop writing these attributes specially once the migration to
585// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40586void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]fe58acc22012-02-29 01:29:58587 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
[email protected]0b33f80b2008-12-17 21:34:36588 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
[email protected]fe58acc22012-02-29 01:29:58589 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
[email protected]0b33f80b2008-12-17 21:34:36590 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58591
[email protected]fe58acc22012-02-29 01:29:58592 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34593 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58594 stability->set_launch_count(launch_count);
595 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36596}
597
[email protected]c68a2b9b2013-10-09 18:16:36598void MetricsLog::WriteRealtimeStabilityAttributes(
599 PrefService* pref,
[email protected]076961c2014-03-12 22:23:56600 base::TimeDelta incremental_uptime,
601 base::TimeDelta uptime) {
[email protected]0b33f80b2008-12-17 21:34:36602 // Update the stats which are critical for real-time stability monitoring.
603 // Since these are "optional," only list ones that are non-zero, as the counts
[email protected]250f7b662013-11-23 02:36:51604 // are aggregated (summed) server side.
[email protected]0b33f80b2008-12-17 21:34:36605
[email protected]fe58acc22012-02-29 01:29:58606 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34607 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36608 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
609 if (count) {
[email protected]fe58acc22012-02-29 01:29:58610 stability->set_page_load_count(count);
[email protected]0b33f80b2008-12-17 21:34:36611 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
612 }
613
614 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
615 if (count) {
[email protected]fe58acc22012-02-29 01:29:58616 stability->set_renderer_crash_count(count);
[email protected]0b33f80b2008-12-17 21:34:36617 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
618 }
619
[email protected]1f085622009-12-04 05:33:45620 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
621 if (count) {
[email protected]fe58acc22012-02-29 01:29:58622 stability->set_extension_renderer_crash_count(count);
[email protected]1f085622009-12-04 05:33:45623 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
624 }
625
[email protected]0b33f80b2008-12-17 21:34:36626 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
627 if (count) {
[email protected]fe58acc22012-02-29 01:29:58628 stability->set_renderer_hang_count(count);
[email protected]0b33f80b2008-12-17 21:34:36629 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
630 }
[email protected]1f085622009-12-04 05:33:45631
632 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
633 if (count) {
[email protected]fe58acc22012-02-29 01:29:58634 stability->set_child_process_crash_count(count);
[email protected]1f085622009-12-04 05:33:45635 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
636 }
[email protected]9165f742010-03-10 22:55:01637
[email protected]c1834a92011-01-21 18:21:03638#if defined(OS_CHROMEOS)
[email protected]c9afed6e2014-02-03 22:12:29639 metrics_log_chromeos_->WriteRealtimeStabilityAttributes(pref);
[email protected]c1834a92011-01-21 18:21:03640#endif // OS_CHROMEOS
641
[email protected]076961c2014-03-12 22:23:56642 const uint64 incremental_uptime_sec = incremental_uptime.InSeconds();
643 if (incremental_uptime_sec)
644 stability->set_incremental_uptime_sec(incremental_uptime_sec);
645 const uint64 uptime_sec = uptime.InSeconds();
[email protected]c68a2b9b2013-10-09 18:16:36646 if (uptime_sec)
647 stability->set_uptime_sec(uptime_sec);
[email protected]0b33f80b2008-12-17 21:34:36648}
649
initial.commit09911bf2008-07-26 23:55:29650void MetricsLog::WritePluginList(
[email protected]d7bd3e52013-07-21 04:29:20651 const std::vector<content::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34652 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29653
[email protected]ebd71962012-12-20 02:56:55654#if defined(ENABLE_PLUGINS)
655 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]767c9d92012-03-02 16:04:34656 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]d7bd3e52013-07-21 04:29:20657 for (std::vector<content::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50658 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29659 iter != plugin_list.end(); ++iter) {
[email protected]0eecc2542013-06-23 04:22:02660 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
661 SetPluginInfo(*iter, plugin_prefs, plugin);
initial.commit09911bf2008-07-26 23:55:29662 }
[email protected]ebd71962012-12-20 02:56:55663#endif // defined(ENABLE_PLUGINS)
initial.commit09911bf2008-07-26 23:55:29664}
665
666void MetricsLog::RecordEnvironment(
[email protected]c68a2b9b2013-10-09 18:16:36667 const std::vector<content::WebPluginInfo>& plugin_list,
668 const GoogleUpdateMetrics& google_update_metrics,
[email protected]60677562013-11-17 15:52:55669 const std::vector<chrome_variations::ActiveGroupId>& synthetic_trials) {
[email protected]0f2f7792013-11-28 16:09:14670 DCHECK(!HasEnvironment());
671
[email protected]bc66d532012-03-23 01:57:05672 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]24b9bb392013-01-29 20:29:29673
674 std::string brand_code;
675 if (google_util::GetBrand(&brand_code))
676 system_profile->set_brand_code(brand_code);
677
[email protected]cc5d7f42012-10-30 00:30:09678 int enabled_date;
679 bool success = base::StringToInt(GetMetricsEnabledDate(GetPrefService()),
680 &enabled_date);
[email protected]bc66d532012-03-23 01:57:05681 DCHECK(success);
[email protected]86573d12013-07-11 19:48:32682
683 // Reduce granularity of the enabled_date field to nearest hour.
684 system_profile->set_uma_enabled_date(RoundSecondsToHour(enabled_date));
685
686 int64 install_date = GetPrefService()->GetInt64(prefs::kInstallDate);
687
688 // Reduce granularity of the install_date field to nearest hour.
689 system_profile->set_install_date(RoundSecondsToHour(install_date));
[email protected]bc66d532012-03-23 01:57:05690
691 system_profile->set_application_locale(
[email protected]eabbfb12013-04-05 23:28:35692 g_browser_process->GetApplicationLocale());
[email protected]bc66d532012-03-23 01:57:05693
694 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
[email protected]0b6a4fb2012-10-16 01:58:21695 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
[email protected]bc66d532012-03-23 01:57:05696 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
697#if defined(OS_WIN)
698 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
699#endif
700
[email protected]74b299e2013-01-29 01:24:42701 SystemProfileProto::Network* network = system_profile->mutable_network();
702 network->set_connection_type_is_ambiguous(
[email protected]5eae204c2013-02-13 15:53:42703 network_observer_.connection_type_is_ambiguous());
704 network->set_connection_type(network_observer_.connection_type());
705 network->set_wifi_phy_layer_protocol_is_ambiguous(
706 network_observer_.wifi_phy_layer_protocol_is_ambiguous());
707 network->set_wifi_phy_layer_protocol(
708 network_observer_.wifi_phy_layer_protocol());
709 network_observer_.Reset();
[email protected]74b299e2013-01-29 01:24:42710
[email protected]bc66d532012-03-23 01:57:05711 SystemProfileProto::OS* os = system_profile->mutable_os();
[email protected]1bb25e02012-08-03 22:39:39712 std::string os_name = base::SysInfo::OperatingSystemName();
713#if defined(OS_WIN)
714 // TODO(mad): This only checks whether the main process is a Metro process at
715 // upload time; not whether the collected metrics were all gathered from
716 // Metro. This is ok as an approximation for now, since users will rarely be
717 // switching from Metro to Desktop mode; but we should re-evaluate whether we
718 // can distinguish metrics more cleanly in the future: http://crbug.com/140568
719 if (base::win::IsMetroProcess())
720 os_name += " (Metro)";
721#endif
722 os->set_name(os_name);
[email protected]bc66d532012-03-23 01:57:05723 os->set_version(base::SysInfo::OperatingSystemVersion());
[email protected]5106b3a2012-10-03 20:10:44724#if defined(OS_ANDROID)
725 os->set_fingerprint(
726 base::android::BuildInfo::GetInstance()->android_build_fp());
727#endif
[email protected]bc66d532012-03-23 01:57:05728
[email protected]5c8f89f692013-07-18 11:13:28729 base::CPU cpu_info;
730 SystemProfileProto::Hardware::CPU* cpu = hardware->mutable_cpu();
731 cpu->set_vendor_name(cpu_info.vendor_name());
732 cpu->set_signature(cpu_info.signature());
733
[email protected]d7b5cc72013-05-23 20:05:00734 const gpu::GPUInfo& gpu_info =
[email protected]bc66d532012-03-23 01:57:05735 GpuDataManager::GetInstance()->GetGPUInfo();
736 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
[email protected]a094e2c2012-05-10 23:02:42737 gpu->set_vendor_id(gpu_info.gpu.vendor_id);
738 gpu->set_device_id(gpu_info.gpu.device_id);
[email protected]bc66d532012-03-23 01:57:05739 gpu->set_driver_version(gpu_info.driver_version);
740 gpu->set_driver_date(gpu_info.driver_date);
741 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
742 gpu_performance = gpu->mutable_performance_statistics();
743 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
744 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
745 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
[email protected]d6bdfae2013-01-18 20:23:01746 gpu->set_gl_vendor(gpu_info.gl_vendor);
747 gpu->set_gl_renderer(gpu_info.gl_renderer);
[email protected]bc66d532012-03-23 01:57:05748
749 const gfx::Size display_size = GetScreenSize();
750 hardware->set_primary_screen_width(display_size.width());
751 hardware->set_primary_screen_height(display_size.height());
[email protected]aa96417972012-08-22 03:16:44752 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor());
[email protected]bc66d532012-03-23 01:57:05753 hardware->set_screen_count(GetScreenCount());
754
[email protected]76869ff2013-01-15 16:13:47755#if defined(OS_WIN)
756 WriteScreenDPIInformationProto(hardware);
757#endif
758
[email protected]197c0772012-05-14 23:50:51759 WriteGoogleUpdateProto(google_update_metrics);
760
[email protected]0eecc2542013-06-23 04:22:02761 WritePluginList(plugin_list);
[email protected]b84ee6e2014-03-15 22:51:54762 extension_metrics_.WriteExtensionList(uma_proto()->mutable_system_profile());
[email protected]bc66d532012-03-23 01:57:05763
[email protected]0c8b7ad2012-11-06 07:08:14764 std::vector<ActiveGroupId> field_trial_ids;
[email protected]767c9d92012-03-02 16:04:34765 GetFieldTrialIds(&field_trial_ids);
766 WriteFieldTrials(field_trial_ids, system_profile);
[email protected]60677562013-11-17 15:52:55767 WriteFieldTrials(synthetic_trials, system_profile);
[email protected]f65859e2013-02-04 20:00:25768
769#if defined(OS_CHROMEOS)
[email protected]c9afed6e2014-02-03 22:12:29770 metrics_log_chromeos_->LogChromeOSMetrics();
771#endif // OS_CHROMEOS
[email protected]0f2f7792013-11-28 16:09:14772
773 std::string serialied_system_profile;
774 std::string base64_system_profile;
[email protected]33fca122013-12-11 01:48:50775 if (system_profile->SerializeToString(&serialied_system_profile)) {
776 base::Base64Encode(serialied_system_profile, &base64_system_profile);
[email protected]0f2f7792013-11-28 16:09:14777 PrefService* local_state = GetPrefService();
778 local_state->SetString(prefs::kStabilitySavedSystemProfile,
779 base64_system_profile);
780 local_state->SetString(prefs::kStabilitySavedSystemProfileHash,
781 ComputeSHA1(serialied_system_profile));
782 }
783}
784
785bool MetricsLog::LoadSavedEnvironmentFromPrefs() {
786 PrefService* local_state = GetPrefService();
787 const std::string base64_system_profile =
788 local_state->GetString(prefs::kStabilitySavedSystemProfile);
789 if (base64_system_profile.empty())
790 return false;
791
792 const std::string system_profile_hash =
793 local_state->GetString(prefs::kStabilitySavedSystemProfileHash);
794 local_state->ClearPref(prefs::kStabilitySavedSystemProfile);
795 local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash);
796
797 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
798 std::string serialied_system_profile;
799 return base::Base64Decode(base64_system_profile, &serialied_system_profile) &&
800 ComputeSHA1(serialied_system_profile) == system_profile_hash &&
801 system_profile->ParseFromString(serialied_system_profile);
initial.commit09911bf2008-07-26 23:55:29802}
803
[email protected]ed0fd002012-04-25 23:10:34804void MetricsLog::RecordProfilerData(
805 const tracked_objects::ProcessDataSnapshot& process_data,
[email protected]f3b357692013-03-22 05:16:13806 int process_type) {
[email protected]ed0fd002012-04-25 23:10:34807 DCHECK(!locked());
808
[email protected]8f829682012-04-27 00:36:49809 if (tracked_objects::GetTimeSourceType() !=
810 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) {
[email protected]ed0fd002012-04-25 23:10:34811 // We currently only support the default time source, wall clock time.
812 return;
813 }
814
815 ProfilerEventProto* profile;
816 if (!uma_proto()->profiler_event_size()) {
817 // For the first process's data, add a new field to the protocol buffer.
818 profile = uma_proto()->add_profiler_event();
819 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
820 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
821 } else {
822 // For the remaining calls, re-use the existing field.
823 profile = uma_proto()->mutable_profiler_event(0);
824 }
825
826 WriteProfilerData(process_data, process_type, profile);
827}
828
[email protected]0fafc8d2013-06-01 00:09:50829void MetricsLog::RecordOmniboxOpenedURL(const OmniboxLog& log) {
[email protected]767c9d92012-03-02 16:04:34830 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29831
[email protected]8790210c2013-12-02 05:29:53832 std::vector<base::string16> terms;
[email protected]65956312012-04-19 21:28:12833 const int num_terms =
[email protected]8790210c2013-12-02 05:29:53834 static_cast<int>(Tokenize(log.text, base::kWhitespaceUTF16, &terms));
initial.commit09911bf2008-07-26 23:55:29835
[email protected]767c9d92012-03-02 16:04:34836 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
[email protected]fe58acc22012-02-29 01:29:58837 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
838 if (log.tab_id != -1) {
839 // If we know what tab the autocomplete URL was opened in, log it.
840 omnibox_event->set_tab_id(log.tab_id);
841 }
842 omnibox_event->set_typed_length(log.text.length());
[email protected]660fe8f32012-05-03 20:01:08843 omnibox_event->set_just_deleted_text(log.just_deleted_text);
[email protected]65956312012-04-19 21:28:12844 omnibox_event->set_num_typed_terms(num_terms);
[email protected]fe58acc22012-02-29 01:29:58845 omnibox_event->set_selected_index(log.selected_index);
[email protected]439f1e32013-12-09 20:09:09846 if (log.completed_length != base::string16::npos)
[email protected]62b3ef52013-01-18 00:13:02847 omnibox_event->set_completed_length(log.completed_length);
[email protected]65956312012-04-19 21:28:12848 if (log.elapsed_time_since_user_first_modified_omnibox !=
849 base::TimeDelta::FromMilliseconds(-1)) {
850 // Only upload the typing duration if it is set/valid.
851 omnibox_event->set_typing_duration_ms(
852 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
853 }
[email protected]35d55602012-11-20 23:49:03854 omnibox_event->set_duration_since_last_default_match_update_ms(
855 log.elapsed_time_since_last_change_to_default_match.InMilliseconds());
[email protected]ee902532012-05-01 23:54:49856 omnibox_event->set_current_page_classification(
[email protected]3c919d6a2013-07-28 18:35:52857 AsOmniboxEventPageClassification(log.current_page_classification));
[email protected]fe58acc22012-02-29 01:29:58858 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
[email protected]1fce7dd42013-08-06 02:29:17859 omnibox_event->set_is_top_result_hidden_in_dropdown(
860 log.result.ShouldHideTopMatch());
[email protected]1fce7dd42013-08-06 02:29:17861
[email protected]fe58acc22012-02-29 01:29:58862 for (AutocompleteResult::const_iterator i(log.result.begin());
863 i != log.result.end(); ++i) {
864 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
[email protected]0e9e8782012-05-15 23:01:51865 suggestion->set_provider(i->provider->AsOmniboxEventProviderType());
[email protected]fe58acc22012-02-29 01:29:58866 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
867 suggestion->set_relevance(i->relevance);
[email protected]cf6256f2012-06-12 23:36:01868 if (i->typed_count != -1)
869 suggestion->set_typed_count(i->typed_count);
[email protected]fe58acc22012-02-29 01:29:58870 suggestion->set_is_starred(i->starred);
871 }
[email protected]0e9e8782012-05-15 23:01:51872 for (ProvidersInfo::const_iterator i(log.providers_info.begin());
873 i != log.providers_info.end(); ++i) {
874 OmniboxEventProto::ProviderInfo* provider_info =
875 omnibox_event->add_provider_info();
876 provider_info->CopyFrom(*i);
877 }
[email protected]fe58acc22012-02-29 01:29:58878
initial.commit09911bf2008-07-26 23:55:29879 ++num_events_;
880}
[email protected]197c0772012-05-14 23:50:51881
882void MetricsLog::WriteGoogleUpdateProto(
883 const GoogleUpdateMetrics& google_update_metrics) {
884#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
885 SystemProfileProto::GoogleUpdate* google_update =
886 uma_proto()->mutable_system_profile()->mutable_google_update();
887
888 google_update->set_is_system_install(google_update_metrics.is_system_install);
889
890 if (!google_update_metrics.last_started_au.is_null()) {
891 google_update->set_last_automatic_start_timestamp(
892 google_update_metrics.last_started_au.ToTimeT());
893 }
894
895 if (!google_update_metrics.last_checked.is_null()) {
896 google_update->set_last_update_check_timestamp(
897 google_update_metrics.last_checked.ToTimeT());
898 }
899
900 if (!google_update_metrics.google_update_data.version.empty()) {
901 ProductDataToProto(google_update_metrics.google_update_data,
902 google_update->mutable_google_update_status());
903 }
904
905 if (!google_update_metrics.product_data.version.empty()) {
906 ProductDataToProto(google_update_metrics.product_data,
907 google_update->mutable_client_status());
908 }
909#endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
910}