blob: e3c6fa321d29f0eb6f6a363bb77d517bae4bb1f4 [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]1eeb5e02010-07-20 23:02:1135#include "chrome/common/chrome_version_info.h"
initial.commit09911bf2008-07-26 23:55:2936#include "chrome/common/logging_chrome.h"
[email protected]fe58acc22012-02-29 01:29:5837#include "chrome/common/metrics/proto/omnibox_event.pb.h"
[email protected]ed0fd002012-04-25 23:10:3438#include "chrome/common/metrics/proto/profiler_event.pb.h"
[email protected]fe58acc22012-02-29 01:29:5839#include "chrome/common/metrics/proto/system_profile.pb.h"
[email protected]cf265dc02012-08-15 01:01:1640#include "chrome/common/metrics/variations/variations_util.h"
initial.commit09911bf2008-07-26 23:55:2941#include "chrome/common/pref_names.h"
[email protected]197c0772012-05-14 23:50:5142#include "chrome/installer/util/google_update_settings.h"
[email protected]fe58acc22012-02-29 01:29:5843#include "content/public/browser/content_browser_client.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;
93 case AutocompleteInput::REQUESTED_URL:
94 return OmniboxEventProto::REQUESTED_URL;
95 case AutocompleteInput::URL:
96 return OmniboxEventProto::URL;
97 case AutocompleteInput::QUERY:
98 return OmniboxEventProto::QUERY;
99 case AutocompleteInput::FORCED_QUERY:
100 return OmniboxEventProto::FORCED_QUERY;
101 default:
102 NOTREACHED();
103 return OmniboxEventProto::INVALID;
104 }
105}
106
[email protected]fe58acc22012-02-29 01:29:58107OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
108 AutocompleteMatch::Type type) {
109 switch (type) {
110 case AutocompleteMatch::URL_WHAT_YOU_TYPED:
111 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
112 case AutocompleteMatch::HISTORY_URL:
113 return OmniboxEventProto::Suggestion::HISTORY_URL;
114 case AutocompleteMatch::HISTORY_TITLE:
115 return OmniboxEventProto::Suggestion::HISTORY_TITLE;
116 case AutocompleteMatch::HISTORY_BODY:
117 return OmniboxEventProto::Suggestion::HISTORY_BODY;
118 case AutocompleteMatch::HISTORY_KEYWORD:
119 return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
120 case AutocompleteMatch::NAVSUGGEST:
121 return OmniboxEventProto::Suggestion::NAVSUGGEST;
122 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
123 return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
124 case AutocompleteMatch::SEARCH_HISTORY:
125 return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
126 case AutocompleteMatch::SEARCH_SUGGEST:
127 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
128 case AutocompleteMatch::SEARCH_OTHER_ENGINE:
129 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
130 case AutocompleteMatch::EXTENSION_APP:
131 return OmniboxEventProto::Suggestion::EXTENSION_APP;
[email protected]dbacefb2012-09-12 03:32:06132 case AutocompleteMatch::CONTACT:
133 return OmniboxEventProto::Suggestion::CONTACT;
[email protected]25320602012-10-18 22:05:56134 case AutocompleteMatch::BOOKMARK_TITLE:
135 return OmniboxEventProto::Suggestion::BOOKMARK_TITLE;
[email protected]fe58acc22012-02-29 01:29:58136 default:
137 NOTREACHED();
138 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
139 }
140}
141
[email protected]ed0fd002012-04-25 23:10:34142ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType(
143 content::ProcessType process_type) {
144 switch (process_type) {
145 case content::PROCESS_TYPE_BROWSER:
146 return ProfilerEventProto::TrackedObject::BROWSER;
147 case content::PROCESS_TYPE_RENDERER:
148 return ProfilerEventProto::TrackedObject::RENDERER;
149 case content::PROCESS_TYPE_PLUGIN:
150 return ProfilerEventProto::TrackedObject::PLUGIN;
151 case content::PROCESS_TYPE_WORKER:
152 return ProfilerEventProto::TrackedObject::WORKER;
153 case content::PROCESS_TYPE_NACL_LOADER:
154 return ProfilerEventProto::TrackedObject::NACL_LOADER;
155 case content::PROCESS_TYPE_UTILITY:
156 return ProfilerEventProto::TrackedObject::UTILITY;
157 case content::PROCESS_TYPE_PROFILE_IMPORT:
158 return ProfilerEventProto::TrackedObject::PROFILE_IMPORT;
159 case content::PROCESS_TYPE_ZYGOTE:
160 return ProfilerEventProto::TrackedObject::ZYGOTE;
161 case content::PROCESS_TYPE_SANDBOX_HELPER:
162 return ProfilerEventProto::TrackedObject::SANDBOX_HELPER;
163 case content::PROCESS_TYPE_NACL_BROKER:
164 return ProfilerEventProto::TrackedObject::NACL_BROKER;
165 case content::PROCESS_TYPE_GPU:
166 return ProfilerEventProto::TrackedObject::GPU;
167 case content::PROCESS_TYPE_PPAPI_PLUGIN:
168 return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN;
169 case content::PROCESS_TYPE_PPAPI_BROKER:
170 return ProfilerEventProto::TrackedObject::PPAPI_BROKER;
171 default:
172 NOTREACHED();
173 return ProfilerEventProto::TrackedObject::UNKNOWN;
174 }
175}
176
[email protected]1df44b72012-01-19 05:20:34177// Returns the plugin preferences corresponding for this user, if available.
178// If multiple user profiles are loaded, returns the preferences corresponding
179// to an arbitrary one of the profiles.
180PluginPrefs* GetPluginPrefs() {
181 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]fe58acc22012-02-29 01:29:58182
183 if (!profile_manager) {
184 // The profile manager can be NULL when testing.
185 return NULL;
186 }
187
[email protected]1df44b72012-01-19 05:20:34188 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
189 if (profiles.empty())
190 return NULL;
191
192 return PluginPrefs::GetForProfile(profiles.front());
193}
194
[email protected]fe58acc22012-02-29 01:29:58195// Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
196void SetPluginInfo(const webkit::WebPluginInfo& plugin_info,
197 const PluginPrefs* plugin_prefs,
198 SystemProfileProto::Plugin* plugin) {
199 plugin->set_name(UTF16ToUTF8(plugin_info.name));
200 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
201 plugin->set_version(UTF16ToUTF8(plugin_info.version));
202 if (plugin_prefs)
203 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
204}
205
[email protected]0c8b7ad2012-11-06 07:08:14206void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids,
[email protected]767c9d92012-03-02 16:04:34207 SystemProfileProto* system_profile) {
[email protected]0c8b7ad2012-11-06 07:08:14208 for (std::vector<ActiveGroupId>::const_iterator it =
[email protected]ad2461c2012-04-27 21:11:03209 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
[email protected]767c9d92012-03-02 16:04:34210 SystemProfileProto::FieldTrial* field_trial =
211 system_profile->add_field_trial();
212 field_trial->set_name_id(it->name);
213 field_trial->set_group_id(it->group);
214 }
215}
216
[email protected]ed0fd002012-04-25 23:10:34217void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
218 content::ProcessType process_type,
219 ProfilerEventProto* performance_profile) {
220 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it =
221 profiler_data.tasks.begin();
222 it != profiler_data.tasks.end(); ++it) {
223 std::string ignored;
224 uint64 birth_thread_name_hash;
225 uint64 exec_thread_name_hash;
226 uint64 source_file_name_hash;
227 uint64 source_function_name_hash;
228 MetricsLogBase::CreateHashes(it->birth.thread_name,
229 &ignored, &birth_thread_name_hash);
230 MetricsLogBase::CreateHashes(it->death_thread_name,
231 &ignored, &exec_thread_name_hash);
[email protected]ed0fd002012-04-25 23:10:34232 MetricsLogBase::CreateHashes(it->birth.location.file_name,
[email protected]04162262012-10-23 01:17:25233 &ignored, &source_file_name_hash);
234 MetricsLogBase::CreateHashes(it->birth.location.function_name,
[email protected]ed0fd002012-04-25 23:10:34235 &ignored, &source_function_name_hash);
236
237 const tracked_objects::DeathDataSnapshot& death_data = it->death_data;
238 ProfilerEventProto::TrackedObject* tracked_object =
239 performance_profile->add_tracked_object();
240 tracked_object->set_birth_thread_name_hash(birth_thread_name_hash);
241 tracked_object->set_exec_thread_name_hash(exec_thread_name_hash);
242 tracked_object->set_source_file_name_hash(source_file_name_hash);
243 tracked_object->set_source_function_name_hash(source_function_name_hash);
244 tracked_object->set_source_line_number(it->birth.location.line_number);
245 tracked_object->set_exec_count(death_data.count);
246 tracked_object->set_exec_time_total(death_data.run_duration_sum);
247 tracked_object->set_exec_time_sampled(death_data.run_duration_sample);
248 tracked_object->set_queue_time_total(death_data.queue_duration_sum);
249 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample);
250 tracked_object->set_process_type(AsProtobufProcessType(process_type));
251 tracked_object->set_process_id(profiler_data.process_id);
252 }
253}
254
[email protected]59a7ae4e2012-10-01 23:54:44255#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
[email protected]197c0772012-05-14 23:50:51256void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data,
257 ProductInfo* product_info) {
258 product_info->set_version(product_data.version);
259 product_info->set_last_update_success_timestamp(
260 product_data.last_success.ToTimeT());
261 product_info->set_last_error(product_data.last_error_code);
262 product_info->set_last_extra_error(product_data.last_extra_code);
263 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) {
264 product_info->set_last_result(
265 static_cast<ProductInfo::InstallResult>(product_data.last_result));
266 }
267}
[email protected]59a7ae4e2012-10-01 23:54:44268#endif
[email protected]197c0772012-05-14 23:50:51269
[email protected]76869ff2013-01-15 16:13:47270#if defined(OS_WIN)
271struct ScreenDPIInformation{
272 double max_dpi_x;
273 double max_dpi_y;
274};
275
276// Called once for each connected monitor.
277BOOL CALLBACK GetMonitorDPICallback(HMONITOR, HDC hdc, LPRECT, LPARAM dwData) {
278 const double kMillimetersPerInch = 25.4;
279 ScreenDPIInformation* screen_info =
280 reinterpret_cast<ScreenDPIInformation*>(dwData);
281 // Size of screen, in mm.
282 DWORD size_x = GetDeviceCaps(hdc, HORZSIZE);
283 DWORD size_y = GetDeviceCaps(hdc, VERTSIZE);
284 double dpi_x = (size_x > 0) ?
285 GetDeviceCaps(hdc, HORZRES) / (size_x / kMillimetersPerInch) : 0;
286 double dpi_y = (size_y > 0) ?
287 GetDeviceCaps(hdc, VERTRES) / (size_y / kMillimetersPerInch) : 0;
288 screen_info->max_dpi_x = std::max(dpi_x, screen_info->max_dpi_x);
289 screen_info->max_dpi_y = std::max(dpi_y, screen_info->max_dpi_y);
290 return TRUE;
291}
292
293void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) {
294 HDC desktop_dc = GetDC(NULL);
295 if (desktop_dc) {
296 ScreenDPIInformation si = {0,0};
297 if (EnumDisplayMonitors(desktop_dc, NULL, GetMonitorDPICallback,
298 reinterpret_cast<LPARAM>(&si))) {
299 hardware->set_max_dpi_x(si.max_dpi_x);
300 hardware->set_max_dpi_y(si.max_dpi_y);
301 }
302 ReleaseDC(GetDesktopWindow(), desktop_dc);
303 }
304}
305
306#endif // defined(OS_WIN)
307
[email protected]1df44b72012-01-19 05:20:34308} // namespace
309
[email protected]197c0772012-05-14 23:50:51310GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {}
311
312GoogleUpdateMetrics::~GoogleUpdateMetrics() {}
313
[email protected]67f92bc32012-01-26 01:56:19314static base::LazyInstance<std::string>::Leaky
[email protected]054c8012011-11-16 00:12:42315 g_version_extension = LAZY_INSTANCE_INITIALIZER;
316
[email protected]1226abb2010-06-10 18:01:28317MetricsLog::MetricsLog(const std::string& client_id, int session_id)
[email protected]5eae204c2013-02-13 15:53:42318 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:41319
[email protected]1226abb2010-06-10 18:01:28320MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:29321
322// static
[email protected]b1de2c72013-02-06 02:45:47323void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) {
324 registry->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29325}
326
[email protected]1df44b72012-01-19 05:20:34327// static
[email protected]9165f742010-03-10 22:55:01328int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
329 base::TimeTicks now = base::TimeTicks::Now();
330 static base::TimeTicks last_updated_time(now);
331 int64 incremental_time = (now - last_updated_time).InSeconds();
332 last_updated_time = now;
333
334 if (incremental_time > 0) {
335 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
336 metrics_uptime += incremental_time;
337 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
338 }
339
340 return incremental_time;
341}
342
[email protected]1226abb2010-06-10 18:01:28343// static
344std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:42345 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:17346 if (!version_info.is_valid()) {
347 NOTREACHED() << "Unable to retrieve version info.";
348 return std::string();
349 }
350
[email protected]0211f57e2010-08-27 20:28:42351 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:42352 if (!version_extension().empty())
353 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:42354 if (!version_info.IsOfficialBuild())
355 version.append("-devel");
356 return version;
[email protected]1226abb2010-06-10 18:01:28357}
358
[email protected]054c8012011-11-16 00:12:42359// static
360void MetricsLog::set_version_extension(const std::string& extension) {
361 g_version_extension.Get() = extension;
362}
363
364// static
365const std::string& MetricsLog::version_extension() {
366 return g_version_extension.Get();
367}
368
[email protected]fe58acc22012-02-29 01:29:58369void MetricsLog::RecordIncrementalStabilityElements(
370 const std::vector<webkit::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34371 DCHECK(!locked());
[email protected]0b33f80b2008-12-17 21:34:36372
[email protected]767c9d92012-03-02 16:04:34373 PrefService* pref = GetPrefService();
[email protected]0b33f80b2008-12-17 21:34:36374 DCHECK(pref);
375
[email protected]147bbc0b2009-01-06 19:37:40376 OPEN_ELEMENT_FOR_SCOPE("profile");
377 WriteCommonEventAttributes();
378
[email protected]9958a322011-03-08 20:04:17379 WriteInstallElement();
[email protected]147bbc0b2009-01-06 19:37:40380
381 {
382 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
383 WriteRequiredStabilityAttributes(pref);
384 WriteRealtimeStabilityAttributes(pref);
[email protected]fe58acc22012-02-29 01:29:58385 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40386 }
[email protected]0b33f80b2008-12-17 21:34:36387}
388
[email protected]767c9d92012-03-02 16:04:34389PrefService* MetricsLog::GetPrefService() {
390 return g_browser_process->local_state();
391}
392
393gfx::Size MetricsLog::GetScreenSize() const {
[email protected]ffabb1e2012-10-12 19:51:17394 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel();
[email protected]767c9d92012-03-02 16:04:34395}
396
[email protected]aa96417972012-08-22 03:16:44397float MetricsLog::GetScreenDeviceScaleFactor() const {
[email protected]ffabb1e2012-10-12 19:51:17398 return gfx::Screen::GetNativeScreen()->
399 GetPrimaryDisplay().device_scale_factor();
[email protected]aa96417972012-08-22 03:16:44400}
401
[email protected]767c9d92012-03-02 16:04:34402int MetricsLog::GetScreenCount() const {
[email protected]ffabb1e2012-10-12 19:51:17403 // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312
404 return gfx::Screen::GetNativeScreen()->GetNumDisplays();
[email protected]767c9d92012-03-02 16:04:34405}
406
[email protected]767c9d92012-03-02 16:04:34407void MetricsLog::GetFieldTrialIds(
[email protected]0c8b7ad2012-11-06 07:08:14408 std::vector<ActiveGroupId>* field_trial_ids) const {
409 chrome_variations::GetFieldTrialActiveGroupIds(field_trial_ids);
[email protected]767c9d92012-03-02 16:04:34410}
411
[email protected]fe58acc22012-02-29 01:29:58412void MetricsLog::WriteStabilityElement(
413 const std::vector<webkit::WebPluginInfo>& plugin_list,
414 PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:34415 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29416
initial.commit09911bf2008-07-26 23:55:29417 // Get stability attributes out of Local State, zeroing out stored values.
418 // NOTE: This could lead to some data loss if this report isn't successfully
419 // sent, but that's true for all the metrics.
420
[email protected]ffaf78a2008-11-12 17:38:33421 OPEN_ELEMENT_FOR_SCOPE("stability");
[email protected]147bbc0b2009-01-06 19:37:40422 WriteRequiredStabilityAttributes(pref);
423 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29424
[email protected]fe58acc22012-02-29 01:29:58425 int incomplete_shutdown_count =
426 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
[email protected]e324f6b2012-02-28 05:43:37427 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58428 int breakpad_registration_success_count =
429 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
[email protected]e324f6b2012-02-28 05:43:37430 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58431 int breakpad_registration_failure_count =
432 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
[email protected]e324f6b2012-02-28 05:43:37433 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58434 int debugger_present_count =
435 pref->GetInteger(prefs::kStabilityDebuggerPresent);
[email protected]e324f6b2012-02-28 05:43:37436 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58437 int debugger_not_present_count =
438 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
[email protected]e324f6b2012-02-28 05:43:37439 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31440
[email protected]fe58acc22012-02-29 01:29:58441 // TODO(jar): The following are all optional, so we *could* optimize them for
442 // values of zero (and not include them).
443
444 // Write the XML version.
445 WriteIntAttribute("incompleteshutdowncount", incomplete_shutdown_count);
446 WriteIntAttribute("breakpadregistrationok",
447 breakpad_registration_success_count);
448 WriteIntAttribute("breakpadregistrationfail",
449 breakpad_registration_failure_count);
450 WriteIntAttribute("debuggerpresent", debugger_present_count);
451 WriteIntAttribute("debuggernotpresent", debugger_not_present_count);
452
453 // Write the protobuf version.
454 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34455 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58456 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
457 stability->set_breakpad_registration_success_count(
458 breakpad_registration_success_count);
459 stability->set_breakpad_registration_failure_count(
460 breakpad_registration_failure_count);
461 stability->set_debugger_present_count(debugger_present_count);
462 stability->set_debugger_not_present_count(debugger_not_present_count);
463
464 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40465}
466
[email protected]fe58acc22012-02-29 01:29:58467void MetricsLog::WritePluginStabilityElements(
468 const std::vector<webkit::WebPluginInfo>& plugin_list,
469 PrefService* pref) {
[email protected]147bbc0b2009-01-06 19:37:40470 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29471 const ListValue* plugin_stats_list = pref->GetList(
472 prefs::kStabilityPluginStats);
[email protected]1df44b72012-01-19 05:20:34473 if (!plugin_stats_list)
474 return;
initial.commit09911bf2008-07-26 23:55:29475
[email protected]1df44b72012-01-19 05:20:34476 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]ebd71962012-12-20 02:56:55477
478#if defined(ENABLE_PLUGINS)
[email protected]fe58acc22012-02-29 01:29:58479 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34480 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58481 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]1df44b72012-01-19 05:20:34482 for (ListValue::const_iterator iter = plugin_stats_list->begin();
483 iter != plugin_stats_list->end(); ++iter) {
484 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
485 NOTREACHED();
486 continue;
initial.commit09911bf2008-07-26 23:55:29487 }
[email protected]1df44b72012-01-19 05:20:34488 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29489
[email protected]1df44b72012-01-19 05:20:34490 std::string plugin_name;
491 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
492
[email protected]fe58acc22012-02-29 01:29:58493 std::string base64_name_hash;
494 uint64 numeric_name_hash_ignored;
495 CreateHashes(plugin_name, &base64_name_hash, &numeric_name_hash_ignored);
496
497 // Write the XML verison.
[email protected]1df44b72012-01-19 05:20:34498 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
499 // Use "filename" instead of "name", otherwise we need to update the
500 // UMA servers.
[email protected]fe58acc22012-02-29 01:29:58501 WriteAttribute("filename", base64_name_hash);
[email protected]1df44b72012-01-19 05:20:34502
503 int launches = 0;
504 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
505 WriteIntAttribute("launchcount", launches);
506
507 int instances = 0;
508 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
509 WriteIntAttribute("instancecount", instances);
510
511 int crashes = 0;
512 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
513 WriteIntAttribute("crashcount", crashes);
[email protected]fe58acc22012-02-29 01:29:58514
515 // Write the protobuf version.
516 // Note that this search is potentially a quadratic operation, but given the
517 // low number of plugins installed on a "reasonable" setup, this should be
518 // fine.
519 // TODO(isherman): Verify that this does not show up as a hotspot in
520 // profiler runs.
521 const webkit::WebPluginInfo* plugin_info = NULL;
522 const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name);
523 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
524 plugin_list.begin();
525 iter != plugin_list.end(); ++iter) {
526 if (iter->name == plugin_name_utf16) {
527 plugin_info = &(*iter);
528 break;
529 }
530 }
531
532 if (!plugin_info) {
533 NOTREACHED();
534 continue;
535 }
[email protected]cd937072012-07-02 09:00:29536 int loading_errors = 0;
537 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors,
538 &loading_errors);
539 WriteIntAttribute("loadingerrorcount", loading_errors);
[email protected]fe58acc22012-02-29 01:29:58540
[email protected]cd937072012-07-02 09:00:29541 // Write the protobuf version.
[email protected]fe58acc22012-02-29 01:29:58542 SystemProfileProto::Stability::PluginStability* plugin_stability =
543 stability->add_plugin_stability();
544 SetPluginInfo(*plugin_info, plugin_prefs,
545 plugin_stability->mutable_plugin());
546 plugin_stability->set_launch_count(launches);
547 plugin_stability->set_instance_count(instances);
548 plugin_stability->set_crash_count(crashes);
[email protected]cd937072012-07-02 09:00:29549 plugin_stability->set_loading_error_count(loading_errors);
initial.commit09911bf2008-07-26 23:55:29550 }
[email protected]ebd71962012-12-20 02:56:55551#endif // defined(ENABLE_PLUGINS)
[email protected]1df44b72012-01-19 05:20:34552
553 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29554}
555
[email protected]fe58acc22012-02-29 01:29:58556// The server refuses data that doesn't have certain values. crashcount and
557// launchcount are currently "required" in the "stability" group.
558// TODO(isherman): Stop writing these attributes specially once the migration to
559// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40560void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]fe58acc22012-02-29 01:29:58561 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
[email protected]0b33f80b2008-12-17 21:34:36562 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
[email protected]fe58acc22012-02-29 01:29:58563 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
[email protected]0b33f80b2008-12-17 21:34:36564 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58565
566 // Write the XML version.
567 WriteIntAttribute("launchcount", launch_count);
568 WriteIntAttribute("crashcount", crash_count);
569
570 // Write the protobuf version.
571 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34572 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58573 stability->set_launch_count(launch_count);
574 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36575}
576
[email protected]147bbc0b2009-01-06 19:37:40577void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36578 // Update the stats which are critical for real-time stability monitoring.
579 // Since these are "optional," only list ones that are non-zero, as the counts
580 // are aggergated (summed) server side.
581
[email protected]fe58acc22012-02-29 01:29:58582 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34583 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36584 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
585 if (count) {
586 WriteIntAttribute("pageloadcount", count);
[email protected]fe58acc22012-02-29 01:29:58587 stability->set_page_load_count(count);
[email protected]0b33f80b2008-12-17 21:34:36588 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
589 }
590
591 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
592 if (count) {
593 WriteIntAttribute("renderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58594 stability->set_renderer_crash_count(count);
[email protected]0b33f80b2008-12-17 21:34:36595 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
596 }
597
[email protected]1f085622009-12-04 05:33:45598 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
599 if (count) {
600 WriteIntAttribute("extensionrenderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58601 stability->set_extension_renderer_crash_count(count);
[email protected]1f085622009-12-04 05:33:45602 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
603 }
604
[email protected]0b33f80b2008-12-17 21:34:36605 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
606 if (count) {
607 WriteIntAttribute("rendererhangcount", count);
[email protected]fe58acc22012-02-29 01:29:58608 stability->set_renderer_hang_count(count);
[email protected]0b33f80b2008-12-17 21:34:36609 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
610 }
[email protected]1f085622009-12-04 05:33:45611
612 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
613 if (count) {
614 WriteIntAttribute("childprocesscrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58615 stability->set_child_process_crash_count(count);
[email protected]1f085622009-12-04 05:33:45616 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
617 }
[email protected]9165f742010-03-10 22:55:01618
[email protected]c1834a92011-01-21 18:21:03619#if defined(OS_CHROMEOS)
620 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
621 if (count) {
[email protected]fe58acc22012-02-29 01:29:58622 stability->set_other_user_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03623 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
624 }
625
626 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
627 if (count) {
[email protected]fe58acc22012-02-29 01:29:58628 stability->set_kernel_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03629 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
630 }
631
632 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
633 if (count) {
[email protected]fe58acc22012-02-29 01:29:58634 stability->set_unclean_system_shutdown_count(count);
[email protected]c1834a92011-01-21 18:21:03635 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
636 }
637#endif // OS_CHROMEOS
638
[email protected]9165f742010-03-10 22:55:01639 int64 recent_duration = GetIncrementalUptime(pref);
[email protected]fe58acc22012-02-29 01:29:58640 if (recent_duration) {
[email protected]9165f742010-03-10 22:55:01641 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]fe58acc22012-02-29 01:29:58642 stability->set_uptime_sec(recent_duration);
643 }
[email protected]0b33f80b2008-12-17 21:34:36644}
645
initial.commit09911bf2008-07-26 23:55:29646void MetricsLog::WritePluginList(
[email protected]bc66d532012-03-23 01:57:05647 const std::vector<webkit::WebPluginInfo>& plugin_list,
648 bool write_as_xml) {
[email protected]767c9d92012-03-02 16:04:34649 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29650
[email protected]ffaf78a2008-11-12 17:38:33651 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]ebd71962012-12-20 02:56:55652
653#if defined(ENABLE_PLUGINS)
654 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]767c9d92012-03-02 16:04:34655 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]91d9f3d2011-08-14 05:24:44656 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50657 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29658 iter != plugin_list.end(); ++iter) {
[email protected]bc66d532012-03-23 01:57:05659 if (write_as_xml) {
660 std::string base64_name_hash;
661 uint64 numeric_hash_ignored;
662 CreateHashes(UTF16ToUTF8(iter->name), &base64_name_hash,
663 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58664
[email protected]bc66d532012-03-23 01:57:05665 std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe();
666 std::string base64_filename_hash;
667 CreateHashes(filename_bytes, &base64_filename_hash,
668 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58669
[email protected]bc66d532012-03-23 01:57:05670 // Write the XML version.
671 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29672
[email protected]bc66d532012-03-23 01:57:05673 // Plugin name and filename are hashed for the privacy of those
674 // testing unreleased new extensions.
675 WriteAttribute("name", base64_name_hash);
676 WriteAttribute("filename", base64_filename_hash);
677 WriteAttribute("version", UTF16ToUTF8(iter->version));
678 if (plugin_prefs)
679 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
680 } else {
681 // Write the protobuf version.
682 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
683 SetPluginInfo(*iter, plugin_prefs, plugin);
684 }
initial.commit09911bf2008-07-26 23:55:29685 }
[email protected]ebd71962012-12-20 02:56:55686#endif // defined(ENABLE_PLUGINS)
initial.commit09911bf2008-07-26 23:55:29687}
688
[email protected]147bbc0b2009-01-06 19:37:40689void MetricsLog::WriteInstallElement() {
[email protected]fe58acc22012-02-29 01:29:58690 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05691 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]147bbc0b2009-01-06 19:37:40692 OPEN_ELEMENT_FOR_SCOPE("install");
[email protected]cc5d7f42012-10-30 00:30:09693 WriteAttribute("installdate", GetMetricsEnabledDate(GetPrefService()));
[email protected]147bbc0b2009-01-06 19:37:40694 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40695}
696
initial.commit09911bf2008-07-26 23:55:29697void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44698 const std::vector<webkit::WebPluginInfo>& plugin_list,
[email protected]197c0772012-05-14 23:50:51699 const GoogleUpdateMetrics& google_update_metrics,
initial.commit09911bf2008-07-26 23:55:29700 const DictionaryValue* profile_metrics) {
[email protected]767c9d92012-03-02 16:04:34701 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29702
[email protected]767c9d92012-03-02 16:04:34703 PrefService* pref = GetPrefService();
initial.commit09911bf2008-07-26 23:55:29704
[email protected]ffaf78a2008-11-12 17:38:33705 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29706 WriteCommonEventAttributes();
707
[email protected]147bbc0b2009-01-06 19:37:40708 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29709
[email protected]bc66d532012-03-23 01:57:05710 // Write the XML version.
711 // We'll write the protobuf version in RecordEnvironmentProto().
712 bool write_as_xml = true;
713 WritePluginList(plugin_list, write_as_xml);
initial.commit09911bf2008-07-26 23:55:29714
[email protected]fe58acc22012-02-29 01:29:58715 WriteStabilityElement(plugin_list, pref);
initial.commit09911bf2008-07-26 23:55:29716
717 {
[email protected]fe58acc22012-02-29 01:29:58718 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05719 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29720 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]0b6a4fb2012-10-16 01:58:21721 WriteAttribute("arch", base::SysInfo::OperatingSystemArchitecture());
initial.commit09911bf2008-07-26 23:55:29722 }
723
724 {
[email protected]fe58acc22012-02-29 01:29:58725 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05726 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29727 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]bc66d532012-03-23 01:57:05728 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38729#if defined(OS_WIN)
730 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
731#endif
initial.commit09911bf2008-07-26 23:55:29732 }
733
734 {
[email protected]fe58acc22012-02-29 01:29:58735 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05736 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29737 OPEN_ELEMENT_FOR_SCOPE("os");
[email protected]bc66d532012-03-23 01:57:05738 WriteAttribute("name", base::SysInfo::OperatingSystemName());
739 WriteAttribute("version", base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29740 }
741
742 {
[email protected]e8c287c872010-07-20 00:49:42743 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]fe58acc22012-02-29 01:29:58744 const content::GPUInfo& gpu_info =
745 GpuDataManager::GetInstance()->GetGPUInfo();
[email protected]fe58acc22012-02-29 01:29:58746
747 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05748 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]a094e2c2012-05-10 23:02:42749 WriteIntAttribute("vendorid", gpu_info.gpu.vendor_id);
750 WriteIntAttribute("deviceid", gpu_info.gpu.device_id);
[email protected]e8c287c872010-07-20 00:49:42751 }
752
753 {
[email protected]767c9d92012-03-02 16:04:34754 const gfx::Size display_size = GetScreenSize();
[email protected]fe58acc22012-02-29 01:29:58755
756 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05757 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]fe58acc22012-02-29 01:29:58758 OPEN_ELEMENT_FOR_SCOPE("display");
[email protected]bc66d532012-03-23 01:57:05759 WriteIntAttribute("xsize", display_size.width());
760 WriteIntAttribute("ysize", display_size.height());
761 WriteIntAttribute("screens", GetScreenCount());
initial.commit09911bf2008-07-26 23:55:29762 }
763
764 {
765 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
initial.commit09911bf2008-07-26 23:55:29766 {
767 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
768 WriteAttribute("name", "full-tree");
[email protected]8542bcc2013-01-30 00:15:36769 WriteIntAttribute("foldercount", 0);
770 WriteIntAttribute("itemcount", 0);
initial.commit09911bf2008-07-26 23:55:29771 }
772 {
773 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
774 WriteAttribute("name", "toolbar");
[email protected]8542bcc2013-01-30 00:15:36775 WriteIntAttribute("foldercount", 0);
776 WriteIntAttribute("itemcount", 0);
initial.commit09911bf2008-07-26 23:55:29777 }
778 }
779
780 {
781 OPEN_ELEMENT_FOR_SCOPE("keywords");
782 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
783 }
784
785 if (profile_metrics)
786 WriteAllProfilesMetrics(*profile_metrics);
[email protected]767c9d92012-03-02 16:04:34787
[email protected]197c0772012-05-14 23:50:51788 RecordEnvironmentProto(plugin_list, google_update_metrics);
[email protected]bc66d532012-03-23 01:57:05789}
790
791void MetricsLog::RecordEnvironmentProto(
[email protected]197c0772012-05-14 23:50:51792 const std::vector<webkit::WebPluginInfo>& plugin_list,
793 const GoogleUpdateMetrics& google_update_metrics) {
[email protected]bc66d532012-03-23 01:57:05794 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]24b9bb392013-01-29 20:29:29795
796 std::string brand_code;
797 if (google_util::GetBrand(&brand_code))
798 system_profile->set_brand_code(brand_code);
799
[email protected]cc5d7f42012-10-30 00:30:09800 int enabled_date;
801 bool success = base::StringToInt(GetMetricsEnabledDate(GetPrefService()),
802 &enabled_date);
[email protected]bc66d532012-03-23 01:57:05803 DCHECK(success);
[email protected]cc5d7f42012-10-30 00:30:09804 system_profile->set_uma_enabled_date(enabled_date);
[email protected]bc66d532012-03-23 01:57:05805
806 system_profile->set_application_locale(
807 content::GetContentClient()->browser()->GetApplicationLocale());
808
809 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
[email protected]0b6a4fb2012-10-16 01:58:21810 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
[email protected]bc66d532012-03-23 01:57:05811 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
812#if defined(OS_WIN)
813 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
814#endif
815
[email protected]74b299e2013-01-29 01:24:42816 SystemProfileProto::Network* network = system_profile->mutable_network();
817 network->set_connection_type_is_ambiguous(
[email protected]5eae204c2013-02-13 15:53:42818 network_observer_.connection_type_is_ambiguous());
819 network->set_connection_type(network_observer_.connection_type());
820 network->set_wifi_phy_layer_protocol_is_ambiguous(
821 network_observer_.wifi_phy_layer_protocol_is_ambiguous());
822 network->set_wifi_phy_layer_protocol(
823 network_observer_.wifi_phy_layer_protocol());
824 network_observer_.Reset();
[email protected]74b299e2013-01-29 01:24:42825
[email protected]bc66d532012-03-23 01:57:05826 SystemProfileProto::OS* os = system_profile->mutable_os();
[email protected]1bb25e02012-08-03 22:39:39827 std::string os_name = base::SysInfo::OperatingSystemName();
828#if defined(OS_WIN)
829 // TODO(mad): This only checks whether the main process is a Metro process at
830 // upload time; not whether the collected metrics were all gathered from
831 // Metro. This is ok as an approximation for now, since users will rarely be
832 // switching from Metro to Desktop mode; but we should re-evaluate whether we
833 // can distinguish metrics more cleanly in the future: http://crbug.com/140568
834 if (base::win::IsMetroProcess())
835 os_name += " (Metro)";
836#endif
837 os->set_name(os_name);
[email protected]bc66d532012-03-23 01:57:05838 os->set_version(base::SysInfo::OperatingSystemVersion());
[email protected]5106b3a2012-10-03 20:10:44839#if defined(OS_ANDROID)
840 os->set_fingerprint(
841 base::android::BuildInfo::GetInstance()->android_build_fp());
842#endif
[email protected]bc66d532012-03-23 01:57:05843
844 const content::GPUInfo& gpu_info =
845 GpuDataManager::GetInstance()->GetGPUInfo();
846 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
[email protected]a094e2c2012-05-10 23:02:42847 gpu->set_vendor_id(gpu_info.gpu.vendor_id);
848 gpu->set_device_id(gpu_info.gpu.device_id);
[email protected]bc66d532012-03-23 01:57:05849 gpu->set_driver_version(gpu_info.driver_version);
850 gpu->set_driver_date(gpu_info.driver_date);
851 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
852 gpu_performance = gpu->mutable_performance_statistics();
853 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
854 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
855 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
[email protected]d6bdfae2013-01-18 20:23:01856 gpu->set_gl_vendor(gpu_info.gl_vendor);
857 gpu->set_gl_renderer(gpu_info.gl_renderer);
[email protected]bc66d532012-03-23 01:57:05858
859 const gfx::Size display_size = GetScreenSize();
860 hardware->set_primary_screen_width(display_size.width());
861 hardware->set_primary_screen_height(display_size.height());
[email protected]aa96417972012-08-22 03:16:44862 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor());
[email protected]bc66d532012-03-23 01:57:05863 hardware->set_screen_count(GetScreenCount());
864
[email protected]76869ff2013-01-15 16:13:47865#if defined(OS_WIN)
866 WriteScreenDPIInformationProto(hardware);
867#endif
868
[email protected]197c0772012-05-14 23:50:51869 WriteGoogleUpdateProto(google_update_metrics);
870
[email protected]bc66d532012-03-23 01:57:05871 bool write_as_xml = false;
872 WritePluginList(plugin_list, write_as_xml);
873
[email protected]0c8b7ad2012-11-06 07:08:14874 std::vector<ActiveGroupId> field_trial_ids;
[email protected]767c9d92012-03-02 16:04:34875 GetFieldTrialIds(&field_trial_ids);
876 WriteFieldTrials(field_trial_ids, system_profile);
[email protected]f65859e2013-02-04 20:00:25877
878#if defined(OS_CHROMEOS)
879 PerfDataProto perf_data_proto;
880 if (perf_provider_.GetPerfData(&perf_data_proto))
881 uma_proto()->add_perf_data()->Swap(&perf_data_proto);
882#endif
initial.commit09911bf2008-07-26 23:55:29883}
884
[email protected]ed0fd002012-04-25 23:10:34885void MetricsLog::RecordProfilerData(
886 const tracked_objects::ProcessDataSnapshot& process_data,
887 content::ProcessType process_type) {
888 DCHECK(!locked());
889
[email protected]8f829682012-04-27 00:36:49890 if (tracked_objects::GetTimeSourceType() !=
891 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) {
[email protected]ed0fd002012-04-25 23:10:34892 // We currently only support the default time source, wall clock time.
893 return;
894 }
895
896 ProfilerEventProto* profile;
897 if (!uma_proto()->profiler_event_size()) {
898 // For the first process's data, add a new field to the protocol buffer.
899 profile = uma_proto()->add_profiler_event();
900 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
901 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
902 } else {
903 // For the remaining calls, re-use the existing field.
904 profile = uma_proto()->mutable_profiler_event(0);
905 }
906
907 WriteProfilerData(process_data, process_type, profile);
908}
909
initial.commit09911bf2008-07-26 23:55:29910void MetricsLog::WriteAllProfilesMetrics(
911 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51912 const std::string profile_prefix(prefs::kProfilePrefix);
initial.commit09911bf2008-07-26 23:55:29913 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
914 i != all_profiles_metrics.end_keys(); ++i) {
[email protected]e7b418b2010-07-30 19:47:47915 const std::string& key_name = *i;
initial.commit09911bf2008-07-26 23:55:29916 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
[email protected]a61890e2012-07-27 22:27:11917 const DictionaryValue* profile;
[email protected]4dad9ad82009-11-25 20:47:52918 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
919 &profile))
initial.commit09911bf2008-07-26 23:55:29920 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
921 }
922 }
923}
924
[email protected]e7b418b2010-07-30 19:47:47925void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29926 const DictionaryValue& profile_metrics) {
927 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47928 WriteAttribute("profileidhash", profileidhash);
initial.commit09911bf2008-07-26 23:55:29929 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
930 i != profile_metrics.end_keys(); ++i) {
[email protected]a61890e2012-07-27 22:27:11931 const Value* value;
[email protected]4dad9ad82009-11-25 20:47:52932 if (profile_metrics.GetWithoutPathExpansion(*i, &value)) {
[email protected]0b6a4fb2012-10-16 01:58:21933 DCHECK_NE(*i, "id");
initial.commit09911bf2008-07-26 23:55:29934 switch (value->GetType()) {
935 case Value::TYPE_STRING: {
[email protected]5e324b72008-12-18 00:07:59936 std::string string_value;
initial.commit09911bf2008-07-26 23:55:29937 if (value->GetAsString(&string_value)) {
938 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47939 WriteAttribute("name", *i);
[email protected]5e324b72008-12-18 00:07:59940 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29941 }
942 break;
943 }
944
945 case Value::TYPE_BOOLEAN: {
946 bool bool_value;
947 if (value->GetAsBoolean(&bool_value)) {
948 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47949 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29950 WriteIntAttribute("value", bool_value ? 1 : 0);
951 }
952 break;
953 }
954
955 case Value::TYPE_INTEGER: {
956 int int_value;
957 if (value->GetAsInteger(&int_value)) {
958 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47959 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29960 WriteIntAttribute("value", int_value);
961 }
962 break;
963 }
964
965 default:
966 NOTREACHED();
967 break;
968 }
969 }
970 }
971}
972
973void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
[email protected]767c9d92012-03-02 16:04:34974 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29975
[email protected]fe58acc22012-02-29 01:29:58976 // Write the XML version.
[email protected]ffaf78a2008-11-12 17:38:33977 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29978 WriteAttribute("action", "autocomplete");
979 WriteAttribute("targetidhash", "");
980 // TODO(kochi): Properly track windows.
981 WriteIntAttribute("window", 0);
[email protected]6ebc3162011-12-19 13:44:00982 if (log.tab_id != -1) {
983 // If we know what tab the autocomplete URL was opened in, log it.
984 WriteIntAttribute("tab", static_cast<int>(log.tab_id));
985 }
initial.commit09911bf2008-07-26 23:55:29986 WriteCommonEventAttributes();
987
[email protected]65956312012-04-19 21:28:12988 std::vector<string16> terms;
989 const int num_terms =
990 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms));
[email protected]ffaf78a2008-11-12 17:38:33991 {
992 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29993
[email protected]ffaf78a2008-11-12 17:38:33994 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
[email protected]65956312012-04-19 21:28:12995 WriteIntAttribute("numterms", num_terms);
[email protected]ffaf78a2008-11-12 17:38:33996 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
997 WriteIntAttribute("completedlength",
[email protected]62b3ef52013-01-18 00:13:02998 log.completed_length != string16::npos ?
999 static_cast<int>(log.completed_length) : 0);
[email protected]9e349762012-01-31 03:24:361000 if (log.elapsed_time_since_user_first_modified_omnibox !=
1001 base::TimeDelta::FromMilliseconds(-1)) {
1002 // Only upload the typing duration if it is set/valid.
1003 WriteInt64Attribute("typingduration",
1004 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
1005 }
[email protected]381e2992008-12-16 01:41:001006 const std::string input_type(
1007 AutocompleteInput::TypeToString(log.input_type));
1008 if (!input_type.empty())
1009 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:291010
[email protected]ffaf78a2008-11-12 17:38:331011 for (AutocompleteResult::const_iterator i(log.result.begin());
1012 i != log.result.end(); ++i) {
1013 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
1014 if (i->provider)
[email protected]35f1f4f02012-09-11 13:17:001015 WriteAttribute("provider", i->provider->GetName());
[email protected]381e2992008-12-16 01:41:001016 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
1017 if (!result_type.empty())
1018 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:331019 WriteIntAttribute("relevance", i->relevance);
1020 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
1021 }
initial.commit09911bf2008-07-26 23:55:291022 }
initial.commit09911bf2008-07-26 23:55:291023
[email protected]fe58acc22012-02-29 01:29:581024 // Write the protobuf version.
[email protected]767c9d92012-03-02 16:04:341025 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
[email protected]fe58acc22012-02-29 01:29:581026 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
1027 if (log.tab_id != -1) {
1028 // If we know what tab the autocomplete URL was opened in, log it.
1029 omnibox_event->set_tab_id(log.tab_id);
1030 }
1031 omnibox_event->set_typed_length(log.text.length());
[email protected]660fe8f32012-05-03 20:01:081032 omnibox_event->set_just_deleted_text(log.just_deleted_text);
[email protected]65956312012-04-19 21:28:121033 omnibox_event->set_num_typed_terms(num_terms);
[email protected]fe58acc22012-02-29 01:29:581034 omnibox_event->set_selected_index(log.selected_index);
[email protected]62b3ef52013-01-18 00:13:021035 if (log.completed_length != string16::npos)
1036 omnibox_event->set_completed_length(log.completed_length);
[email protected]65956312012-04-19 21:28:121037 if (log.elapsed_time_since_user_first_modified_omnibox !=
1038 base::TimeDelta::FromMilliseconds(-1)) {
1039 // Only upload the typing duration if it is set/valid.
1040 omnibox_event->set_typing_duration_ms(
1041 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
1042 }
[email protected]35d55602012-11-20 23:49:031043 omnibox_event->set_duration_since_last_default_match_update_ms(
1044 log.elapsed_time_since_last_change_to_default_match.InMilliseconds());
[email protected]ee902532012-05-01 23:54:491045 omnibox_event->set_current_page_classification(
1046 log.current_page_classification);
[email protected]fe58acc22012-02-29 01:29:581047 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
1048 for (AutocompleteResult::const_iterator i(log.result.begin());
1049 i != log.result.end(); ++i) {
1050 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
[email protected]0e9e8782012-05-15 23:01:511051 suggestion->set_provider(i->provider->AsOmniboxEventProviderType());
[email protected]fe58acc22012-02-29 01:29:581052 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
1053 suggestion->set_relevance(i->relevance);
[email protected]cf6256f2012-06-12 23:36:011054 if (i->typed_count != -1)
1055 suggestion->set_typed_count(i->typed_count);
[email protected]fe58acc22012-02-29 01:29:581056 suggestion->set_is_starred(i->starred);
1057 }
[email protected]0e9e8782012-05-15 23:01:511058 for (ProvidersInfo::const_iterator i(log.providers_info.begin());
1059 i != log.providers_info.end(); ++i) {
1060 OmniboxEventProto::ProviderInfo* provider_info =
1061 omnibox_event->add_provider_info();
1062 provider_info->CopyFrom(*i);
1063 }
[email protected]fe58acc22012-02-29 01:29:581064
initial.commit09911bf2008-07-26 23:55:291065 ++num_events_;
1066}
[email protected]197c0772012-05-14 23:50:511067
1068void MetricsLog::WriteGoogleUpdateProto(
1069 const GoogleUpdateMetrics& google_update_metrics) {
1070#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
1071 SystemProfileProto::GoogleUpdate* google_update =
1072 uma_proto()->mutable_system_profile()->mutable_google_update();
1073
1074 google_update->set_is_system_install(google_update_metrics.is_system_install);
1075
1076 if (!google_update_metrics.last_started_au.is_null()) {
1077 google_update->set_last_automatic_start_timestamp(
1078 google_update_metrics.last_started_au.ToTimeT());
1079 }
1080
1081 if (!google_update_metrics.last_checked.is_null()) {
1082 google_update->set_last_update_check_timestamp(
1083 google_update_metrics.last_checked.ToTimeT());
1084 }
1085
1086 if (!google_update_metrics.google_update_data.version.empty()) {
1087 ProductDataToProto(google_update_metrics.google_update_data,
1088 google_update->mutable_google_update_status());
1089 }
1090
1091 if (!google_update_metrics.product_data.version.empty()) {
1092 ProductDataToProto(google_update_metrics.product_data,
1093 google_update->mutable_client_status());
1094 }
1095#endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
1096}