blob: 246880ee34f4de5c80826e9cb89cd832f4b80a1a [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]d1be67b2008-11-19 20:28:3811#include "base/basictypes.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/file_util.h"
[email protected]054c8012011-11-16 00:12:4213#include "base/lazy_instance.h"
[email protected]3b63f8f42011-03-28 01:54:1514#include "base/memory/scoped_ptr.h"
[email protected]85ed9d42010-06-08 22:37:4415#include "base/perftimer.h"
[email protected]ed0fd002012-04-25 23:10:3416#include "base/profiler/alternate_timer.h"
[email protected]fe58acc22012-02-29 01:29:5817#include "base/string_number_conversions.h"
initial.commit09911bf2008-07-26 23:55:2918#include "base/string_util.h"
[email protected]fadf97f2008-09-18 12:18:1419#include "base/sys_info.h"
[email protected]37f39e42010-01-06 17:35:1720#include "base/third_party/nspr/prtime.h"
[email protected]1eeb5e02010-07-20 23:02:1121#include "base/time.h"
[email protected]ed0fd002012-04-25 23:10:3422#include "base/tracked_objects.h"
[email protected]1eeb5e02010-07-20 23:02:1123#include "base/utf_string_conversions.h"
[email protected]9f8bc2f2012-07-03 16:26:5324#include "chrome/browser/autocomplete/autocomplete_input.h"
[email protected]19871a92012-06-27 19:50:3225#include "chrome/browser/autocomplete/autocomplete_log.h"
[email protected]9ac40092010-10-27 23:05:2626#include "chrome/browser/autocomplete/autocomplete_match.h"
[email protected]30f5bc92012-06-26 04:14:5527#include "chrome/browser/autocomplete/autocomplete_provider.h"
[email protected]73c2b1632012-07-02 22:51:3828#include "chrome/browser/autocomplete/autocomplete_result.h"
initial.commit09911bf2008-07-26 23:55:2929#include "chrome/browser/browser_process.h"
[email protected]0f5e57f52012-09-20 20:53:1830#include "chrome/browser/plugins/plugin_prefs.h"
[email protected]37858e52010-08-26 00:22:0231#include "chrome/browser/prefs/pref_service.h"
[email protected]10084982011-08-19 17:56:5632#include "chrome/browser/profiles/profile_manager.h"
[email protected]1eeb5e02010-07-20 23:02:1133#include "chrome/common/chrome_version_info.h"
initial.commit09911bf2008-07-26 23:55:2934#include "chrome/common/logging_chrome.h"
[email protected]fe58acc22012-02-29 01:29:5835#include "chrome/common/metrics/proto/omnibox_event.pb.h"
[email protected]ed0fd002012-04-25 23:10:3436#include "chrome/common/metrics/proto/profiler_event.pb.h"
[email protected]fe58acc22012-02-29 01:29:5837#include "chrome/common/metrics/proto/system_profile.pb.h"
[email protected]cf265dc02012-08-15 01:01:1638#include "chrome/common/metrics/variations/variations_util.h"
initial.commit09911bf2008-07-26 23:55:2939#include "chrome/common/pref_names.h"
[email protected]197c0772012-05-14 23:50:5140#include "chrome/installer/util/google_update_settings.h"
[email protected]fe58acc22012-02-29 01:29:5841#include "content/public/browser/content_browser_client.h"
[email protected]79078df2012-02-16 01:22:3242#include "content/public/browser/gpu_data_manager.h"
[email protected]1a838cc2012-04-24 22:06:4943#include "content/public/common/content_client.h"
[email protected]ed0fd002012-04-25 23:10:3444#include "content/public/common/gpu_info.h"
[email protected]46072d42008-07-28 14:49:3545#include "googleurl/src/gurl.h"
[email protected]6b7d954ff2011-10-25 00:39:3546#include "ui/gfx/screen.h"
[email protected]91d9f3d2011-08-14 05:24:4447#include "webkit/plugins/webplugininfo.h"
initial.commit09911bf2008-07-26 23:55:2948
[email protected]5106b3a2012-10-03 20:10:4449#if defined(OS_ANDROID)
50#include "base/android/build_info.h"
51#endif
52
initial.commit09911bf2008-07-26 23:55:2953#define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
54
[email protected]d1be67b2008-11-19 20:28:3855#if defined(OS_WIN)
[email protected]1bb25e02012-08-03 22:39:3956#include "base/win/metro.h"
57
58// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
[email protected]d1be67b2008-11-19 20:28:3859extern "C" IMAGE_DOS_HEADER __ImageBase;
60#endif
61
[email protected]79078df2012-02-16 01:22:3262using content::GpuDataManager;
[email protected]fe58acc22012-02-29 01:29:5863using metrics::OmniboxEventProto;
[email protected]ed0fd002012-04-25 23:10:3464using metrics::ProfilerEventProto;
[email protected]fe58acc22012-02-29 01:29:5865using metrics::SystemProfileProto;
[email protected]ed0fd002012-04-25 23:10:3466using tracked_objects::ProcessDataSnapshot;
[email protected]0c8b7ad2012-11-06 07:08:1467typedef chrome_variations::ActiveGroupId ActiveGroupId;
[email protected]197c0772012-05-14 23:50:5168typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo;
[email protected]79078df2012-02-16 01:22:3269
[email protected]1df44b72012-01-19 05:20:3470namespace {
71
72// Returns the date at which the current metrics client ID was created as
[email protected]ca5ac4b2012-12-14 07:46:4073// a string containing seconds since the epoch, or "0" if none was found.
[email protected]cc5d7f42012-10-30 00:30:0974std::string GetMetricsEnabledDate(PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:3475 if (!pref) {
[email protected]1df44b72012-01-19 05:20:3476 NOTREACHED();
77 return "0";
78 }
[email protected]767c9d92012-03-02 16:04:3479
80 return pref->GetString(prefs::kMetricsClientIDTimestamp);
[email protected]1df44b72012-01-19 05:20:3481}
82
[email protected]fe58acc22012-02-29 01:29:5883OmniboxEventProto::InputType AsOmniboxEventInputType(
84 AutocompleteInput::Type type) {
85 switch (type) {
86 case AutocompleteInput::INVALID:
87 return OmniboxEventProto::INVALID;
88 case AutocompleteInput::UNKNOWN:
89 return OmniboxEventProto::UNKNOWN;
90 case AutocompleteInput::REQUESTED_URL:
91 return OmniboxEventProto::REQUESTED_URL;
92 case AutocompleteInput::URL:
93 return OmniboxEventProto::URL;
94 case AutocompleteInput::QUERY:
95 return OmniboxEventProto::QUERY;
96 case AutocompleteInput::FORCED_QUERY:
97 return OmniboxEventProto::FORCED_QUERY;
98 default:
99 NOTREACHED();
100 return OmniboxEventProto::INVALID;
101 }
102}
103
[email protected]fe58acc22012-02-29 01:29:58104OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
105 AutocompleteMatch::Type type) {
106 switch (type) {
107 case AutocompleteMatch::URL_WHAT_YOU_TYPED:
108 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
109 case AutocompleteMatch::HISTORY_URL:
110 return OmniboxEventProto::Suggestion::HISTORY_URL;
111 case AutocompleteMatch::HISTORY_TITLE:
112 return OmniboxEventProto::Suggestion::HISTORY_TITLE;
113 case AutocompleteMatch::HISTORY_BODY:
114 return OmniboxEventProto::Suggestion::HISTORY_BODY;
115 case AutocompleteMatch::HISTORY_KEYWORD:
116 return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
117 case AutocompleteMatch::NAVSUGGEST:
118 return OmniboxEventProto::Suggestion::NAVSUGGEST;
119 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
120 return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
121 case AutocompleteMatch::SEARCH_HISTORY:
122 return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
123 case AutocompleteMatch::SEARCH_SUGGEST:
124 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
125 case AutocompleteMatch::SEARCH_OTHER_ENGINE:
126 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
127 case AutocompleteMatch::EXTENSION_APP:
128 return OmniboxEventProto::Suggestion::EXTENSION_APP;
[email protected]dbacefb2012-09-12 03:32:06129 case AutocompleteMatch::CONTACT:
130 return OmniboxEventProto::Suggestion::CONTACT;
[email protected]25320602012-10-18 22:05:56131 case AutocompleteMatch::BOOKMARK_TITLE:
132 return OmniboxEventProto::Suggestion::BOOKMARK_TITLE;
[email protected]fe58acc22012-02-29 01:29:58133 default:
134 NOTREACHED();
135 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
136 }
137}
138
[email protected]ed0fd002012-04-25 23:10:34139ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType(
140 content::ProcessType process_type) {
141 switch (process_type) {
142 case content::PROCESS_TYPE_BROWSER:
143 return ProfilerEventProto::TrackedObject::BROWSER;
144 case content::PROCESS_TYPE_RENDERER:
145 return ProfilerEventProto::TrackedObject::RENDERER;
146 case content::PROCESS_TYPE_PLUGIN:
147 return ProfilerEventProto::TrackedObject::PLUGIN;
148 case content::PROCESS_TYPE_WORKER:
149 return ProfilerEventProto::TrackedObject::WORKER;
150 case content::PROCESS_TYPE_NACL_LOADER:
151 return ProfilerEventProto::TrackedObject::NACL_LOADER;
152 case content::PROCESS_TYPE_UTILITY:
153 return ProfilerEventProto::TrackedObject::UTILITY;
154 case content::PROCESS_TYPE_PROFILE_IMPORT:
155 return ProfilerEventProto::TrackedObject::PROFILE_IMPORT;
156 case content::PROCESS_TYPE_ZYGOTE:
157 return ProfilerEventProto::TrackedObject::ZYGOTE;
158 case content::PROCESS_TYPE_SANDBOX_HELPER:
159 return ProfilerEventProto::TrackedObject::SANDBOX_HELPER;
160 case content::PROCESS_TYPE_NACL_BROKER:
161 return ProfilerEventProto::TrackedObject::NACL_BROKER;
162 case content::PROCESS_TYPE_GPU:
163 return ProfilerEventProto::TrackedObject::GPU;
164 case content::PROCESS_TYPE_PPAPI_PLUGIN:
165 return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN;
166 case content::PROCESS_TYPE_PPAPI_BROKER:
167 return ProfilerEventProto::TrackedObject::PPAPI_BROKER;
168 default:
169 NOTREACHED();
170 return ProfilerEventProto::TrackedObject::UNKNOWN;
171 }
172}
173
[email protected]1df44b72012-01-19 05:20:34174// Returns the plugin preferences corresponding for this user, if available.
175// If multiple user profiles are loaded, returns the preferences corresponding
176// to an arbitrary one of the profiles.
177PluginPrefs* GetPluginPrefs() {
178 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]fe58acc22012-02-29 01:29:58179
180 if (!profile_manager) {
181 // The profile manager can be NULL when testing.
182 return NULL;
183 }
184
[email protected]1df44b72012-01-19 05:20:34185 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
186 if (profiles.empty())
187 return NULL;
188
189 return PluginPrefs::GetForProfile(profiles.front());
190}
191
[email protected]fe58acc22012-02-29 01:29:58192// Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
193void SetPluginInfo(const webkit::WebPluginInfo& plugin_info,
194 const PluginPrefs* plugin_prefs,
195 SystemProfileProto::Plugin* plugin) {
196 plugin->set_name(UTF16ToUTF8(plugin_info.name));
197 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
198 plugin->set_version(UTF16ToUTF8(plugin_info.version));
199 if (plugin_prefs)
200 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
201}
202
[email protected]0c8b7ad2012-11-06 07:08:14203void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids,
[email protected]767c9d92012-03-02 16:04:34204 SystemProfileProto* system_profile) {
[email protected]0c8b7ad2012-11-06 07:08:14205 for (std::vector<ActiveGroupId>::const_iterator it =
[email protected]ad2461c2012-04-27 21:11:03206 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
[email protected]767c9d92012-03-02 16:04:34207 SystemProfileProto::FieldTrial* field_trial =
208 system_profile->add_field_trial();
209 field_trial->set_name_id(it->name);
210 field_trial->set_group_id(it->group);
211 }
212}
213
[email protected]ed0fd002012-04-25 23:10:34214void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
215 content::ProcessType process_type,
216 ProfilerEventProto* performance_profile) {
217 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it =
218 profiler_data.tasks.begin();
219 it != profiler_data.tasks.end(); ++it) {
220 std::string ignored;
221 uint64 birth_thread_name_hash;
222 uint64 exec_thread_name_hash;
223 uint64 source_file_name_hash;
224 uint64 source_function_name_hash;
225 MetricsLogBase::CreateHashes(it->birth.thread_name,
226 &ignored, &birth_thread_name_hash);
227 MetricsLogBase::CreateHashes(it->death_thread_name,
228 &ignored, &exec_thread_name_hash);
[email protected]ed0fd002012-04-25 23:10:34229 MetricsLogBase::CreateHashes(it->birth.location.file_name,
[email protected]04162262012-10-23 01:17:25230 &ignored, &source_file_name_hash);
231 MetricsLogBase::CreateHashes(it->birth.location.function_name,
[email protected]ed0fd002012-04-25 23:10:34232 &ignored, &source_function_name_hash);
233
234 const tracked_objects::DeathDataSnapshot& death_data = it->death_data;
235 ProfilerEventProto::TrackedObject* tracked_object =
236 performance_profile->add_tracked_object();
237 tracked_object->set_birth_thread_name_hash(birth_thread_name_hash);
238 tracked_object->set_exec_thread_name_hash(exec_thread_name_hash);
239 tracked_object->set_source_file_name_hash(source_file_name_hash);
240 tracked_object->set_source_function_name_hash(source_function_name_hash);
241 tracked_object->set_source_line_number(it->birth.location.line_number);
242 tracked_object->set_exec_count(death_data.count);
243 tracked_object->set_exec_time_total(death_data.run_duration_sum);
244 tracked_object->set_exec_time_sampled(death_data.run_duration_sample);
245 tracked_object->set_queue_time_total(death_data.queue_duration_sum);
246 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample);
247 tracked_object->set_process_type(AsProtobufProcessType(process_type));
248 tracked_object->set_process_id(profiler_data.process_id);
249 }
250}
251
[email protected]59a7ae4e2012-10-01 23:54:44252#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
[email protected]197c0772012-05-14 23:50:51253void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data,
254 ProductInfo* product_info) {
255 product_info->set_version(product_data.version);
256 product_info->set_last_update_success_timestamp(
257 product_data.last_success.ToTimeT());
258 product_info->set_last_error(product_data.last_error_code);
259 product_info->set_last_extra_error(product_data.last_extra_code);
260 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) {
261 product_info->set_last_result(
262 static_cast<ProductInfo::InstallResult>(product_data.last_result));
263 }
264}
[email protected]59a7ae4e2012-10-01 23:54:44265#endif
[email protected]197c0772012-05-14 23:50:51266
[email protected]76869ff2013-01-15 16:13:47267#if defined(OS_WIN)
268struct ScreenDPIInformation{
269 double max_dpi_x;
270 double max_dpi_y;
271};
272
273// Called once for each connected monitor.
274BOOL CALLBACK GetMonitorDPICallback(HMONITOR, HDC hdc, LPRECT, LPARAM dwData) {
275 const double kMillimetersPerInch = 25.4;
276 ScreenDPIInformation* screen_info =
277 reinterpret_cast<ScreenDPIInformation*>(dwData);
278 // Size of screen, in mm.
279 DWORD size_x = GetDeviceCaps(hdc, HORZSIZE);
280 DWORD size_y = GetDeviceCaps(hdc, VERTSIZE);
281 double dpi_x = (size_x > 0) ?
282 GetDeviceCaps(hdc, HORZRES) / (size_x / kMillimetersPerInch) : 0;
283 double dpi_y = (size_y > 0) ?
284 GetDeviceCaps(hdc, VERTRES) / (size_y / kMillimetersPerInch) : 0;
285 screen_info->max_dpi_x = std::max(dpi_x, screen_info->max_dpi_x);
286 screen_info->max_dpi_y = std::max(dpi_y, screen_info->max_dpi_y);
287 return TRUE;
288}
289
290void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) {
291 HDC desktop_dc = GetDC(NULL);
292 if (desktop_dc) {
293 ScreenDPIInformation si = {0,0};
294 if (EnumDisplayMonitors(desktop_dc, NULL, GetMonitorDPICallback,
295 reinterpret_cast<LPARAM>(&si))) {
296 hardware->set_max_dpi_x(si.max_dpi_x);
297 hardware->set_max_dpi_y(si.max_dpi_y);
298 }
299 ReleaseDC(GetDesktopWindow(), desktop_dc);
300 }
301}
302
303#endif // defined(OS_WIN)
304
[email protected]1df44b72012-01-19 05:20:34305} // namespace
306
[email protected]197c0772012-05-14 23:50:51307GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {}
308
309GoogleUpdateMetrics::~GoogleUpdateMetrics() {}
310
[email protected]67f92bc32012-01-26 01:56:19311static base::LazyInstance<std::string>::Leaky
[email protected]054c8012011-11-16 00:12:42312 g_version_extension = LAZY_INSTANCE_INITIALIZER;
313
[email protected]1226abb2010-06-10 18:01:28314MetricsLog::MetricsLog(const std::string& client_id, int session_id)
315 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:41316
[email protected]1226abb2010-06-10 18:01:28317MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:29318
319// static
[email protected]5b199522012-12-22 17:24:44320void MetricsLog::RegisterPrefs(PrefServiceSimple* local_state) {
initial.commit09911bf2008-07-26 23:55:29321 local_state->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29322}
323
[email protected]1df44b72012-01-19 05:20:34324// static
[email protected]9165f742010-03-10 22:55:01325int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
326 base::TimeTicks now = base::TimeTicks::Now();
327 static base::TimeTicks last_updated_time(now);
328 int64 incremental_time = (now - last_updated_time).InSeconds();
329 last_updated_time = now;
330
331 if (incremental_time > 0) {
332 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
333 metrics_uptime += incremental_time;
334 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
335 }
336
337 return incremental_time;
338}
339
[email protected]1226abb2010-06-10 18:01:28340// static
341std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:42342 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:17343 if (!version_info.is_valid()) {
344 NOTREACHED() << "Unable to retrieve version info.";
345 return std::string();
346 }
347
[email protected]0211f57e2010-08-27 20:28:42348 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:42349 if (!version_extension().empty())
350 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:42351 if (!version_info.IsOfficialBuild())
352 version.append("-devel");
353 return version;
[email protected]1226abb2010-06-10 18:01:28354}
355
[email protected]054c8012011-11-16 00:12:42356// static
357void MetricsLog::set_version_extension(const std::string& extension) {
358 g_version_extension.Get() = extension;
359}
360
361// static
362const std::string& MetricsLog::version_extension() {
363 return g_version_extension.Get();
364}
365
[email protected]fe58acc22012-02-29 01:29:58366void MetricsLog::RecordIncrementalStabilityElements(
367 const std::vector<webkit::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34368 DCHECK(!locked());
[email protected]0b33f80b2008-12-17 21:34:36369
[email protected]767c9d92012-03-02 16:04:34370 PrefService* pref = GetPrefService();
[email protected]0b33f80b2008-12-17 21:34:36371 DCHECK(pref);
372
[email protected]147bbc0b2009-01-06 19:37:40373 OPEN_ELEMENT_FOR_SCOPE("profile");
374 WriteCommonEventAttributes();
375
[email protected]9958a322011-03-08 20:04:17376 WriteInstallElement();
[email protected]147bbc0b2009-01-06 19:37:40377
378 {
379 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
380 WriteRequiredStabilityAttributes(pref);
381 WriteRealtimeStabilityAttributes(pref);
[email protected]fe58acc22012-02-29 01:29:58382 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40383 }
[email protected]0b33f80b2008-12-17 21:34:36384}
385
[email protected]767c9d92012-03-02 16:04:34386PrefService* MetricsLog::GetPrefService() {
387 return g_browser_process->local_state();
388}
389
390gfx::Size MetricsLog::GetScreenSize() const {
[email protected]ffabb1e2012-10-12 19:51:17391 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel();
[email protected]767c9d92012-03-02 16:04:34392}
393
[email protected]aa96417972012-08-22 03:16:44394float MetricsLog::GetScreenDeviceScaleFactor() const {
[email protected]ffabb1e2012-10-12 19:51:17395 return gfx::Screen::GetNativeScreen()->
396 GetPrimaryDisplay().device_scale_factor();
[email protected]aa96417972012-08-22 03:16:44397}
398
[email protected]767c9d92012-03-02 16:04:34399int MetricsLog::GetScreenCount() const {
[email protected]ffabb1e2012-10-12 19:51:17400 // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312
401 return gfx::Screen::GetNativeScreen()->GetNumDisplays();
[email protected]767c9d92012-03-02 16:04:34402}
403
[email protected]767c9d92012-03-02 16:04:34404void MetricsLog::GetFieldTrialIds(
[email protected]0c8b7ad2012-11-06 07:08:14405 std::vector<ActiveGroupId>* field_trial_ids) const {
406 chrome_variations::GetFieldTrialActiveGroupIds(field_trial_ids);
[email protected]767c9d92012-03-02 16:04:34407}
408
[email protected]fe58acc22012-02-29 01:29:58409void MetricsLog::WriteStabilityElement(
410 const std::vector<webkit::WebPluginInfo>& plugin_list,
411 PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:34412 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29413
initial.commit09911bf2008-07-26 23:55:29414 // Get stability attributes out of Local State, zeroing out stored values.
415 // NOTE: This could lead to some data loss if this report isn't successfully
416 // sent, but that's true for all the metrics.
417
[email protected]ffaf78a2008-11-12 17:38:33418 OPEN_ELEMENT_FOR_SCOPE("stability");
[email protected]147bbc0b2009-01-06 19:37:40419 WriteRequiredStabilityAttributes(pref);
420 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29421
[email protected]fe58acc22012-02-29 01:29:58422 int incomplete_shutdown_count =
423 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
[email protected]e324f6b2012-02-28 05:43:37424 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58425 int breakpad_registration_success_count =
426 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
[email protected]e324f6b2012-02-28 05:43:37427 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58428 int breakpad_registration_failure_count =
429 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
[email protected]e324f6b2012-02-28 05:43:37430 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58431 int debugger_present_count =
432 pref->GetInteger(prefs::kStabilityDebuggerPresent);
[email protected]e324f6b2012-02-28 05:43:37433 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58434 int debugger_not_present_count =
435 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
[email protected]e324f6b2012-02-28 05:43:37436 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31437
[email protected]fe58acc22012-02-29 01:29:58438 // TODO(jar): The following are all optional, so we *could* optimize them for
439 // values of zero (and not include them).
440
441 // Write the XML version.
442 WriteIntAttribute("incompleteshutdowncount", incomplete_shutdown_count);
443 WriteIntAttribute("breakpadregistrationok",
444 breakpad_registration_success_count);
445 WriteIntAttribute("breakpadregistrationfail",
446 breakpad_registration_failure_count);
447 WriteIntAttribute("debuggerpresent", debugger_present_count);
448 WriteIntAttribute("debuggernotpresent", debugger_not_present_count);
449
450 // Write the protobuf version.
451 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34452 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58453 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
454 stability->set_breakpad_registration_success_count(
455 breakpad_registration_success_count);
456 stability->set_breakpad_registration_failure_count(
457 breakpad_registration_failure_count);
458 stability->set_debugger_present_count(debugger_present_count);
459 stability->set_debugger_not_present_count(debugger_not_present_count);
460
461 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40462}
463
[email protected]fe58acc22012-02-29 01:29:58464void MetricsLog::WritePluginStabilityElements(
465 const std::vector<webkit::WebPluginInfo>& plugin_list,
466 PrefService* pref) {
[email protected]147bbc0b2009-01-06 19:37:40467 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29468 const ListValue* plugin_stats_list = pref->GetList(
469 prefs::kStabilityPluginStats);
[email protected]1df44b72012-01-19 05:20:34470 if (!plugin_stats_list)
471 return;
initial.commit09911bf2008-07-26 23:55:29472
[email protected]1df44b72012-01-19 05:20:34473 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]ebd71962012-12-20 02:56:55474
475#if defined(ENABLE_PLUGINS)
[email protected]fe58acc22012-02-29 01:29:58476 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34477 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58478 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]1df44b72012-01-19 05:20:34479 for (ListValue::const_iterator iter = plugin_stats_list->begin();
480 iter != plugin_stats_list->end(); ++iter) {
481 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
482 NOTREACHED();
483 continue;
initial.commit09911bf2008-07-26 23:55:29484 }
[email protected]1df44b72012-01-19 05:20:34485 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29486
[email protected]1df44b72012-01-19 05:20:34487 std::string plugin_name;
488 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
489
[email protected]fe58acc22012-02-29 01:29:58490 std::string base64_name_hash;
491 uint64 numeric_name_hash_ignored;
492 CreateHashes(plugin_name, &base64_name_hash, &numeric_name_hash_ignored);
493
494 // Write the XML verison.
[email protected]1df44b72012-01-19 05:20:34495 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
496 // Use "filename" instead of "name", otherwise we need to update the
497 // UMA servers.
[email protected]fe58acc22012-02-29 01:29:58498 WriteAttribute("filename", base64_name_hash);
[email protected]1df44b72012-01-19 05:20:34499
500 int launches = 0;
501 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
502 WriteIntAttribute("launchcount", launches);
503
504 int instances = 0;
505 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
506 WriteIntAttribute("instancecount", instances);
507
508 int crashes = 0;
509 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
510 WriteIntAttribute("crashcount", crashes);
[email protected]fe58acc22012-02-29 01:29:58511
512 // Write the protobuf version.
513 // Note that this search is potentially a quadratic operation, but given the
514 // low number of plugins installed on a "reasonable" setup, this should be
515 // fine.
516 // TODO(isherman): Verify that this does not show up as a hotspot in
517 // profiler runs.
518 const webkit::WebPluginInfo* plugin_info = NULL;
519 const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name);
520 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
521 plugin_list.begin();
522 iter != plugin_list.end(); ++iter) {
523 if (iter->name == plugin_name_utf16) {
524 plugin_info = &(*iter);
525 break;
526 }
527 }
528
529 if (!plugin_info) {
530 NOTREACHED();
531 continue;
532 }
[email protected]cd937072012-07-02 09:00:29533 int loading_errors = 0;
534 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors,
535 &loading_errors);
536 WriteIntAttribute("loadingerrorcount", loading_errors);
[email protected]fe58acc22012-02-29 01:29:58537
[email protected]cd937072012-07-02 09:00:29538 // Write the protobuf version.
[email protected]fe58acc22012-02-29 01:29:58539 SystemProfileProto::Stability::PluginStability* plugin_stability =
540 stability->add_plugin_stability();
541 SetPluginInfo(*plugin_info, plugin_prefs,
542 plugin_stability->mutable_plugin());
543 plugin_stability->set_launch_count(launches);
544 plugin_stability->set_instance_count(instances);
545 plugin_stability->set_crash_count(crashes);
[email protected]cd937072012-07-02 09:00:29546 plugin_stability->set_loading_error_count(loading_errors);
initial.commit09911bf2008-07-26 23:55:29547 }
[email protected]ebd71962012-12-20 02:56:55548#endif // defined(ENABLE_PLUGINS)
[email protected]1df44b72012-01-19 05:20:34549
550 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29551}
552
[email protected]fe58acc22012-02-29 01:29:58553// The server refuses data that doesn't have certain values. crashcount and
554// launchcount are currently "required" in the "stability" group.
555// TODO(isherman): Stop writing these attributes specially once the migration to
556// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40557void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]fe58acc22012-02-29 01:29:58558 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
[email protected]0b33f80b2008-12-17 21:34:36559 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
[email protected]fe58acc22012-02-29 01:29:58560 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
[email protected]0b33f80b2008-12-17 21:34:36561 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58562
563 // Write the XML version.
564 WriteIntAttribute("launchcount", launch_count);
565 WriteIntAttribute("crashcount", crash_count);
566
567 // Write the protobuf version.
568 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34569 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58570 stability->set_launch_count(launch_count);
571 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36572}
573
[email protected]147bbc0b2009-01-06 19:37:40574void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36575 // Update the stats which are critical for real-time stability monitoring.
576 // Since these are "optional," only list ones that are non-zero, as the counts
577 // are aggergated (summed) server side.
578
[email protected]fe58acc22012-02-29 01:29:58579 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34580 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36581 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
582 if (count) {
583 WriteIntAttribute("pageloadcount", count);
[email protected]fe58acc22012-02-29 01:29:58584 stability->set_page_load_count(count);
[email protected]0b33f80b2008-12-17 21:34:36585 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
586 }
587
588 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
589 if (count) {
590 WriteIntAttribute("renderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58591 stability->set_renderer_crash_count(count);
[email protected]0b33f80b2008-12-17 21:34:36592 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
593 }
594
[email protected]1f085622009-12-04 05:33:45595 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
596 if (count) {
597 WriteIntAttribute("extensionrenderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58598 stability->set_extension_renderer_crash_count(count);
[email protected]1f085622009-12-04 05:33:45599 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
600 }
601
[email protected]0b33f80b2008-12-17 21:34:36602 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
603 if (count) {
604 WriteIntAttribute("rendererhangcount", count);
[email protected]fe58acc22012-02-29 01:29:58605 stability->set_renderer_hang_count(count);
[email protected]0b33f80b2008-12-17 21:34:36606 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
607 }
[email protected]1f085622009-12-04 05:33:45608
609 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
610 if (count) {
611 WriteIntAttribute("childprocesscrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58612 stability->set_child_process_crash_count(count);
[email protected]1f085622009-12-04 05:33:45613 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
614 }
[email protected]9165f742010-03-10 22:55:01615
[email protected]c1834a92011-01-21 18:21:03616#if defined(OS_CHROMEOS)
617 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
618 if (count) {
[email protected]fe58acc22012-02-29 01:29:58619 stability->set_other_user_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03620 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
621 }
622
623 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
624 if (count) {
[email protected]fe58acc22012-02-29 01:29:58625 stability->set_kernel_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03626 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
627 }
628
629 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
630 if (count) {
[email protected]fe58acc22012-02-29 01:29:58631 stability->set_unclean_system_shutdown_count(count);
[email protected]c1834a92011-01-21 18:21:03632 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
633 }
634#endif // OS_CHROMEOS
635
[email protected]9165f742010-03-10 22:55:01636 int64 recent_duration = GetIncrementalUptime(pref);
[email protected]fe58acc22012-02-29 01:29:58637 if (recent_duration) {
[email protected]9165f742010-03-10 22:55:01638 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]fe58acc22012-02-29 01:29:58639 stability->set_uptime_sec(recent_duration);
640 }
[email protected]0b33f80b2008-12-17 21:34:36641}
642
initial.commit09911bf2008-07-26 23:55:29643void MetricsLog::WritePluginList(
[email protected]bc66d532012-03-23 01:57:05644 const std::vector<webkit::WebPluginInfo>& plugin_list,
645 bool write_as_xml) {
[email protected]767c9d92012-03-02 16:04:34646 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29647
[email protected]ffaf78a2008-11-12 17:38:33648 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]ebd71962012-12-20 02:56:55649
650#if defined(ENABLE_PLUGINS)
651 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]767c9d92012-03-02 16:04:34652 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]91d9f3d2011-08-14 05:24:44653 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50654 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29655 iter != plugin_list.end(); ++iter) {
[email protected]bc66d532012-03-23 01:57:05656 if (write_as_xml) {
657 std::string base64_name_hash;
658 uint64 numeric_hash_ignored;
659 CreateHashes(UTF16ToUTF8(iter->name), &base64_name_hash,
660 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58661
[email protected]bc66d532012-03-23 01:57:05662 std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe();
663 std::string base64_filename_hash;
664 CreateHashes(filename_bytes, &base64_filename_hash,
665 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58666
[email protected]bc66d532012-03-23 01:57:05667 // Write the XML version.
668 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29669
[email protected]bc66d532012-03-23 01:57:05670 // Plugin name and filename are hashed for the privacy of those
671 // testing unreleased new extensions.
672 WriteAttribute("name", base64_name_hash);
673 WriteAttribute("filename", base64_filename_hash);
674 WriteAttribute("version", UTF16ToUTF8(iter->version));
675 if (plugin_prefs)
676 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
677 } else {
678 // Write the protobuf version.
679 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
680 SetPluginInfo(*iter, plugin_prefs, plugin);
681 }
initial.commit09911bf2008-07-26 23:55:29682 }
[email protected]ebd71962012-12-20 02:56:55683#endif // defined(ENABLE_PLUGINS)
initial.commit09911bf2008-07-26 23:55:29684}
685
[email protected]147bbc0b2009-01-06 19:37:40686void MetricsLog::WriteInstallElement() {
[email protected]fe58acc22012-02-29 01:29:58687 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05688 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]147bbc0b2009-01-06 19:37:40689 OPEN_ELEMENT_FOR_SCOPE("install");
[email protected]cc5d7f42012-10-30 00:30:09690 WriteAttribute("installdate", GetMetricsEnabledDate(GetPrefService()));
[email protected]147bbc0b2009-01-06 19:37:40691 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40692}
693
initial.commit09911bf2008-07-26 23:55:29694void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44695 const std::vector<webkit::WebPluginInfo>& plugin_list,
[email protected]197c0772012-05-14 23:50:51696 const GoogleUpdateMetrics& google_update_metrics,
initial.commit09911bf2008-07-26 23:55:29697 const DictionaryValue* profile_metrics) {
[email protected]767c9d92012-03-02 16:04:34698 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29699
[email protected]767c9d92012-03-02 16:04:34700 PrefService* pref = GetPrefService();
initial.commit09911bf2008-07-26 23:55:29701
[email protected]ffaf78a2008-11-12 17:38:33702 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29703 WriteCommonEventAttributes();
704
[email protected]147bbc0b2009-01-06 19:37:40705 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29706
[email protected]bc66d532012-03-23 01:57:05707 // Write the XML version.
708 // We'll write the protobuf version in RecordEnvironmentProto().
709 bool write_as_xml = true;
710 WritePluginList(plugin_list, write_as_xml);
initial.commit09911bf2008-07-26 23:55:29711
[email protected]fe58acc22012-02-29 01:29:58712 WriteStabilityElement(plugin_list, pref);
initial.commit09911bf2008-07-26 23:55:29713
714 {
[email protected]fe58acc22012-02-29 01:29:58715 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05716 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29717 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]0b6a4fb2012-10-16 01:58:21718 WriteAttribute("arch", base::SysInfo::OperatingSystemArchitecture());
initial.commit09911bf2008-07-26 23:55:29719 }
720
721 {
[email protected]fe58acc22012-02-29 01:29:58722 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05723 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29724 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]bc66d532012-03-23 01:57:05725 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38726#if defined(OS_WIN)
727 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
728#endif
initial.commit09911bf2008-07-26 23:55:29729 }
730
731 {
[email protected]fe58acc22012-02-29 01:29:58732 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05733 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29734 OPEN_ELEMENT_FOR_SCOPE("os");
[email protected]bc66d532012-03-23 01:57:05735 WriteAttribute("name", base::SysInfo::OperatingSystemName());
736 WriteAttribute("version", base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29737 }
738
739 {
[email protected]e8c287c872010-07-20 00:49:42740 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]fe58acc22012-02-29 01:29:58741 const content::GPUInfo& gpu_info =
742 GpuDataManager::GetInstance()->GetGPUInfo();
[email protected]fe58acc22012-02-29 01:29:58743
744 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05745 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]a094e2c2012-05-10 23:02:42746 WriteIntAttribute("vendorid", gpu_info.gpu.vendor_id);
747 WriteIntAttribute("deviceid", gpu_info.gpu.device_id);
[email protected]e8c287c872010-07-20 00:49:42748 }
749
750 {
[email protected]767c9d92012-03-02 16:04:34751 const gfx::Size display_size = GetScreenSize();
[email protected]fe58acc22012-02-29 01:29:58752
753 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05754 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]fe58acc22012-02-29 01:29:58755 OPEN_ELEMENT_FOR_SCOPE("display");
[email protected]bc66d532012-03-23 01:57:05756 WriteIntAttribute("xsize", display_size.width());
757 WriteIntAttribute("ysize", display_size.height());
758 WriteIntAttribute("screens", GetScreenCount());
initial.commit09911bf2008-07-26 23:55:29759 }
760
761 {
762 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
763 int num_bookmarks_on_bookmark_bar =
764 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
765 int num_folders_on_bookmark_bar =
766 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
767 int num_bookmarks_in_other_bookmarks_folder =
768 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
769 int num_folders_in_other_bookmarks_folder =
770 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
771 {
772 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
773 WriteAttribute("name", "full-tree");
774 WriteIntAttribute("foldercount",
775 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
776 WriteIntAttribute("itemcount",
777 num_bookmarks_on_bookmark_bar +
778 num_bookmarks_in_other_bookmarks_folder);
779 }
780 {
781 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
782 WriteAttribute("name", "toolbar");
783 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
784 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
785 }
786 }
787
788 {
789 OPEN_ELEMENT_FOR_SCOPE("keywords");
790 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
791 }
792
793 if (profile_metrics)
794 WriteAllProfilesMetrics(*profile_metrics);
[email protected]767c9d92012-03-02 16:04:34795
[email protected]197c0772012-05-14 23:50:51796 RecordEnvironmentProto(plugin_list, google_update_metrics);
[email protected]bc66d532012-03-23 01:57:05797}
798
799void MetricsLog::RecordEnvironmentProto(
[email protected]197c0772012-05-14 23:50:51800 const std::vector<webkit::WebPluginInfo>& plugin_list,
801 const GoogleUpdateMetrics& google_update_metrics) {
[email protected]bc66d532012-03-23 01:57:05802 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]cc5d7f42012-10-30 00:30:09803 int enabled_date;
804 bool success = base::StringToInt(GetMetricsEnabledDate(GetPrefService()),
805 &enabled_date);
[email protected]bc66d532012-03-23 01:57:05806 DCHECK(success);
[email protected]cc5d7f42012-10-30 00:30:09807 system_profile->set_uma_enabled_date(enabled_date);
[email protected]bc66d532012-03-23 01:57:05808
809 system_profile->set_application_locale(
810 content::GetContentClient()->browser()->GetApplicationLocale());
811
812 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
[email protected]0b6a4fb2012-10-16 01:58:21813 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
[email protected]bc66d532012-03-23 01:57:05814 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
815#if defined(OS_WIN)
816 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
817#endif
818
819 SystemProfileProto::OS* os = system_profile->mutable_os();
[email protected]1bb25e02012-08-03 22:39:39820 std::string os_name = base::SysInfo::OperatingSystemName();
821#if defined(OS_WIN)
822 // TODO(mad): This only checks whether the main process is a Metro process at
823 // upload time; not whether the collected metrics were all gathered from
824 // Metro. This is ok as an approximation for now, since users will rarely be
825 // switching from Metro to Desktop mode; but we should re-evaluate whether we
826 // can distinguish metrics more cleanly in the future: http://crbug.com/140568
827 if (base::win::IsMetroProcess())
828 os_name += " (Metro)";
829#endif
830 os->set_name(os_name);
[email protected]bc66d532012-03-23 01:57:05831 os->set_version(base::SysInfo::OperatingSystemVersion());
[email protected]5106b3a2012-10-03 20:10:44832#if defined(OS_ANDROID)
833 os->set_fingerprint(
834 base::android::BuildInfo::GetInstance()->android_build_fp());
835#endif
[email protected]bc66d532012-03-23 01:57:05836
837 const content::GPUInfo& gpu_info =
838 GpuDataManager::GetInstance()->GetGPUInfo();
839 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
[email protected]a094e2c2012-05-10 23:02:42840 gpu->set_vendor_id(gpu_info.gpu.vendor_id);
841 gpu->set_device_id(gpu_info.gpu.device_id);
[email protected]bc66d532012-03-23 01:57:05842 gpu->set_driver_version(gpu_info.driver_version);
843 gpu->set_driver_date(gpu_info.driver_date);
844 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
845 gpu_performance = gpu->mutable_performance_statistics();
846 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
847 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
848 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
849
850 const gfx::Size display_size = GetScreenSize();
851 hardware->set_primary_screen_width(display_size.width());
852 hardware->set_primary_screen_height(display_size.height());
[email protected]aa96417972012-08-22 03:16:44853 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor());
[email protected]bc66d532012-03-23 01:57:05854 hardware->set_screen_count(GetScreenCount());
855
[email protected]76869ff2013-01-15 16:13:47856#if defined(OS_WIN)
857 WriteScreenDPIInformationProto(hardware);
858#endif
859
[email protected]197c0772012-05-14 23:50:51860 WriteGoogleUpdateProto(google_update_metrics);
861
[email protected]bc66d532012-03-23 01:57:05862 bool write_as_xml = false;
863 WritePluginList(plugin_list, write_as_xml);
864
[email protected]0c8b7ad2012-11-06 07:08:14865 std::vector<ActiveGroupId> field_trial_ids;
[email protected]767c9d92012-03-02 16:04:34866 GetFieldTrialIds(&field_trial_ids);
867 WriteFieldTrials(field_trial_ids, system_profile);
initial.commit09911bf2008-07-26 23:55:29868}
869
[email protected]ed0fd002012-04-25 23:10:34870void MetricsLog::RecordProfilerData(
871 const tracked_objects::ProcessDataSnapshot& process_data,
872 content::ProcessType process_type) {
873 DCHECK(!locked());
874
[email protected]8f829682012-04-27 00:36:49875 if (tracked_objects::GetTimeSourceType() !=
876 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) {
[email protected]ed0fd002012-04-25 23:10:34877 // We currently only support the default time source, wall clock time.
878 return;
879 }
880
881 ProfilerEventProto* profile;
882 if (!uma_proto()->profiler_event_size()) {
883 // For the first process's data, add a new field to the protocol buffer.
884 profile = uma_proto()->add_profiler_event();
885 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
886 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
887 } else {
888 // For the remaining calls, re-use the existing field.
889 profile = uma_proto()->mutable_profiler_event(0);
890 }
891
892 WriteProfilerData(process_data, process_type, profile);
893}
894
initial.commit09911bf2008-07-26 23:55:29895void MetricsLog::WriteAllProfilesMetrics(
896 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51897 const std::string profile_prefix(prefs::kProfilePrefix);
initial.commit09911bf2008-07-26 23:55:29898 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
899 i != all_profiles_metrics.end_keys(); ++i) {
[email protected]e7b418b2010-07-30 19:47:47900 const std::string& key_name = *i;
initial.commit09911bf2008-07-26 23:55:29901 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
[email protected]a61890e2012-07-27 22:27:11902 const DictionaryValue* profile;
[email protected]4dad9ad82009-11-25 20:47:52903 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
904 &profile))
initial.commit09911bf2008-07-26 23:55:29905 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
906 }
907 }
908}
909
[email protected]e7b418b2010-07-30 19:47:47910void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29911 const DictionaryValue& profile_metrics) {
912 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47913 WriteAttribute("profileidhash", profileidhash);
initial.commit09911bf2008-07-26 23:55:29914 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
915 i != profile_metrics.end_keys(); ++i) {
[email protected]a61890e2012-07-27 22:27:11916 const Value* value;
[email protected]4dad9ad82009-11-25 20:47:52917 if (profile_metrics.GetWithoutPathExpansion(*i, &value)) {
[email protected]0b6a4fb2012-10-16 01:58:21918 DCHECK_NE(*i, "id");
initial.commit09911bf2008-07-26 23:55:29919 switch (value->GetType()) {
920 case Value::TYPE_STRING: {
[email protected]5e324b72008-12-18 00:07:59921 std::string string_value;
initial.commit09911bf2008-07-26 23:55:29922 if (value->GetAsString(&string_value)) {
923 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47924 WriteAttribute("name", *i);
[email protected]5e324b72008-12-18 00:07:59925 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29926 }
927 break;
928 }
929
930 case Value::TYPE_BOOLEAN: {
931 bool bool_value;
932 if (value->GetAsBoolean(&bool_value)) {
933 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47934 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29935 WriteIntAttribute("value", bool_value ? 1 : 0);
936 }
937 break;
938 }
939
940 case Value::TYPE_INTEGER: {
941 int int_value;
942 if (value->GetAsInteger(&int_value)) {
943 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47944 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29945 WriteIntAttribute("value", int_value);
946 }
947 break;
948 }
949
950 default:
951 NOTREACHED();
952 break;
953 }
954 }
955 }
956}
957
958void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
[email protected]767c9d92012-03-02 16:04:34959 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29960
[email protected]fe58acc22012-02-29 01:29:58961 // Write the XML version.
[email protected]ffaf78a2008-11-12 17:38:33962 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29963 WriteAttribute("action", "autocomplete");
964 WriteAttribute("targetidhash", "");
965 // TODO(kochi): Properly track windows.
966 WriteIntAttribute("window", 0);
[email protected]6ebc3162011-12-19 13:44:00967 if (log.tab_id != -1) {
968 // If we know what tab the autocomplete URL was opened in, log it.
969 WriteIntAttribute("tab", static_cast<int>(log.tab_id));
970 }
initial.commit09911bf2008-07-26 23:55:29971 WriteCommonEventAttributes();
972
[email protected]65956312012-04-19 21:28:12973 std::vector<string16> terms;
974 const int num_terms =
975 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms));
[email protected]ffaf78a2008-11-12 17:38:33976 {
977 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29978
[email protected]ffaf78a2008-11-12 17:38:33979 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
[email protected]65956312012-04-19 21:28:12980 WriteIntAttribute("numterms", num_terms);
[email protected]ffaf78a2008-11-12 17:38:33981 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
982 WriteIntAttribute("completedlength",
[email protected]62b3ef52013-01-18 00:13:02983 log.completed_length != string16::npos ?
984 static_cast<int>(log.completed_length) : 0);
[email protected]9e349762012-01-31 03:24:36985 if (log.elapsed_time_since_user_first_modified_omnibox !=
986 base::TimeDelta::FromMilliseconds(-1)) {
987 // Only upload the typing duration if it is set/valid.
988 WriteInt64Attribute("typingduration",
989 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
990 }
[email protected]381e2992008-12-16 01:41:00991 const std::string input_type(
992 AutocompleteInput::TypeToString(log.input_type));
993 if (!input_type.empty())
994 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:29995
[email protected]ffaf78a2008-11-12 17:38:33996 for (AutocompleteResult::const_iterator i(log.result.begin());
997 i != log.result.end(); ++i) {
998 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
999 if (i->provider)
[email protected]35f1f4f02012-09-11 13:17:001000 WriteAttribute("provider", i->provider->GetName());
[email protected]381e2992008-12-16 01:41:001001 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
1002 if (!result_type.empty())
1003 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:331004 WriteIntAttribute("relevance", i->relevance);
1005 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
1006 }
initial.commit09911bf2008-07-26 23:55:291007 }
initial.commit09911bf2008-07-26 23:55:291008
[email protected]fe58acc22012-02-29 01:29:581009 // Write the protobuf version.
[email protected]767c9d92012-03-02 16:04:341010 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
[email protected]fe58acc22012-02-29 01:29:581011 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
1012 if (log.tab_id != -1) {
1013 // If we know what tab the autocomplete URL was opened in, log it.
1014 omnibox_event->set_tab_id(log.tab_id);
1015 }
1016 omnibox_event->set_typed_length(log.text.length());
[email protected]660fe8f32012-05-03 20:01:081017 omnibox_event->set_just_deleted_text(log.just_deleted_text);
[email protected]65956312012-04-19 21:28:121018 omnibox_event->set_num_typed_terms(num_terms);
[email protected]fe58acc22012-02-29 01:29:581019 omnibox_event->set_selected_index(log.selected_index);
[email protected]62b3ef52013-01-18 00:13:021020 if (log.completed_length != string16::npos)
1021 omnibox_event->set_completed_length(log.completed_length);
[email protected]65956312012-04-19 21:28:121022 if (log.elapsed_time_since_user_first_modified_omnibox !=
1023 base::TimeDelta::FromMilliseconds(-1)) {
1024 // Only upload the typing duration if it is set/valid.
1025 omnibox_event->set_typing_duration_ms(
1026 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
1027 }
[email protected]35d55602012-11-20 23:49:031028 omnibox_event->set_duration_since_last_default_match_update_ms(
1029 log.elapsed_time_since_last_change_to_default_match.InMilliseconds());
[email protected]ee902532012-05-01 23:54:491030 omnibox_event->set_current_page_classification(
1031 log.current_page_classification);
[email protected]fe58acc22012-02-29 01:29:581032 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
1033 for (AutocompleteResult::const_iterator i(log.result.begin());
1034 i != log.result.end(); ++i) {
1035 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
[email protected]0e9e8782012-05-15 23:01:511036 suggestion->set_provider(i->provider->AsOmniboxEventProviderType());
[email protected]fe58acc22012-02-29 01:29:581037 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
1038 suggestion->set_relevance(i->relevance);
[email protected]cf6256f2012-06-12 23:36:011039 if (i->typed_count != -1)
1040 suggestion->set_typed_count(i->typed_count);
[email protected]fe58acc22012-02-29 01:29:581041 suggestion->set_is_starred(i->starred);
1042 }
[email protected]0e9e8782012-05-15 23:01:511043 for (ProvidersInfo::const_iterator i(log.providers_info.begin());
1044 i != log.providers_info.end(); ++i) {
1045 OmniboxEventProto::ProviderInfo* provider_info =
1046 omnibox_event->add_provider_info();
1047 provider_info->CopyFrom(*i);
1048 }
[email protected]fe58acc22012-02-29 01:29:581049
initial.commit09911bf2008-07-26 23:55:291050 ++num_events_;
1051}
[email protected]197c0772012-05-14 23:50:511052
1053void MetricsLog::WriteGoogleUpdateProto(
1054 const GoogleUpdateMetrics& google_update_metrics) {
1055#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
1056 SystemProfileProto::GoogleUpdate* google_update =
1057 uma_proto()->mutable_system_profile()->mutable_google_update();
1058
1059 google_update->set_is_system_install(google_update_metrics.is_system_install);
1060
1061 if (!google_update_metrics.last_started_au.is_null()) {
1062 google_update->set_last_automatic_start_timestamp(
1063 google_update_metrics.last_started_au.ToTimeT());
1064 }
1065
1066 if (!google_update_metrics.last_checked.is_null()) {
1067 google_update->set_last_update_check_timestamp(
1068 google_update_metrics.last_checked.ToTimeT());
1069 }
1070
1071 if (!google_update_metrics.google_update_data.version.empty()) {
1072 ProductDataToProto(google_update_metrics.google_update_data,
1073 google_update->mutable_google_update_status());
1074 }
1075
1076 if (!google_update_metrics.product_data.version.empty()) {
1077 ProductDataToProto(google_update_metrics.product_data,
1078 google_update->mutable_client_status());
1079 }
1080#endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
1081}