blob: 72fff96f1905bb6e0fb9f8ab654c66fda7d99ef4 [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]3853a4c2013-02-11 17:15:5716#include "base/prefs/pref_registry_simple.h"
17#include "base/prefs/pref_service.h"
[email protected]ed0fd002012-04-25 23:10:3418#include "base/profiler/alternate_timer.h"
initial.commit09911bf2008-07-26 23:55:2919#include "base/string_util.h"
[email protected]3ea1b182013-02-08 22:38:4120#include "base/strings/string_number_conversions.h"
[email protected]fadf97f2008-09-18 12:18:1421#include "base/sys_info.h"
[email protected]37f39e42010-01-06 17:35:1722#include "base/third_party/nspr/prtime.h"
[email protected]1eeb5e02010-07-20 23:02:1123#include "base/time.h"
[email protected]ed0fd002012-04-25 23:10:3424#include "base/tracked_objects.h"
[email protected]1eeb5e02010-07-20 23:02:1125#include "base/utf_string_conversions.h"
[email protected]9f8bc2f2012-07-03 16:26:5326#include "chrome/browser/autocomplete/autocomplete_input.h"
[email protected]19871a92012-06-27 19:50:3227#include "chrome/browser/autocomplete/autocomplete_log.h"
[email protected]9ac40092010-10-27 23:05:2628#include "chrome/browser/autocomplete/autocomplete_match.h"
[email protected]30f5bc92012-06-26 04:14:5529#include "chrome/browser/autocomplete/autocomplete_provider.h"
[email protected]73c2b1632012-07-02 22:51:3830#include "chrome/browser/autocomplete/autocomplete_result.h"
initial.commit09911bf2008-07-26 23:55:2931#include "chrome/browser/browser_process.h"
[email protected]24b9bb392013-01-29 20:29:2932#include "chrome/browser/google/google_util.h"
[email protected]0f5e57f52012-09-20 20:53:1833#include "chrome/browser/plugins/plugin_prefs.h"
[email protected]10084982011-08-19 17:56:5634#include "chrome/browser/profiles/profile_manager.h"
[email protected]f3b357692013-03-22 05:16:1335#include "chrome/common/chrome_process_type.h"
[email protected]1eeb5e02010-07-20 23:02:1136#include "chrome/common/chrome_version_info.h"
initial.commit09911bf2008-07-26 23:55:2937#include "chrome/common/logging_chrome.h"
[email protected]fe58acc22012-02-29 01:29:5838#include "chrome/common/metrics/proto/omnibox_event.pb.h"
[email protected]ed0fd002012-04-25 23:10:3439#include "chrome/common/metrics/proto/profiler_event.pb.h"
[email protected]fe58acc22012-02-29 01:29:5840#include "chrome/common/metrics/proto/system_profile.pb.h"
[email protected]cf265dc02012-08-15 01:01:1641#include "chrome/common/metrics/variations/variations_util.h"
initial.commit09911bf2008-07-26 23:55:2942#include "chrome/common/pref_names.h"
[email protected]197c0772012-05-14 23:50:5143#include "chrome/installer/util/google_update_settings.h"
[email protected]79078df2012-02-16 01:22:3244#include "content/public/browser/gpu_data_manager.h"
[email protected]1a838cc2012-04-24 22:06:4945#include "content/public/common/content_client.h"
[email protected]ed0fd002012-04-25 23:10:3446#include "content/public/common/gpu_info.h"
[email protected]46072d42008-07-28 14:49:3547#include "googleurl/src/gurl.h"
[email protected]6b7d954ff2011-10-25 00:39:3548#include "ui/gfx/screen.h"
[email protected]91d9f3d2011-08-14 05:24:4449#include "webkit/plugins/webplugininfo.h"
initial.commit09911bf2008-07-26 23:55:2950
[email protected]5106b3a2012-10-03 20:10:4451#if defined(OS_ANDROID)
52#include "base/android/build_info.h"
53#endif
54
initial.commit09911bf2008-07-26 23:55:2955#define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
56
[email protected]d1be67b2008-11-19 20:28:3857#if defined(OS_WIN)
[email protected]1bb25e02012-08-03 22:39:3958#include "base/win/metro.h"
59
60// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
[email protected]d1be67b2008-11-19 20:28:3861extern "C" IMAGE_DOS_HEADER __ImageBase;
62#endif
63
[email protected]79078df2012-02-16 01:22:3264using content::GpuDataManager;
[email protected]fe58acc22012-02-29 01:29:5865using metrics::OmniboxEventProto;
[email protected]f65859e2013-02-04 20:00:2566using metrics::PerfDataProto;
[email protected]ed0fd002012-04-25 23:10:3467using metrics::ProfilerEventProto;
[email protected]fe58acc22012-02-29 01:29:5868using metrics::SystemProfileProto;
[email protected]ed0fd002012-04-25 23:10:3469using tracked_objects::ProcessDataSnapshot;
[email protected]0c8b7ad2012-11-06 07:08:1470typedef chrome_variations::ActiveGroupId ActiveGroupId;
[email protected]197c0772012-05-14 23:50:5171typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo;
[email protected]79078df2012-02-16 01:22:3272
[email protected]1df44b72012-01-19 05:20:3473namespace {
74
75// Returns the date at which the current metrics client ID was created as
[email protected]ca5ac4b2012-12-14 07:46:4076// a string containing seconds since the epoch, or "0" if none was found.
[email protected]cc5d7f42012-10-30 00:30:0977std::string GetMetricsEnabledDate(PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:3478 if (!pref) {
[email protected]1df44b72012-01-19 05:20:3479 NOTREACHED();
80 return "0";
81 }
[email protected]767c9d92012-03-02 16:04:3482
83 return pref->GetString(prefs::kMetricsClientIDTimestamp);
[email protected]1df44b72012-01-19 05:20:3484}
85
[email protected]fe58acc22012-02-29 01:29:5886OmniboxEventProto::InputType AsOmniboxEventInputType(
87 AutocompleteInput::Type type) {
88 switch (type) {
89 case AutocompleteInput::INVALID:
90 return OmniboxEventProto::INVALID;
91 case AutocompleteInput::UNKNOWN:
92 return OmniboxEventProto::UNKNOWN;
[email protected]fe58acc22012-02-29 01:29:5893 case AutocompleteInput::URL:
94 return OmniboxEventProto::URL;
95 case AutocompleteInput::QUERY:
96 return OmniboxEventProto::QUERY;
97 case AutocompleteInput::FORCED_QUERY:
98 return OmniboxEventProto::FORCED_QUERY;
99 default:
100 NOTREACHED();
101 return OmniboxEventProto::INVALID;
102 }
103}
104
[email protected]fe58acc22012-02-29 01:29:58105OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
106 AutocompleteMatch::Type type) {
107 switch (type) {
108 case AutocompleteMatch::URL_WHAT_YOU_TYPED:
109 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
110 case AutocompleteMatch::HISTORY_URL:
111 return OmniboxEventProto::Suggestion::HISTORY_URL;
112 case AutocompleteMatch::HISTORY_TITLE:
113 return OmniboxEventProto::Suggestion::HISTORY_TITLE;
114 case AutocompleteMatch::HISTORY_BODY:
115 return OmniboxEventProto::Suggestion::HISTORY_BODY;
116 case AutocompleteMatch::HISTORY_KEYWORD:
117 return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
118 case AutocompleteMatch::NAVSUGGEST:
119 return OmniboxEventProto::Suggestion::NAVSUGGEST;
120 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
121 return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
122 case AutocompleteMatch::SEARCH_HISTORY:
123 return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
124 case AutocompleteMatch::SEARCH_SUGGEST:
125 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
126 case AutocompleteMatch::SEARCH_OTHER_ENGINE:
127 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
128 case AutocompleteMatch::EXTENSION_APP:
129 return OmniboxEventProto::Suggestion::EXTENSION_APP;
[email protected]dbacefb2012-09-12 03:32:06130 case AutocompleteMatch::CONTACT:
131 return OmniboxEventProto::Suggestion::CONTACT;
[email protected]25320602012-10-18 22:05:56132 case AutocompleteMatch::BOOKMARK_TITLE:
133 return OmniboxEventProto::Suggestion::BOOKMARK_TITLE;
[email protected]fe58acc22012-02-29 01:29:58134 default:
135 NOTREACHED();
136 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
137 }
138}
139
[email protected]ed0fd002012-04-25 23:10:34140ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType(
[email protected]f3b357692013-03-22 05:16:13141 int process_type) {
[email protected]ed0fd002012-04-25 23:10:34142 switch (process_type) {
143 case content::PROCESS_TYPE_BROWSER:
144 return ProfilerEventProto::TrackedObject::BROWSER;
145 case content::PROCESS_TYPE_RENDERER:
146 return ProfilerEventProto::TrackedObject::RENDERER;
147 case content::PROCESS_TYPE_PLUGIN:
148 return ProfilerEventProto::TrackedObject::PLUGIN;
149 case content::PROCESS_TYPE_WORKER:
150 return ProfilerEventProto::TrackedObject::WORKER;
[email protected]ed0fd002012-04-25 23:10:34151 case content::PROCESS_TYPE_UTILITY:
152 return ProfilerEventProto::TrackedObject::UTILITY;
[email protected]ed0fd002012-04-25 23:10:34153 case content::PROCESS_TYPE_ZYGOTE:
154 return ProfilerEventProto::TrackedObject::ZYGOTE;
155 case content::PROCESS_TYPE_SANDBOX_HELPER:
156 return ProfilerEventProto::TrackedObject::SANDBOX_HELPER;
[email protected]ed0fd002012-04-25 23:10:34157 case content::PROCESS_TYPE_GPU:
158 return ProfilerEventProto::TrackedObject::GPU;
159 case content::PROCESS_TYPE_PPAPI_PLUGIN:
160 return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN;
161 case content::PROCESS_TYPE_PPAPI_BROKER:
162 return ProfilerEventProto::TrackedObject::PPAPI_BROKER;
[email protected]f3b357692013-03-22 05:16:13163 case PROCESS_TYPE_PROFILE_IMPORT:
164 return ProfilerEventProto::TrackedObject::PROFILE_IMPORT;
165 case PROCESS_TYPE_NACL_LOADER:
166 return ProfilerEventProto::TrackedObject::NACL_LOADER;
167 case PROCESS_TYPE_NACL_BROKER:
168 return ProfilerEventProto::TrackedObject::NACL_BROKER;
[email protected]ed0fd002012-04-25 23:10:34169 default:
170 NOTREACHED();
171 return ProfilerEventProto::TrackedObject::UNKNOWN;
172 }
173}
174
[email protected]1df44b72012-01-19 05:20:34175// Returns the plugin preferences corresponding for this user, if available.
176// If multiple user profiles are loaded, returns the preferences corresponding
177// to an arbitrary one of the profiles.
178PluginPrefs* GetPluginPrefs() {
179 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]fe58acc22012-02-29 01:29:58180
181 if (!profile_manager) {
182 // The profile manager can be NULL when testing.
183 return NULL;
184 }
185
[email protected]1df44b72012-01-19 05:20:34186 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
187 if (profiles.empty())
188 return NULL;
189
190 return PluginPrefs::GetForProfile(profiles.front());
191}
192
[email protected]fe58acc22012-02-29 01:29:58193// Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
194void SetPluginInfo(const webkit::WebPluginInfo& plugin_info,
195 const PluginPrefs* plugin_prefs,
196 SystemProfileProto::Plugin* plugin) {
197 plugin->set_name(UTF16ToUTF8(plugin_info.name));
198 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
199 plugin->set_version(UTF16ToUTF8(plugin_info.version));
200 if (plugin_prefs)
201 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
202}
203
[email protected]0c8b7ad2012-11-06 07:08:14204void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids,
[email protected]767c9d92012-03-02 16:04:34205 SystemProfileProto* system_profile) {
[email protected]0c8b7ad2012-11-06 07:08:14206 for (std::vector<ActiveGroupId>::const_iterator it =
[email protected]ad2461c2012-04-27 21:11:03207 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
[email protected]767c9d92012-03-02 16:04:34208 SystemProfileProto::FieldTrial* field_trial =
209 system_profile->add_field_trial();
210 field_trial->set_name_id(it->name);
211 field_trial->set_group_id(it->group);
212 }
213}
214
[email protected]ed0fd002012-04-25 23:10:34215void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
[email protected]f3b357692013-03-22 05:16:13216 int process_type,
[email protected]ed0fd002012-04-25 23:10:34217 ProfilerEventProto* performance_profile) {
218 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it =
219 profiler_data.tasks.begin();
220 it != profiler_data.tasks.end(); ++it) {
221 std::string ignored;
222 uint64 birth_thread_name_hash;
223 uint64 exec_thread_name_hash;
224 uint64 source_file_name_hash;
225 uint64 source_function_name_hash;
226 MetricsLogBase::CreateHashes(it->birth.thread_name,
227 &ignored, &birth_thread_name_hash);
228 MetricsLogBase::CreateHashes(it->death_thread_name,
229 &ignored, &exec_thread_name_hash);
[email protected]ed0fd002012-04-25 23:10:34230 MetricsLogBase::CreateHashes(it->birth.location.file_name,
[email protected]04162262012-10-23 01:17:25231 &ignored, &source_file_name_hash);
232 MetricsLogBase::CreateHashes(it->birth.location.function_name,
[email protected]ed0fd002012-04-25 23:10:34233 &ignored, &source_function_name_hash);
234
235 const tracked_objects::DeathDataSnapshot& death_data = it->death_data;
236 ProfilerEventProto::TrackedObject* tracked_object =
237 performance_profile->add_tracked_object();
238 tracked_object->set_birth_thread_name_hash(birth_thread_name_hash);
239 tracked_object->set_exec_thread_name_hash(exec_thread_name_hash);
240 tracked_object->set_source_file_name_hash(source_file_name_hash);
241 tracked_object->set_source_function_name_hash(source_function_name_hash);
242 tracked_object->set_source_line_number(it->birth.location.line_number);
243 tracked_object->set_exec_count(death_data.count);
244 tracked_object->set_exec_time_total(death_data.run_duration_sum);
245 tracked_object->set_exec_time_sampled(death_data.run_duration_sample);
246 tracked_object->set_queue_time_total(death_data.queue_duration_sum);
247 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample);
248 tracked_object->set_process_type(AsProtobufProcessType(process_type));
249 tracked_object->set_process_id(profiler_data.process_id);
250 }
251}
252
[email protected]59a7ae4e2012-10-01 23:54:44253#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
[email protected]197c0772012-05-14 23:50:51254void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data,
255 ProductInfo* product_info) {
256 product_info->set_version(product_data.version);
257 product_info->set_last_update_success_timestamp(
258 product_data.last_success.ToTimeT());
259 product_info->set_last_error(product_data.last_error_code);
260 product_info->set_last_extra_error(product_data.last_extra_code);
261 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) {
262 product_info->set_last_result(
263 static_cast<ProductInfo::InstallResult>(product_data.last_result));
264 }
265}
[email protected]59a7ae4e2012-10-01 23:54:44266#endif
[email protected]197c0772012-05-14 23:50:51267
[email protected]76869ff2013-01-15 16:13:47268#if defined(OS_WIN)
269struct ScreenDPIInformation{
270 double max_dpi_x;
271 double max_dpi_y;
272};
273
274// Called once for each connected monitor.
275BOOL CALLBACK GetMonitorDPICallback(HMONITOR, HDC hdc, LPRECT, LPARAM dwData) {
276 const double kMillimetersPerInch = 25.4;
277 ScreenDPIInformation* screen_info =
278 reinterpret_cast<ScreenDPIInformation*>(dwData);
279 // Size of screen, in mm.
280 DWORD size_x = GetDeviceCaps(hdc, HORZSIZE);
281 DWORD size_y = GetDeviceCaps(hdc, VERTSIZE);
282 double dpi_x = (size_x > 0) ?
283 GetDeviceCaps(hdc, HORZRES) / (size_x / kMillimetersPerInch) : 0;
284 double dpi_y = (size_y > 0) ?
285 GetDeviceCaps(hdc, VERTRES) / (size_y / kMillimetersPerInch) : 0;
286 screen_info->max_dpi_x = std::max(dpi_x, screen_info->max_dpi_x);
287 screen_info->max_dpi_y = std::max(dpi_y, screen_info->max_dpi_y);
288 return TRUE;
289}
290
291void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) {
292 HDC desktop_dc = GetDC(NULL);
293 if (desktop_dc) {
294 ScreenDPIInformation si = {0,0};
295 if (EnumDisplayMonitors(desktop_dc, NULL, GetMonitorDPICallback,
296 reinterpret_cast<LPARAM>(&si))) {
297 hardware->set_max_dpi_x(si.max_dpi_x);
298 hardware->set_max_dpi_y(si.max_dpi_y);
299 }
300 ReleaseDC(GetDesktopWindow(), desktop_dc);
301 }
302}
303
304#endif // defined(OS_WIN)
305
[email protected]1df44b72012-01-19 05:20:34306} // namespace
307
[email protected]197c0772012-05-14 23:50:51308GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {}
309
310GoogleUpdateMetrics::~GoogleUpdateMetrics() {}
311
[email protected]67f92bc32012-01-26 01:56:19312static base::LazyInstance<std::string>::Leaky
[email protected]054c8012011-11-16 00:12:42313 g_version_extension = LAZY_INSTANCE_INITIALIZER;
314
[email protected]1226abb2010-06-10 18:01:28315MetricsLog::MetricsLog(const std::string& client_id, int session_id)
[email protected]5eae204c2013-02-13 15:53:42316 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:41317
[email protected]1226abb2010-06-10 18:01:28318MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:29319
320// static
[email protected]b1de2c72013-02-06 02:45:47321void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) {
322 registry->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29323}
324
[email protected]1df44b72012-01-19 05:20:34325// static
[email protected]9165f742010-03-10 22:55:01326int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
327 base::TimeTicks now = base::TimeTicks::Now();
328 static base::TimeTicks last_updated_time(now);
329 int64 incremental_time = (now - last_updated_time).InSeconds();
330 last_updated_time = now;
331
332 if (incremental_time > 0) {
333 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
334 metrics_uptime += incremental_time;
335 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
336 }
337
338 return incremental_time;
339}
340
[email protected]1226abb2010-06-10 18:01:28341// static
342std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:42343 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:17344 if (!version_info.is_valid()) {
345 NOTREACHED() << "Unable to retrieve version info.";
346 return std::string();
347 }
348
[email protected]0211f57e2010-08-27 20:28:42349 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:42350 if (!version_extension().empty())
351 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:42352 if (!version_info.IsOfficialBuild())
353 version.append("-devel");
354 return version;
[email protected]1226abb2010-06-10 18:01:28355}
356
[email protected]054c8012011-11-16 00:12:42357// static
358void MetricsLog::set_version_extension(const std::string& extension) {
359 g_version_extension.Get() = extension;
360}
361
362// static
363const std::string& MetricsLog::version_extension() {
364 return g_version_extension.Get();
365}
366
[email protected]fe58acc22012-02-29 01:29:58367void MetricsLog::RecordIncrementalStabilityElements(
368 const std::vector<webkit::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34369 DCHECK(!locked());
[email protected]0b33f80b2008-12-17 21:34:36370
[email protected]767c9d92012-03-02 16:04:34371 PrefService* pref = GetPrefService();
[email protected]0b33f80b2008-12-17 21:34:36372 DCHECK(pref);
373
[email protected]147bbc0b2009-01-06 19:37:40374 OPEN_ELEMENT_FOR_SCOPE("profile");
375 WriteCommonEventAttributes();
376
[email protected]9958a322011-03-08 20:04:17377 WriteInstallElement();
[email protected]147bbc0b2009-01-06 19:37:40378
379 {
380 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
381 WriteRequiredStabilityAttributes(pref);
382 WriteRealtimeStabilityAttributes(pref);
[email protected]fe58acc22012-02-29 01:29:58383 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40384 }
[email protected]0b33f80b2008-12-17 21:34:36385}
386
[email protected]767c9d92012-03-02 16:04:34387PrefService* MetricsLog::GetPrefService() {
388 return g_browser_process->local_state();
389}
390
391gfx::Size MetricsLog::GetScreenSize() const {
[email protected]ffabb1e2012-10-12 19:51:17392 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel();
[email protected]767c9d92012-03-02 16:04:34393}
394
[email protected]aa96417972012-08-22 03:16:44395float MetricsLog::GetScreenDeviceScaleFactor() const {
[email protected]ffabb1e2012-10-12 19:51:17396 return gfx::Screen::GetNativeScreen()->
397 GetPrimaryDisplay().device_scale_factor();
[email protected]aa96417972012-08-22 03:16:44398}
399
[email protected]767c9d92012-03-02 16:04:34400int MetricsLog::GetScreenCount() const {
[email protected]ffabb1e2012-10-12 19:51:17401 // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312
402 return gfx::Screen::GetNativeScreen()->GetNumDisplays();
[email protected]767c9d92012-03-02 16:04:34403}
404
[email protected]767c9d92012-03-02 16:04:34405void MetricsLog::GetFieldTrialIds(
[email protected]0c8b7ad2012-11-06 07:08:14406 std::vector<ActiveGroupId>* field_trial_ids) const {
407 chrome_variations::GetFieldTrialActiveGroupIds(field_trial_ids);
[email protected]767c9d92012-03-02 16:04:34408}
409
[email protected]fe58acc22012-02-29 01:29:58410void MetricsLog::WriteStabilityElement(
411 const std::vector<webkit::WebPluginInfo>& plugin_list,
412 PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:34413 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29414
initial.commit09911bf2008-07-26 23:55:29415 // Get stability attributes out of Local State, zeroing out stored values.
416 // NOTE: This could lead to some data loss if this report isn't successfully
417 // sent, but that's true for all the metrics.
418
[email protected]ffaf78a2008-11-12 17:38:33419 OPEN_ELEMENT_FOR_SCOPE("stability");
[email protected]147bbc0b2009-01-06 19:37:40420 WriteRequiredStabilityAttributes(pref);
421 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29422
[email protected]fe58acc22012-02-29 01:29:58423 int incomplete_shutdown_count =
424 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
[email protected]e324f6b2012-02-28 05:43:37425 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58426 int breakpad_registration_success_count =
427 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
[email protected]e324f6b2012-02-28 05:43:37428 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58429 int breakpad_registration_failure_count =
430 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
[email protected]e324f6b2012-02-28 05:43:37431 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58432 int debugger_present_count =
433 pref->GetInteger(prefs::kStabilityDebuggerPresent);
[email protected]e324f6b2012-02-28 05:43:37434 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58435 int debugger_not_present_count =
436 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
[email protected]e324f6b2012-02-28 05:43:37437 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31438
[email protected]fe58acc22012-02-29 01:29:58439 // TODO(jar): The following are all optional, so we *could* optimize them for
440 // values of zero (and not include them).
441
442 // Write the XML version.
443 WriteIntAttribute("incompleteshutdowncount", incomplete_shutdown_count);
444 WriteIntAttribute("breakpadregistrationok",
445 breakpad_registration_success_count);
446 WriteIntAttribute("breakpadregistrationfail",
447 breakpad_registration_failure_count);
448 WriteIntAttribute("debuggerpresent", debugger_present_count);
449 WriteIntAttribute("debuggernotpresent", debugger_not_present_count);
450
451 // Write the protobuf version.
452 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34453 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58454 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
455 stability->set_breakpad_registration_success_count(
456 breakpad_registration_success_count);
457 stability->set_breakpad_registration_failure_count(
458 breakpad_registration_failure_count);
459 stability->set_debugger_present_count(debugger_present_count);
460 stability->set_debugger_not_present_count(debugger_not_present_count);
461
462 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40463}
464
[email protected]fe58acc22012-02-29 01:29:58465void MetricsLog::WritePluginStabilityElements(
466 const std::vector<webkit::WebPluginInfo>& plugin_list,
467 PrefService* pref) {
[email protected]147bbc0b2009-01-06 19:37:40468 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29469 const ListValue* plugin_stats_list = pref->GetList(
470 prefs::kStabilityPluginStats);
[email protected]1df44b72012-01-19 05:20:34471 if (!plugin_stats_list)
472 return;
initial.commit09911bf2008-07-26 23:55:29473
[email protected]1df44b72012-01-19 05:20:34474 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]ebd71962012-12-20 02:56:55475
476#if defined(ENABLE_PLUGINS)
[email protected]fe58acc22012-02-29 01:29:58477 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34478 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58479 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]1df44b72012-01-19 05:20:34480 for (ListValue::const_iterator iter = plugin_stats_list->begin();
481 iter != plugin_stats_list->end(); ++iter) {
482 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
483 NOTREACHED();
484 continue;
initial.commit09911bf2008-07-26 23:55:29485 }
[email protected]1df44b72012-01-19 05:20:34486 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29487
[email protected]1df44b72012-01-19 05:20:34488 std::string plugin_name;
489 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
490
[email protected]fe58acc22012-02-29 01:29:58491 std::string base64_name_hash;
492 uint64 numeric_name_hash_ignored;
493 CreateHashes(plugin_name, &base64_name_hash, &numeric_name_hash_ignored);
494
495 // Write the XML verison.
[email protected]1df44b72012-01-19 05:20:34496 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
497 // Use "filename" instead of "name", otherwise we need to update the
498 // UMA servers.
[email protected]fe58acc22012-02-29 01:29:58499 WriteAttribute("filename", base64_name_hash);
[email protected]1df44b72012-01-19 05:20:34500
501 int launches = 0;
502 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
503 WriteIntAttribute("launchcount", launches);
504
505 int instances = 0;
506 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
507 WriteIntAttribute("instancecount", instances);
508
509 int crashes = 0;
510 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
511 WriteIntAttribute("crashcount", crashes);
[email protected]fe58acc22012-02-29 01:29:58512
513 // Write the protobuf version.
514 // Note that this search is potentially a quadratic operation, but given the
515 // low number of plugins installed on a "reasonable" setup, this should be
516 // fine.
517 // TODO(isherman): Verify that this does not show up as a hotspot in
518 // profiler runs.
519 const webkit::WebPluginInfo* plugin_info = NULL;
520 const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name);
521 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
522 plugin_list.begin();
523 iter != plugin_list.end(); ++iter) {
524 if (iter->name == plugin_name_utf16) {
525 plugin_info = &(*iter);
526 break;
527 }
528 }
529
530 if (!plugin_info) {
531 NOTREACHED();
532 continue;
533 }
[email protected]cd937072012-07-02 09:00:29534 int loading_errors = 0;
535 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors,
536 &loading_errors);
537 WriteIntAttribute("loadingerrorcount", loading_errors);
[email protected]fe58acc22012-02-29 01:29:58538
[email protected]cd937072012-07-02 09:00:29539 // Write the protobuf version.
[email protected]fe58acc22012-02-29 01:29:58540 SystemProfileProto::Stability::PluginStability* plugin_stability =
541 stability->add_plugin_stability();
542 SetPluginInfo(*plugin_info, plugin_prefs,
543 plugin_stability->mutable_plugin());
544 plugin_stability->set_launch_count(launches);
545 plugin_stability->set_instance_count(instances);
546 plugin_stability->set_crash_count(crashes);
[email protected]cd937072012-07-02 09:00:29547 plugin_stability->set_loading_error_count(loading_errors);
initial.commit09911bf2008-07-26 23:55:29548 }
[email protected]ebd71962012-12-20 02:56:55549#endif // defined(ENABLE_PLUGINS)
[email protected]1df44b72012-01-19 05:20:34550
551 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29552}
553
[email protected]fe58acc22012-02-29 01:29:58554// The server refuses data that doesn't have certain values. crashcount and
555// launchcount are currently "required" in the "stability" group.
556// TODO(isherman): Stop writing these attributes specially once the migration to
557// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40558void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]fe58acc22012-02-29 01:29:58559 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
[email protected]0b33f80b2008-12-17 21:34:36560 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
[email protected]fe58acc22012-02-29 01:29:58561 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
[email protected]0b33f80b2008-12-17 21:34:36562 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58563
564 // Write the XML version.
565 WriteIntAttribute("launchcount", launch_count);
566 WriteIntAttribute("crashcount", crash_count);
567
568 // Write the protobuf version.
569 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34570 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58571 stability->set_launch_count(launch_count);
572 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36573}
574
[email protected]147bbc0b2009-01-06 19:37:40575void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36576 // Update the stats which are critical for real-time stability monitoring.
577 // Since these are "optional," only list ones that are non-zero, as the counts
578 // are aggergated (summed) server side.
579
[email protected]fe58acc22012-02-29 01:29:58580 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34581 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36582 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
583 if (count) {
584 WriteIntAttribute("pageloadcount", count);
[email protected]fe58acc22012-02-29 01:29:58585 stability->set_page_load_count(count);
[email protected]0b33f80b2008-12-17 21:34:36586 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
587 }
588
589 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
590 if (count) {
591 WriteIntAttribute("renderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58592 stability->set_renderer_crash_count(count);
[email protected]0b33f80b2008-12-17 21:34:36593 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
594 }
595
[email protected]1f085622009-12-04 05:33:45596 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
597 if (count) {
598 WriteIntAttribute("extensionrenderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58599 stability->set_extension_renderer_crash_count(count);
[email protected]1f085622009-12-04 05:33:45600 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
601 }
602
[email protected]0b33f80b2008-12-17 21:34:36603 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
604 if (count) {
605 WriteIntAttribute("rendererhangcount", count);
[email protected]fe58acc22012-02-29 01:29:58606 stability->set_renderer_hang_count(count);
[email protected]0b33f80b2008-12-17 21:34:36607 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
608 }
[email protected]1f085622009-12-04 05:33:45609
610 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
611 if (count) {
612 WriteIntAttribute("childprocesscrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58613 stability->set_child_process_crash_count(count);
[email protected]1f085622009-12-04 05:33:45614 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
615 }
[email protected]9165f742010-03-10 22:55:01616
[email protected]c1834a92011-01-21 18:21:03617#if defined(OS_CHROMEOS)
618 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
619 if (count) {
[email protected]fe58acc22012-02-29 01:29:58620 stability->set_other_user_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03621 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
622 }
623
624 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
625 if (count) {
[email protected]fe58acc22012-02-29 01:29:58626 stability->set_kernel_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03627 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
628 }
629
630 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
631 if (count) {
[email protected]fe58acc22012-02-29 01:29:58632 stability->set_unclean_system_shutdown_count(count);
[email protected]c1834a92011-01-21 18:21:03633 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
634 }
635#endif // OS_CHROMEOS
636
[email protected]9165f742010-03-10 22:55:01637 int64 recent_duration = GetIncrementalUptime(pref);
[email protected]fe58acc22012-02-29 01:29:58638 if (recent_duration) {
[email protected]9165f742010-03-10 22:55:01639 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]fe58acc22012-02-29 01:29:58640 stability->set_uptime_sec(recent_duration);
641 }
[email protected]0b33f80b2008-12-17 21:34:36642}
643
initial.commit09911bf2008-07-26 23:55:29644void MetricsLog::WritePluginList(
[email protected]bc66d532012-03-23 01:57:05645 const std::vector<webkit::WebPluginInfo>& plugin_list,
646 bool write_as_xml) {
[email protected]767c9d92012-03-02 16:04:34647 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29648
[email protected]ffaf78a2008-11-12 17:38:33649 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]ebd71962012-12-20 02:56:55650
651#if defined(ENABLE_PLUGINS)
652 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]767c9d92012-03-02 16:04:34653 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]91d9f3d2011-08-14 05:24:44654 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50655 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29656 iter != plugin_list.end(); ++iter) {
[email protected]bc66d532012-03-23 01:57:05657 if (write_as_xml) {
658 std::string base64_name_hash;
659 uint64 numeric_hash_ignored;
660 CreateHashes(UTF16ToUTF8(iter->name), &base64_name_hash,
661 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58662
[email protected]bc66d532012-03-23 01:57:05663 std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe();
664 std::string base64_filename_hash;
665 CreateHashes(filename_bytes, &base64_filename_hash,
666 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58667
[email protected]bc66d532012-03-23 01:57:05668 // Write the XML version.
669 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29670
[email protected]bc66d532012-03-23 01:57:05671 // Plugin name and filename are hashed for the privacy of those
672 // testing unreleased new extensions.
673 WriteAttribute("name", base64_name_hash);
674 WriteAttribute("filename", base64_filename_hash);
675 WriteAttribute("version", UTF16ToUTF8(iter->version));
676 if (plugin_prefs)
677 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
678 } else {
679 // Write the protobuf version.
680 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
681 SetPluginInfo(*iter, plugin_prefs, plugin);
682 }
initial.commit09911bf2008-07-26 23:55:29683 }
[email protected]ebd71962012-12-20 02:56:55684#endif // defined(ENABLE_PLUGINS)
initial.commit09911bf2008-07-26 23:55:29685}
686
[email protected]147bbc0b2009-01-06 19:37:40687void MetricsLog::WriteInstallElement() {
[email protected]fe58acc22012-02-29 01:29:58688 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05689 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]147bbc0b2009-01-06 19:37:40690 OPEN_ELEMENT_FOR_SCOPE("install");
[email protected]cc5d7f42012-10-30 00:30:09691 WriteAttribute("installdate", GetMetricsEnabledDate(GetPrefService()));
[email protected]147bbc0b2009-01-06 19:37:40692 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40693}
694
initial.commit09911bf2008-07-26 23:55:29695void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44696 const std::vector<webkit::WebPluginInfo>& plugin_list,
[email protected]197c0772012-05-14 23:50:51697 const GoogleUpdateMetrics& google_update_metrics,
initial.commit09911bf2008-07-26 23:55:29698 const DictionaryValue* profile_metrics) {
[email protected]767c9d92012-03-02 16:04:34699 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29700
[email protected]767c9d92012-03-02 16:04:34701 PrefService* pref = GetPrefService();
initial.commit09911bf2008-07-26 23:55:29702
[email protected]ffaf78a2008-11-12 17:38:33703 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29704 WriteCommonEventAttributes();
705
[email protected]147bbc0b2009-01-06 19:37:40706 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29707
[email protected]bc66d532012-03-23 01:57:05708 // Write the XML version.
709 // We'll write the protobuf version in RecordEnvironmentProto().
710 bool write_as_xml = true;
711 WritePluginList(plugin_list, write_as_xml);
initial.commit09911bf2008-07-26 23:55:29712
[email protected]fe58acc22012-02-29 01:29:58713 WriteStabilityElement(plugin_list, pref);
initial.commit09911bf2008-07-26 23:55:29714
715 {
[email protected]fe58acc22012-02-29 01:29:58716 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05717 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29718 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]0b6a4fb2012-10-16 01:58:21719 WriteAttribute("arch", base::SysInfo::OperatingSystemArchitecture());
initial.commit09911bf2008-07-26 23:55:29720 }
721
722 {
[email protected]fe58acc22012-02-29 01:29:58723 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05724 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29725 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]bc66d532012-03-23 01:57:05726 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38727#if defined(OS_WIN)
728 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
729#endif
initial.commit09911bf2008-07-26 23:55:29730 }
731
732 {
[email protected]fe58acc22012-02-29 01:29:58733 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05734 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29735 OPEN_ELEMENT_FOR_SCOPE("os");
[email protected]bc66d532012-03-23 01:57:05736 WriteAttribute("name", base::SysInfo::OperatingSystemName());
737 WriteAttribute("version", base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29738 }
739
740 {
[email protected]e8c287c872010-07-20 00:49:42741 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]fe58acc22012-02-29 01:29:58742 const content::GPUInfo& gpu_info =
743 GpuDataManager::GetInstance()->GetGPUInfo();
[email protected]fe58acc22012-02-29 01:29:58744
745 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05746 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]a094e2c2012-05-10 23:02:42747 WriteIntAttribute("vendorid", gpu_info.gpu.vendor_id);
748 WriteIntAttribute("deviceid", gpu_info.gpu.device_id);
[email protected]e8c287c872010-07-20 00:49:42749 }
750
751 {
[email protected]767c9d92012-03-02 16:04:34752 const gfx::Size display_size = GetScreenSize();
[email protected]fe58acc22012-02-29 01:29:58753
754 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05755 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]fe58acc22012-02-29 01:29:58756 OPEN_ELEMENT_FOR_SCOPE("display");
[email protected]bc66d532012-03-23 01:57:05757 WriteIntAttribute("xsize", display_size.width());
758 WriteIntAttribute("ysize", display_size.height());
759 WriteIntAttribute("screens", GetScreenCount());
initial.commit09911bf2008-07-26 23:55:29760 }
761
762 {
763 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
initial.commit09911bf2008-07-26 23:55:29764 {
765 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
766 WriteAttribute("name", "full-tree");
[email protected]8542bcc2013-01-30 00:15:36767 WriteIntAttribute("foldercount", 0);
768 WriteIntAttribute("itemcount", 0);
initial.commit09911bf2008-07-26 23:55:29769 }
770 {
771 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
772 WriteAttribute("name", "toolbar");
[email protected]8542bcc2013-01-30 00:15:36773 WriteIntAttribute("foldercount", 0);
774 WriteIntAttribute("itemcount", 0);
initial.commit09911bf2008-07-26 23:55:29775 }
776 }
777
778 {
779 OPEN_ELEMENT_FOR_SCOPE("keywords");
780 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
781 }
782
783 if (profile_metrics)
784 WriteAllProfilesMetrics(*profile_metrics);
[email protected]767c9d92012-03-02 16:04:34785
[email protected]197c0772012-05-14 23:50:51786 RecordEnvironmentProto(plugin_list, google_update_metrics);
[email protected]bc66d532012-03-23 01:57:05787}
788
789void MetricsLog::RecordEnvironmentProto(
[email protected]197c0772012-05-14 23:50:51790 const std::vector<webkit::WebPluginInfo>& plugin_list,
791 const GoogleUpdateMetrics& google_update_metrics) {
[email protected]bc66d532012-03-23 01:57:05792 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]24b9bb392013-01-29 20:29:29793
794 std::string brand_code;
795 if (google_util::GetBrand(&brand_code))
796 system_profile->set_brand_code(brand_code);
797
[email protected]cc5d7f42012-10-30 00:30:09798 int enabled_date;
799 bool success = base::StringToInt(GetMetricsEnabledDate(GetPrefService()),
800 &enabled_date);
[email protected]bc66d532012-03-23 01:57:05801 DCHECK(success);
[email protected]cc5d7f42012-10-30 00:30:09802 system_profile->set_uma_enabled_date(enabled_date);
[email protected]bc66d532012-03-23 01:57:05803
804 system_profile->set_application_locale(
[email protected]eabbfb12013-04-05 23:28:35805 g_browser_process->GetApplicationLocale());
[email protected]bc66d532012-03-23 01:57:05806
807 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
[email protected]0b6a4fb2012-10-16 01:58:21808 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
[email protected]bc66d532012-03-23 01:57:05809 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
810#if defined(OS_WIN)
811 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
812#endif
813
[email protected]74b299e2013-01-29 01:24:42814 SystemProfileProto::Network* network = system_profile->mutable_network();
815 network->set_connection_type_is_ambiguous(
[email protected]5eae204c2013-02-13 15:53:42816 network_observer_.connection_type_is_ambiguous());
817 network->set_connection_type(network_observer_.connection_type());
818 network->set_wifi_phy_layer_protocol_is_ambiguous(
819 network_observer_.wifi_phy_layer_protocol_is_ambiguous());
820 network->set_wifi_phy_layer_protocol(
821 network_observer_.wifi_phy_layer_protocol());
822 network_observer_.Reset();
[email protected]74b299e2013-01-29 01:24:42823
[email protected]bc66d532012-03-23 01:57:05824 SystemProfileProto::OS* os = system_profile->mutable_os();
[email protected]1bb25e02012-08-03 22:39:39825 std::string os_name = base::SysInfo::OperatingSystemName();
826#if defined(OS_WIN)
827 // TODO(mad): This only checks whether the main process is a Metro process at
828 // upload time; not whether the collected metrics were all gathered from
829 // Metro. This is ok as an approximation for now, since users will rarely be
830 // switching from Metro to Desktop mode; but we should re-evaluate whether we
831 // can distinguish metrics more cleanly in the future: http://crbug.com/140568
832 if (base::win::IsMetroProcess())
833 os_name += " (Metro)";
834#endif
835 os->set_name(os_name);
[email protected]bc66d532012-03-23 01:57:05836 os->set_version(base::SysInfo::OperatingSystemVersion());
[email protected]5106b3a2012-10-03 20:10:44837#if defined(OS_ANDROID)
838 os->set_fingerprint(
839 base::android::BuildInfo::GetInstance()->android_build_fp());
840#endif
[email protected]bc66d532012-03-23 01:57:05841
842 const content::GPUInfo& gpu_info =
843 GpuDataManager::GetInstance()->GetGPUInfo();
844 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
[email protected]a094e2c2012-05-10 23:02:42845 gpu->set_vendor_id(gpu_info.gpu.vendor_id);
846 gpu->set_device_id(gpu_info.gpu.device_id);
[email protected]bc66d532012-03-23 01:57:05847 gpu->set_driver_version(gpu_info.driver_version);
848 gpu->set_driver_date(gpu_info.driver_date);
849 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
850 gpu_performance = gpu->mutable_performance_statistics();
851 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
852 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
853 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
[email protected]d6bdfae2013-01-18 20:23:01854 gpu->set_gl_vendor(gpu_info.gl_vendor);
855 gpu->set_gl_renderer(gpu_info.gl_renderer);
[email protected]bc66d532012-03-23 01:57:05856
857 const gfx::Size display_size = GetScreenSize();
858 hardware->set_primary_screen_width(display_size.width());
859 hardware->set_primary_screen_height(display_size.height());
[email protected]aa96417972012-08-22 03:16:44860 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor());
[email protected]bc66d532012-03-23 01:57:05861 hardware->set_screen_count(GetScreenCount());
862
[email protected]76869ff2013-01-15 16:13:47863#if defined(OS_WIN)
864 WriteScreenDPIInformationProto(hardware);
865#endif
866
[email protected]197c0772012-05-14 23:50:51867 WriteGoogleUpdateProto(google_update_metrics);
868
[email protected]bc66d532012-03-23 01:57:05869 bool write_as_xml = false;
870 WritePluginList(plugin_list, write_as_xml);
871
[email protected]0c8b7ad2012-11-06 07:08:14872 std::vector<ActiveGroupId> field_trial_ids;
[email protected]767c9d92012-03-02 16:04:34873 GetFieldTrialIds(&field_trial_ids);
874 WriteFieldTrials(field_trial_ids, system_profile);
[email protected]f65859e2013-02-04 20:00:25875
876#if defined(OS_CHROMEOS)
877 PerfDataProto perf_data_proto;
878 if (perf_provider_.GetPerfData(&perf_data_proto))
879 uma_proto()->add_perf_data()->Swap(&perf_data_proto);
880#endif
initial.commit09911bf2008-07-26 23:55:29881}
882
[email protected]ed0fd002012-04-25 23:10:34883void MetricsLog::RecordProfilerData(
884 const tracked_objects::ProcessDataSnapshot& process_data,
[email protected]f3b357692013-03-22 05:16:13885 int process_type) {
[email protected]ed0fd002012-04-25 23:10:34886 DCHECK(!locked());
887
[email protected]8f829682012-04-27 00:36:49888 if (tracked_objects::GetTimeSourceType() !=
889 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) {
[email protected]ed0fd002012-04-25 23:10:34890 // We currently only support the default time source, wall clock time.
891 return;
892 }
893
894 ProfilerEventProto* profile;
895 if (!uma_proto()->profiler_event_size()) {
896 // For the first process's data, add a new field to the protocol buffer.
897 profile = uma_proto()->add_profiler_event();
898 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
899 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
900 } else {
901 // For the remaining calls, re-use the existing field.
902 profile = uma_proto()->mutable_profiler_event(0);
903 }
904
905 WriteProfilerData(process_data, process_type, profile);
906}
907
initial.commit09911bf2008-07-26 23:55:29908void MetricsLog::WriteAllProfilesMetrics(
909 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51910 const std::string profile_prefix(prefs::kProfilePrefix);
[email protected]a703e71e2013-02-26 23:58:14911 for (DictionaryValue::Iterator i(all_profiles_metrics); !i.IsAtEnd();
912 i.Advance()) {
913 if (i.key().compare(0, profile_prefix.size(), profile_prefix) == 0) {
[email protected]a61890e2012-07-27 22:27:11914 const DictionaryValue* profile;
[email protected]a703e71e2013-02-26 23:58:14915 if (i.value().GetAsDictionary(&profile))
916 WriteProfileMetrics(i.key().substr(profile_prefix.size()), *profile);
initial.commit09911bf2008-07-26 23:55:29917 }
918 }
919}
920
[email protected]e7b418b2010-07-30 19:47:47921void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29922 const DictionaryValue& profile_metrics) {
923 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47924 WriteAttribute("profileidhash", profileidhash);
[email protected]a703e71e2013-02-26 23:58:14925 for (DictionaryValue::Iterator i(profile_metrics); !i.IsAtEnd();
926 i.Advance()) {
927 DCHECK_NE(i.key(), "id");
928 switch (i.value().GetType()) {
929 case Value::TYPE_STRING: {
930 std::string string_value;
931 if (i.value().GetAsString(&string_value)) {
932 OPEN_ELEMENT_FOR_SCOPE("profileparam");
933 WriteAttribute("name", i.key());
934 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29935 }
[email protected]a703e71e2013-02-26 23:58:14936 break;
initial.commit09911bf2008-07-26 23:55:29937 }
[email protected]a703e71e2013-02-26 23:58:14938
939 case Value::TYPE_BOOLEAN: {
940 bool bool_value;
941 if (i.value().GetAsBoolean(&bool_value)) {
942 OPEN_ELEMENT_FOR_SCOPE("profileparam");
943 WriteAttribute("name", i.key());
944 WriteIntAttribute("value", bool_value ? 1 : 0);
945 }
946 break;
947 }
948
949 case Value::TYPE_INTEGER: {
950 int int_value;
951 if (i.value().GetAsInteger(&int_value)) {
952 OPEN_ELEMENT_FOR_SCOPE("profileparam");
953 WriteAttribute("name", i.key());
954 WriteIntAttribute("value", int_value);
955 }
956 break;
957 }
958
959 default:
960 NOTREACHED();
961 break;
initial.commit09911bf2008-07-26 23:55:29962 }
963 }
964}
965
966void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
[email protected]767c9d92012-03-02 16:04:34967 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29968
[email protected]fe58acc22012-02-29 01:29:58969 // Write the XML version.
[email protected]ffaf78a2008-11-12 17:38:33970 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29971 WriteAttribute("action", "autocomplete");
972 WriteAttribute("targetidhash", "");
973 // TODO(kochi): Properly track windows.
974 WriteIntAttribute("window", 0);
[email protected]6ebc3162011-12-19 13:44:00975 if (log.tab_id != -1) {
976 // If we know what tab the autocomplete URL was opened in, log it.
977 WriteIntAttribute("tab", static_cast<int>(log.tab_id));
978 }
initial.commit09911bf2008-07-26 23:55:29979 WriteCommonEventAttributes();
980
[email protected]65956312012-04-19 21:28:12981 std::vector<string16> terms;
982 const int num_terms =
983 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms));
[email protected]ffaf78a2008-11-12 17:38:33984 {
985 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29986
[email protected]ffaf78a2008-11-12 17:38:33987 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
[email protected]65956312012-04-19 21:28:12988 WriteIntAttribute("numterms", num_terms);
[email protected]ffaf78a2008-11-12 17:38:33989 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
990 WriteIntAttribute("completedlength",
[email protected]62b3ef52013-01-18 00:13:02991 log.completed_length != string16::npos ?
992 static_cast<int>(log.completed_length) : 0);
[email protected]9e349762012-01-31 03:24:36993 if (log.elapsed_time_since_user_first_modified_omnibox !=
994 base::TimeDelta::FromMilliseconds(-1)) {
995 // Only upload the typing duration if it is set/valid.
996 WriteInt64Attribute("typingduration",
997 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
998 }
[email protected]381e2992008-12-16 01:41:00999 const std::string input_type(
1000 AutocompleteInput::TypeToString(log.input_type));
1001 if (!input_type.empty())
1002 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:291003
[email protected]ffaf78a2008-11-12 17:38:331004 for (AutocompleteResult::const_iterator i(log.result.begin());
1005 i != log.result.end(); ++i) {
1006 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
1007 if (i->provider)
[email protected]35f1f4f02012-09-11 13:17:001008 WriteAttribute("provider", i->provider->GetName());
[email protected]381e2992008-12-16 01:41:001009 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
1010 if (!result_type.empty())
1011 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:331012 WriteIntAttribute("relevance", i->relevance);
1013 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
1014 }
initial.commit09911bf2008-07-26 23:55:291015 }
initial.commit09911bf2008-07-26 23:55:291016
[email protected]fe58acc22012-02-29 01:29:581017 // Write the protobuf version.
[email protected]767c9d92012-03-02 16:04:341018 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
[email protected]fe58acc22012-02-29 01:29:581019 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
1020 if (log.tab_id != -1) {
1021 // If we know what tab the autocomplete URL was opened in, log it.
1022 omnibox_event->set_tab_id(log.tab_id);
1023 }
1024 omnibox_event->set_typed_length(log.text.length());
[email protected]660fe8f32012-05-03 20:01:081025 omnibox_event->set_just_deleted_text(log.just_deleted_text);
[email protected]65956312012-04-19 21:28:121026 omnibox_event->set_num_typed_terms(num_terms);
[email protected]fe58acc22012-02-29 01:29:581027 omnibox_event->set_selected_index(log.selected_index);
[email protected]62b3ef52013-01-18 00:13:021028 if (log.completed_length != string16::npos)
1029 omnibox_event->set_completed_length(log.completed_length);
[email protected]65956312012-04-19 21:28:121030 if (log.elapsed_time_since_user_first_modified_omnibox !=
1031 base::TimeDelta::FromMilliseconds(-1)) {
1032 // Only upload the typing duration if it is set/valid.
1033 omnibox_event->set_typing_duration_ms(
1034 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
1035 }
[email protected]35d55602012-11-20 23:49:031036 omnibox_event->set_duration_since_last_default_match_update_ms(
1037 log.elapsed_time_since_last_change_to_default_match.InMilliseconds());
[email protected]ee902532012-05-01 23:54:491038 omnibox_event->set_current_page_classification(
1039 log.current_page_classification);
[email protected]fe58acc22012-02-29 01:29:581040 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
1041 for (AutocompleteResult::const_iterator i(log.result.begin());
1042 i != log.result.end(); ++i) {
1043 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
[email protected]0e9e8782012-05-15 23:01:511044 suggestion->set_provider(i->provider->AsOmniboxEventProviderType());
[email protected]fe58acc22012-02-29 01:29:581045 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
1046 suggestion->set_relevance(i->relevance);
[email protected]cf6256f2012-06-12 23:36:011047 if (i->typed_count != -1)
1048 suggestion->set_typed_count(i->typed_count);
[email protected]fe58acc22012-02-29 01:29:581049 suggestion->set_is_starred(i->starred);
1050 }
[email protected]0e9e8782012-05-15 23:01:511051 for (ProvidersInfo::const_iterator i(log.providers_info.begin());
1052 i != log.providers_info.end(); ++i) {
1053 OmniboxEventProto::ProviderInfo* provider_info =
1054 omnibox_event->add_provider_info();
1055 provider_info->CopyFrom(*i);
1056 }
[email protected]fe58acc22012-02-29 01:29:581057
initial.commit09911bf2008-07-26 23:55:291058 ++num_events_;
1059}
[email protected]197c0772012-05-14 23:50:511060
1061void MetricsLog::WriteGoogleUpdateProto(
1062 const GoogleUpdateMetrics& google_update_metrics) {
1063#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
1064 SystemProfileProto::GoogleUpdate* google_update =
1065 uma_proto()->mutable_system_profile()->mutable_google_update();
1066
1067 google_update->set_is_system_install(google_update_metrics.is_system_install);
1068
1069 if (!google_update_metrics.last_started_au.is_null()) {
1070 google_update->set_last_automatic_start_timestamp(
1071 google_update_metrics.last_started_au.ToTimeT());
1072 }
1073
1074 if (!google_update_metrics.last_checked.is_null()) {
1075 google_update->set_last_update_check_timestamp(
1076 google_update_metrics.last_checked.ToTimeT());
1077 }
1078
1079 if (!google_update_metrics.google_update_data.version.empty()) {
1080 ProductDataToProto(google_update_metrics.google_update_data,
1081 google_update->mutable_google_update_status());
1082 }
1083
1084 if (!google_update_metrics.product_data.version.empty()) {
1085 ProductDataToProto(google_update_metrics.product_data,
1086 google_update->mutable_client_status());
1087 }
1088#endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
1089}