blob: 2771aa9f077ce10addf5e1884d457f4991ee50fe [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]1eeb5e02010-07-20 23:02:117#include <string>
8#include <vector>
9
[email protected]d1be67b2008-11-19 20:28:3810#include "base/basictypes.h"
initial.commit09911bf2008-07-26 23:55:2911#include "base/file_util.h"
[email protected]054c8012011-11-16 00:12:4212#include "base/lazy_instance.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/scoped_ptr.h"
[email protected]85ed9d42010-06-08 22:37:4414#include "base/perftimer.h"
[email protected]ed0fd002012-04-25 23:10:3415#include "base/profiler/alternate_timer.h"
[email protected]fe58acc22012-02-29 01:29:5816#include "base/string_number_conversions.h"
initial.commit09911bf2008-07-26 23:55:2917#include "base/string_util.h"
[email protected]fadf97f2008-09-18 12:18:1418#include "base/sys_info.h"
[email protected]37f39e42010-01-06 17:35:1719#include "base/third_party/nspr/prtime.h"
[email protected]1eeb5e02010-07-20 23:02:1120#include "base/time.h"
[email protected]ed0fd002012-04-25 23:10:3421#include "base/tracked_objects.h"
[email protected]1eeb5e02010-07-20 23:02:1122#include "base/utf_string_conversions.h"
[email protected]9f8bc2f2012-07-03 16:26:5323#include "chrome/browser/autocomplete/autocomplete_input.h"
[email protected]19871a92012-06-27 19:50:3224#include "chrome/browser/autocomplete/autocomplete_log.h"
[email protected]9ac40092010-10-27 23:05:2625#include "chrome/browser/autocomplete/autocomplete_match.h"
[email protected]30f5bc92012-06-26 04:14:5526#include "chrome/browser/autocomplete/autocomplete_provider.h"
[email protected]73c2b1632012-07-02 22:51:3827#include "chrome/browser/autocomplete/autocomplete_result.h"
initial.commit09911bf2008-07-26 23:55:2928#include "chrome/browser/browser_process.h"
[email protected]0f5e57f52012-09-20 20:53:1829#include "chrome/browser/plugins/plugin_prefs.h"
[email protected]37858e52010-08-26 00:22:0230#include "chrome/browser/prefs/pref_service.h"
[email protected]10084982011-08-19 17:56:5631#include "chrome/browser/profiles/profile_manager.h"
[email protected]1eeb5e02010-07-20 23:02:1132#include "chrome/common/chrome_version_info.h"
initial.commit09911bf2008-07-26 23:55:2933#include "chrome/common/logging_chrome.h"
[email protected]fe58acc22012-02-29 01:29:5834#include "chrome/common/metrics/proto/omnibox_event.pb.h"
[email protected]ed0fd002012-04-25 23:10:3435#include "chrome/common/metrics/proto/profiler_event.pb.h"
[email protected]fe58acc22012-02-29 01:29:5836#include "chrome/common/metrics/proto/system_profile.pb.h"
[email protected]cf265dc02012-08-15 01:01:1637#include "chrome/common/metrics/variations/variations_util.h"
initial.commit09911bf2008-07-26 23:55:2938#include "chrome/common/pref_names.h"
[email protected]197c0772012-05-14 23:50:5139#include "chrome/installer/util/google_update_settings.h"
[email protected]fe58acc22012-02-29 01:29:5840#include "content/public/browser/content_browser_client.h"
[email protected]79078df2012-02-16 01:22:3241#include "content/public/browser/gpu_data_manager.h"
[email protected]1a838cc2012-04-24 22:06:4942#include "content/public/common/content_client.h"
[email protected]ed0fd002012-04-25 23:10:3443#include "content/public/common/gpu_info.h"
[email protected]46072d42008-07-28 14:49:3544#include "googleurl/src/gurl.h"
[email protected]6b7d954ff2011-10-25 00:39:3545#include "ui/gfx/screen.h"
[email protected]91d9f3d2011-08-14 05:24:4446#include "webkit/plugins/webplugininfo.h"
initial.commit09911bf2008-07-26 23:55:2947
48#define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
49
[email protected]d1be67b2008-11-19 20:28:3850#if defined(OS_WIN)
[email protected]1bb25e02012-08-03 22:39:3951#include "base/win/metro.h"
52
53// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
[email protected]d1be67b2008-11-19 20:28:3854extern "C" IMAGE_DOS_HEADER __ImageBase;
55#endif
56
[email protected]79078df2012-02-16 01:22:3257using content::GpuDataManager;
[email protected]fe58acc22012-02-29 01:29:5858using metrics::OmniboxEventProto;
[email protected]ed0fd002012-04-25 23:10:3459using metrics::ProfilerEventProto;
[email protected]fe58acc22012-02-29 01:29:5860using metrics::SystemProfileProto;
[email protected]ed0fd002012-04-25 23:10:3461using tracked_objects::ProcessDataSnapshot;
[email protected]2ac73f62012-08-13 21:49:0762typedef chrome_variations::SelectedGroupId SelectedGroupId;
[email protected]197c0772012-05-14 23:50:5163typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo;
[email protected]79078df2012-02-16 01:22:3264
[email protected]1df44b72012-01-19 05:20:3465namespace {
66
67// Returns the date at which the current metrics client ID was created as
68// a string containing milliseconds since the epoch, or "0" if none was found.
[email protected]767c9d92012-03-02 16:04:3469std::string GetInstallDate(PrefService* pref) {
70 if (!pref) {
[email protected]1df44b72012-01-19 05:20:3471 NOTREACHED();
72 return "0";
73 }
[email protected]767c9d92012-03-02 16:04:3474
75 return pref->GetString(prefs::kMetricsClientIDTimestamp);
[email protected]1df44b72012-01-19 05:20:3476}
77
[email protected]fe58acc22012-02-29 01:29:5878OmniboxEventProto::InputType AsOmniboxEventInputType(
79 AutocompleteInput::Type type) {
80 switch (type) {
81 case AutocompleteInput::INVALID:
82 return OmniboxEventProto::INVALID;
83 case AutocompleteInput::UNKNOWN:
84 return OmniboxEventProto::UNKNOWN;
85 case AutocompleteInput::REQUESTED_URL:
86 return OmniboxEventProto::REQUESTED_URL;
87 case AutocompleteInput::URL:
88 return OmniboxEventProto::URL;
89 case AutocompleteInput::QUERY:
90 return OmniboxEventProto::QUERY;
91 case AutocompleteInput::FORCED_QUERY:
92 return OmniboxEventProto::FORCED_QUERY;
93 default:
94 NOTREACHED();
95 return OmniboxEventProto::INVALID;
96 }
97}
98
[email protected]fe58acc22012-02-29 01:29:5899OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
100 AutocompleteMatch::Type type) {
101 switch (type) {
102 case AutocompleteMatch::URL_WHAT_YOU_TYPED:
103 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
104 case AutocompleteMatch::HISTORY_URL:
105 return OmniboxEventProto::Suggestion::HISTORY_URL;
106 case AutocompleteMatch::HISTORY_TITLE:
107 return OmniboxEventProto::Suggestion::HISTORY_TITLE;
108 case AutocompleteMatch::HISTORY_BODY:
109 return OmniboxEventProto::Suggestion::HISTORY_BODY;
110 case AutocompleteMatch::HISTORY_KEYWORD:
111 return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
112 case AutocompleteMatch::NAVSUGGEST:
113 return OmniboxEventProto::Suggestion::NAVSUGGEST;
114 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
115 return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
116 case AutocompleteMatch::SEARCH_HISTORY:
117 return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
118 case AutocompleteMatch::SEARCH_SUGGEST:
119 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
120 case AutocompleteMatch::SEARCH_OTHER_ENGINE:
121 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
122 case AutocompleteMatch::EXTENSION_APP:
123 return OmniboxEventProto::Suggestion::EXTENSION_APP;
[email protected]dbacefb2012-09-12 03:32:06124 case AutocompleteMatch::CONTACT:
125 return OmniboxEventProto::Suggestion::CONTACT;
[email protected]fe58acc22012-02-29 01:29:58126 default:
127 NOTREACHED();
128 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
129 }
130}
131
[email protected]ed0fd002012-04-25 23:10:34132ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType(
133 content::ProcessType process_type) {
134 switch (process_type) {
135 case content::PROCESS_TYPE_BROWSER:
136 return ProfilerEventProto::TrackedObject::BROWSER;
137 case content::PROCESS_TYPE_RENDERER:
138 return ProfilerEventProto::TrackedObject::RENDERER;
139 case content::PROCESS_TYPE_PLUGIN:
140 return ProfilerEventProto::TrackedObject::PLUGIN;
141 case content::PROCESS_TYPE_WORKER:
142 return ProfilerEventProto::TrackedObject::WORKER;
143 case content::PROCESS_TYPE_NACL_LOADER:
144 return ProfilerEventProto::TrackedObject::NACL_LOADER;
145 case content::PROCESS_TYPE_UTILITY:
146 return ProfilerEventProto::TrackedObject::UTILITY;
147 case content::PROCESS_TYPE_PROFILE_IMPORT:
148 return ProfilerEventProto::TrackedObject::PROFILE_IMPORT;
149 case content::PROCESS_TYPE_ZYGOTE:
150 return ProfilerEventProto::TrackedObject::ZYGOTE;
151 case content::PROCESS_TYPE_SANDBOX_HELPER:
152 return ProfilerEventProto::TrackedObject::SANDBOX_HELPER;
153 case content::PROCESS_TYPE_NACL_BROKER:
154 return ProfilerEventProto::TrackedObject::NACL_BROKER;
155 case content::PROCESS_TYPE_GPU:
156 return ProfilerEventProto::TrackedObject::GPU;
157 case content::PROCESS_TYPE_PPAPI_PLUGIN:
158 return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN;
159 case content::PROCESS_TYPE_PPAPI_BROKER:
160 return ProfilerEventProto::TrackedObject::PPAPI_BROKER;
161 default:
162 NOTREACHED();
163 return ProfilerEventProto::TrackedObject::UNKNOWN;
164 }
165}
166
[email protected]1df44b72012-01-19 05:20:34167// Returns the plugin preferences corresponding for this user, if available.
168// If multiple user profiles are loaded, returns the preferences corresponding
169// to an arbitrary one of the profiles.
170PluginPrefs* GetPluginPrefs() {
171 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]fe58acc22012-02-29 01:29:58172
173 if (!profile_manager) {
174 // The profile manager can be NULL when testing.
175 return NULL;
176 }
177
[email protected]1df44b72012-01-19 05:20:34178 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
179 if (profiles.empty())
180 return NULL;
181
182 return PluginPrefs::GetForProfile(profiles.front());
183}
184
[email protected]fe58acc22012-02-29 01:29:58185// Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
186void SetPluginInfo(const webkit::WebPluginInfo& plugin_info,
187 const PluginPrefs* plugin_prefs,
188 SystemProfileProto::Plugin* plugin) {
189 plugin->set_name(UTF16ToUTF8(plugin_info.name));
190 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
191 plugin->set_version(UTF16ToUTF8(plugin_info.version));
192 if (plugin_prefs)
193 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
194}
195
[email protected]ad2461c2012-04-27 21:11:03196void WriteFieldTrials(const std::vector<SelectedGroupId>& field_trial_ids,
[email protected]767c9d92012-03-02 16:04:34197 SystemProfileProto* system_profile) {
[email protected]ad2461c2012-04-27 21:11:03198 for (std::vector<SelectedGroupId>::const_iterator it =
199 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
[email protected]767c9d92012-03-02 16:04:34200 SystemProfileProto::FieldTrial* field_trial =
201 system_profile->add_field_trial();
202 field_trial->set_name_id(it->name);
203 field_trial->set_group_id(it->group);
204 }
205}
206
[email protected]ed0fd002012-04-25 23:10:34207void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
208 content::ProcessType process_type,
209 ProfilerEventProto* performance_profile) {
210 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it =
211 profiler_data.tasks.begin();
212 it != profiler_data.tasks.end(); ++it) {
213 std::string ignored;
214 uint64 birth_thread_name_hash;
215 uint64 exec_thread_name_hash;
216 uint64 source_file_name_hash;
217 uint64 source_function_name_hash;
218 MetricsLogBase::CreateHashes(it->birth.thread_name,
219 &ignored, &birth_thread_name_hash);
220 MetricsLogBase::CreateHashes(it->death_thread_name,
221 &ignored, &exec_thread_name_hash);
222 MetricsLogBase::CreateHashes(it->birth.location.function_name,
223 &ignored, &source_file_name_hash);
224 MetricsLogBase::CreateHashes(it->birth.location.file_name,
225 &ignored, &source_function_name_hash);
226
227 const tracked_objects::DeathDataSnapshot& death_data = it->death_data;
228 ProfilerEventProto::TrackedObject* tracked_object =
229 performance_profile->add_tracked_object();
230 tracked_object->set_birth_thread_name_hash(birth_thread_name_hash);
231 tracked_object->set_exec_thread_name_hash(exec_thread_name_hash);
232 tracked_object->set_source_file_name_hash(source_file_name_hash);
233 tracked_object->set_source_function_name_hash(source_function_name_hash);
234 tracked_object->set_source_line_number(it->birth.location.line_number);
235 tracked_object->set_exec_count(death_data.count);
236 tracked_object->set_exec_time_total(death_data.run_duration_sum);
237 tracked_object->set_exec_time_sampled(death_data.run_duration_sample);
238 tracked_object->set_queue_time_total(death_data.queue_duration_sum);
239 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample);
240 tracked_object->set_process_type(AsProtobufProcessType(process_type));
241 tracked_object->set_process_id(profiler_data.process_id);
242 }
243}
244
[email protected]59a7ae4e2012-10-01 23:54:44245#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
[email protected]197c0772012-05-14 23:50:51246void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data,
247 ProductInfo* product_info) {
248 product_info->set_version(product_data.version);
249 product_info->set_last_update_success_timestamp(
250 product_data.last_success.ToTimeT());
251 product_info->set_last_error(product_data.last_error_code);
252 product_info->set_last_extra_error(product_data.last_extra_code);
253 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) {
254 product_info->set_last_result(
255 static_cast<ProductInfo::InstallResult>(product_data.last_result));
256 }
257}
[email protected]59a7ae4e2012-10-01 23:54:44258#endif
[email protected]197c0772012-05-14 23:50:51259
[email protected]1df44b72012-01-19 05:20:34260} // namespace
261
[email protected]197c0772012-05-14 23:50:51262GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {}
263
264GoogleUpdateMetrics::~GoogleUpdateMetrics() {}
265
[email protected]67f92bc32012-01-26 01:56:19266static base::LazyInstance<std::string>::Leaky
[email protected]054c8012011-11-16 00:12:42267 g_version_extension = LAZY_INSTANCE_INITIALIZER;
268
[email protected]1226abb2010-06-10 18:01:28269MetricsLog::MetricsLog(const std::string& client_id, int session_id)
270 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:41271
[email protected]1226abb2010-06-10 18:01:28272MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:29273
274// static
275void MetricsLog::RegisterPrefs(PrefService* local_state) {
276 local_state->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29277}
278
[email protected]1df44b72012-01-19 05:20:34279// static
[email protected]9165f742010-03-10 22:55:01280int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
281 base::TimeTicks now = base::TimeTicks::Now();
282 static base::TimeTicks last_updated_time(now);
283 int64 incremental_time = (now - last_updated_time).InSeconds();
284 last_updated_time = now;
285
286 if (incremental_time > 0) {
287 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
288 metrics_uptime += incremental_time;
289 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
290 }
291
292 return incremental_time;
293}
294
[email protected]1226abb2010-06-10 18:01:28295// static
296std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:42297 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:17298 if (!version_info.is_valid()) {
299 NOTREACHED() << "Unable to retrieve version info.";
300 return std::string();
301 }
302
[email protected]0211f57e2010-08-27 20:28:42303 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:42304 if (!version_extension().empty())
305 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:42306 if (!version_info.IsOfficialBuild())
307 version.append("-devel");
308 return version;
[email protected]1226abb2010-06-10 18:01:28309}
310
[email protected]054c8012011-11-16 00:12:42311// static
312void MetricsLog::set_version_extension(const std::string& extension) {
313 g_version_extension.Get() = extension;
314}
315
316// static
317const std::string& MetricsLog::version_extension() {
318 return g_version_extension.Get();
319}
320
[email protected]fe58acc22012-02-29 01:29:58321void MetricsLog::RecordIncrementalStabilityElements(
322 const std::vector<webkit::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34323 DCHECK(!locked());
[email protected]0b33f80b2008-12-17 21:34:36324
[email protected]767c9d92012-03-02 16:04:34325 PrefService* pref = GetPrefService();
[email protected]0b33f80b2008-12-17 21:34:36326 DCHECK(pref);
327
[email protected]147bbc0b2009-01-06 19:37:40328 OPEN_ELEMENT_FOR_SCOPE("profile");
329 WriteCommonEventAttributes();
330
[email protected]9958a322011-03-08 20:04:17331 WriteInstallElement();
[email protected]147bbc0b2009-01-06 19:37:40332
333 {
334 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
335 WriteRequiredStabilityAttributes(pref);
336 WriteRealtimeStabilityAttributes(pref);
337
[email protected]fe58acc22012-02-29 01:29:58338 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40339 }
[email protected]0b33f80b2008-12-17 21:34:36340}
341
[email protected]767c9d92012-03-02 16:04:34342PrefService* MetricsLog::GetPrefService() {
343 return g_browser_process->local_state();
344}
345
346gfx::Size MetricsLog::GetScreenSize() const {
[email protected]42c0a0c62012-06-17 03:50:33347 return gfx::Screen::GetPrimaryDisplay().GetSizeInPixel();
[email protected]767c9d92012-03-02 16:04:34348}
349
[email protected]aa96417972012-08-22 03:16:44350float MetricsLog::GetScreenDeviceScaleFactor() const {
351 return gfx::Screen::GetPrimaryDisplay().device_scale_factor();
352}
353
[email protected]767c9d92012-03-02 16:04:34354int MetricsLog::GetScreenCount() const {
[email protected]42c0a0c62012-06-17 03:50:33355 return gfx::Screen::GetNumDisplays();
[email protected]767c9d92012-03-02 16:04:34356}
357
[email protected]767c9d92012-03-02 16:04:34358void MetricsLog::GetFieldTrialIds(
[email protected]ad2461c2012-04-27 21:11:03359 std::vector<SelectedGroupId>* field_trial_ids) const {
[email protected]2ac73f62012-08-13 21:49:07360 chrome_variations::GetFieldTrialSelectedGroupIds(field_trial_ids);
[email protected]767c9d92012-03-02 16:04:34361}
362
[email protected]fe58acc22012-02-29 01:29:58363void MetricsLog::WriteStabilityElement(
364 const std::vector<webkit::WebPluginInfo>& plugin_list,
365 PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:34366 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29367
initial.commit09911bf2008-07-26 23:55:29368 // Get stability attributes out of Local State, zeroing out stored values.
369 // NOTE: This could lead to some data loss if this report isn't successfully
370 // sent, but that's true for all the metrics.
371
[email protected]ffaf78a2008-11-12 17:38:33372 OPEN_ELEMENT_FOR_SCOPE("stability");
[email protected]147bbc0b2009-01-06 19:37:40373 WriteRequiredStabilityAttributes(pref);
374 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29375
[email protected]fe58acc22012-02-29 01:29:58376 int incomplete_shutdown_count =
377 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
[email protected]e324f6b2012-02-28 05:43:37378 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58379 int breakpad_registration_success_count =
380 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
[email protected]e324f6b2012-02-28 05:43:37381 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58382 int breakpad_registration_failure_count =
383 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
[email protected]e324f6b2012-02-28 05:43:37384 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58385 int debugger_present_count =
386 pref->GetInteger(prefs::kStabilityDebuggerPresent);
[email protected]e324f6b2012-02-28 05:43:37387 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58388 int debugger_not_present_count =
389 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
[email protected]e324f6b2012-02-28 05:43:37390 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31391
[email protected]fe58acc22012-02-29 01:29:58392 // TODO(jar): The following are all optional, so we *could* optimize them for
393 // values of zero (and not include them).
394
395 // Write the XML version.
396 WriteIntAttribute("incompleteshutdowncount", incomplete_shutdown_count);
397 WriteIntAttribute("breakpadregistrationok",
398 breakpad_registration_success_count);
399 WriteIntAttribute("breakpadregistrationfail",
400 breakpad_registration_failure_count);
401 WriteIntAttribute("debuggerpresent", debugger_present_count);
402 WriteIntAttribute("debuggernotpresent", debugger_not_present_count);
403
404 // Write the protobuf version.
405 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34406 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58407 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
408 stability->set_breakpad_registration_success_count(
409 breakpad_registration_success_count);
410 stability->set_breakpad_registration_failure_count(
411 breakpad_registration_failure_count);
412 stability->set_debugger_present_count(debugger_present_count);
413 stability->set_debugger_not_present_count(debugger_not_present_count);
414
415 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40416}
417
[email protected]fe58acc22012-02-29 01:29:58418void MetricsLog::WritePluginStabilityElements(
419 const std::vector<webkit::WebPluginInfo>& plugin_list,
420 PrefService* pref) {
[email protected]147bbc0b2009-01-06 19:37:40421 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29422 const ListValue* plugin_stats_list = pref->GetList(
423 prefs::kStabilityPluginStats);
[email protected]1df44b72012-01-19 05:20:34424 if (!plugin_stats_list)
425 return;
initial.commit09911bf2008-07-26 23:55:29426
[email protected]1df44b72012-01-19 05:20:34427 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]fe58acc22012-02-29 01:29:58428 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34429 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58430 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]1df44b72012-01-19 05:20:34431 for (ListValue::const_iterator iter = plugin_stats_list->begin();
432 iter != plugin_stats_list->end(); ++iter) {
433 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
434 NOTREACHED();
435 continue;
initial.commit09911bf2008-07-26 23:55:29436 }
[email protected]1df44b72012-01-19 05:20:34437 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29438
[email protected]1df44b72012-01-19 05:20:34439 std::string plugin_name;
440 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
441
[email protected]fe58acc22012-02-29 01:29:58442 std::string base64_name_hash;
443 uint64 numeric_name_hash_ignored;
444 CreateHashes(plugin_name, &base64_name_hash, &numeric_name_hash_ignored);
445
446 // Write the XML verison.
[email protected]1df44b72012-01-19 05:20:34447 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
448 // Use "filename" instead of "name", otherwise we need to update the
449 // UMA servers.
[email protected]fe58acc22012-02-29 01:29:58450 WriteAttribute("filename", base64_name_hash);
[email protected]1df44b72012-01-19 05:20:34451
452 int launches = 0;
453 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
454 WriteIntAttribute("launchcount", launches);
455
456 int instances = 0;
457 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
458 WriteIntAttribute("instancecount", instances);
459
460 int crashes = 0;
461 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
462 WriteIntAttribute("crashcount", crashes);
[email protected]fe58acc22012-02-29 01:29:58463
464 // Write the protobuf version.
465 // Note that this search is potentially a quadratic operation, but given the
466 // low number of plugins installed on a "reasonable" setup, this should be
467 // fine.
468 // TODO(isherman): Verify that this does not show up as a hotspot in
469 // profiler runs.
470 const webkit::WebPluginInfo* plugin_info = NULL;
471 const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name);
472 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
473 plugin_list.begin();
474 iter != plugin_list.end(); ++iter) {
475 if (iter->name == plugin_name_utf16) {
476 plugin_info = &(*iter);
477 break;
478 }
479 }
480
481 if (!plugin_info) {
482 NOTREACHED();
483 continue;
484 }
[email protected]cd937072012-07-02 09:00:29485 int loading_errors = 0;
486 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors,
487 &loading_errors);
488 WriteIntAttribute("loadingerrorcount", loading_errors);
[email protected]fe58acc22012-02-29 01:29:58489
[email protected]cd937072012-07-02 09:00:29490 // Write the protobuf version.
[email protected]fe58acc22012-02-29 01:29:58491 SystemProfileProto::Stability::PluginStability* plugin_stability =
492 stability->add_plugin_stability();
493 SetPluginInfo(*plugin_info, plugin_prefs,
494 plugin_stability->mutable_plugin());
495 plugin_stability->set_launch_count(launches);
496 plugin_stability->set_instance_count(instances);
497 plugin_stability->set_crash_count(crashes);
[email protected]cd937072012-07-02 09:00:29498 plugin_stability->set_loading_error_count(loading_errors);
initial.commit09911bf2008-07-26 23:55:29499 }
[email protected]1df44b72012-01-19 05:20:34500
501 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29502}
503
[email protected]fe58acc22012-02-29 01:29:58504// The server refuses data that doesn't have certain values. crashcount and
505// launchcount are currently "required" in the "stability" group.
506// TODO(isherman): Stop writing these attributes specially once the migration to
507// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40508void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]fe58acc22012-02-29 01:29:58509 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
[email protected]0b33f80b2008-12-17 21:34:36510 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
[email protected]fe58acc22012-02-29 01:29:58511 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
[email protected]0b33f80b2008-12-17 21:34:36512 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58513
514 // Write the XML version.
515 WriteIntAttribute("launchcount", launch_count);
516 WriteIntAttribute("crashcount", crash_count);
517
518 // Write the protobuf version.
519 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34520 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58521 stability->set_launch_count(launch_count);
522 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36523}
524
[email protected]147bbc0b2009-01-06 19:37:40525void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36526 // Update the stats which are critical for real-time stability monitoring.
527 // Since these are "optional," only list ones that are non-zero, as the counts
528 // are aggergated (summed) server side.
529
[email protected]fe58acc22012-02-29 01:29:58530 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34531 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36532 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
533 if (count) {
534 WriteIntAttribute("pageloadcount", count);
[email protected]fe58acc22012-02-29 01:29:58535 stability->set_page_load_count(count);
[email protected]0b33f80b2008-12-17 21:34:36536 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
537 }
538
539 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
540 if (count) {
541 WriteIntAttribute("renderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58542 stability->set_renderer_crash_count(count);
[email protected]0b33f80b2008-12-17 21:34:36543 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
544 }
545
[email protected]1f085622009-12-04 05:33:45546 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
547 if (count) {
548 WriteIntAttribute("extensionrenderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58549 stability->set_extension_renderer_crash_count(count);
[email protected]1f085622009-12-04 05:33:45550 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
551 }
552
[email protected]0b33f80b2008-12-17 21:34:36553 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
554 if (count) {
555 WriteIntAttribute("rendererhangcount", count);
[email protected]fe58acc22012-02-29 01:29:58556 stability->set_renderer_hang_count(count);
[email protected]0b33f80b2008-12-17 21:34:36557 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
558 }
[email protected]1f085622009-12-04 05:33:45559
560 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
561 if (count) {
562 WriteIntAttribute("childprocesscrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58563 stability->set_child_process_crash_count(count);
[email protected]1f085622009-12-04 05:33:45564 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
565 }
[email protected]9165f742010-03-10 22:55:01566
[email protected]c1834a92011-01-21 18:21:03567#if defined(OS_CHROMEOS)
568 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
569 if (count) {
[email protected]fe58acc22012-02-29 01:29:58570 stability->set_other_user_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03571 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
572 }
573
574 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
575 if (count) {
[email protected]fe58acc22012-02-29 01:29:58576 stability->set_kernel_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03577 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
578 }
579
580 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
581 if (count) {
[email protected]fe58acc22012-02-29 01:29:58582 stability->set_unclean_system_shutdown_count(count);
[email protected]c1834a92011-01-21 18:21:03583 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
584 }
585#endif // OS_CHROMEOS
586
[email protected]9165f742010-03-10 22:55:01587 int64 recent_duration = GetIncrementalUptime(pref);
[email protected]fe58acc22012-02-29 01:29:58588 if (recent_duration) {
[email protected]9165f742010-03-10 22:55:01589 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]fe58acc22012-02-29 01:29:58590 stability->set_uptime_sec(recent_duration);
591 }
[email protected]0b33f80b2008-12-17 21:34:36592}
593
initial.commit09911bf2008-07-26 23:55:29594void MetricsLog::WritePluginList(
[email protected]bc66d532012-03-23 01:57:05595 const std::vector<webkit::WebPluginInfo>& plugin_list,
596 bool write_as_xml) {
[email protected]767c9d92012-03-02 16:04:34597 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29598
[email protected]1df44b72012-01-19 05:20:34599 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]10084982011-08-19 17:56:56600
[email protected]ffaf78a2008-11-12 17:38:33601 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]767c9d92012-03-02 16:04:34602 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]91d9f3d2011-08-14 05:24:44603 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50604 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29605 iter != plugin_list.end(); ++iter) {
[email protected]bc66d532012-03-23 01:57:05606 if (write_as_xml) {
607 std::string base64_name_hash;
608 uint64 numeric_hash_ignored;
609 CreateHashes(UTF16ToUTF8(iter->name), &base64_name_hash,
610 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58611
[email protected]bc66d532012-03-23 01:57:05612 std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe();
613 std::string base64_filename_hash;
614 CreateHashes(filename_bytes, &base64_filename_hash,
615 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58616
[email protected]bc66d532012-03-23 01:57:05617 // Write the XML version.
618 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29619
[email protected]bc66d532012-03-23 01:57:05620 // Plugin name and filename are hashed for the privacy of those
621 // testing unreleased new extensions.
622 WriteAttribute("name", base64_name_hash);
623 WriteAttribute("filename", base64_filename_hash);
624 WriteAttribute("version", UTF16ToUTF8(iter->version));
625 if (plugin_prefs)
626 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
627 } else {
628 // Write the protobuf version.
629 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
630 SetPluginInfo(*iter, plugin_prefs, plugin);
631 }
initial.commit09911bf2008-07-26 23:55:29632 }
initial.commit09911bf2008-07-26 23:55:29633}
634
[email protected]147bbc0b2009-01-06 19:37:40635void MetricsLog::WriteInstallElement() {
[email protected]fe58acc22012-02-29 01:29:58636 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05637 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]147bbc0b2009-01-06 19:37:40638 OPEN_ELEMENT_FOR_SCOPE("install");
[email protected]bc66d532012-03-23 01:57:05639 WriteAttribute("installdate", GetInstallDate(GetPrefService()));
[email protected]147bbc0b2009-01-06 19:37:40640 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40641}
642
initial.commit09911bf2008-07-26 23:55:29643void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44644 const std::vector<webkit::WebPluginInfo>& plugin_list,
[email protected]197c0772012-05-14 23:50:51645 const GoogleUpdateMetrics& google_update_metrics,
initial.commit09911bf2008-07-26 23:55:29646 const DictionaryValue* profile_metrics) {
[email protected]767c9d92012-03-02 16:04:34647 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29648
[email protected]767c9d92012-03-02 16:04:34649 PrefService* pref = GetPrefService();
initial.commit09911bf2008-07-26 23:55:29650
[email protected]ffaf78a2008-11-12 17:38:33651 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29652 WriteCommonEventAttributes();
653
[email protected]147bbc0b2009-01-06 19:37:40654 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29655
[email protected]bc66d532012-03-23 01:57:05656 // Write the XML version.
657 // We'll write the protobuf version in RecordEnvironmentProto().
658 bool write_as_xml = true;
659 WritePluginList(plugin_list, write_as_xml);
initial.commit09911bf2008-07-26 23:55:29660
[email protected]fe58acc22012-02-29 01:29:58661 WriteStabilityElement(plugin_list, pref);
initial.commit09911bf2008-07-26 23:55:29662
663 {
[email protected]fe58acc22012-02-29 01:29:58664 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05665 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29666 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]bc66d532012-03-23 01:57:05667 WriteAttribute("arch", base::SysInfo::CPUArchitecture());
initial.commit09911bf2008-07-26 23:55:29668 }
669
670 {
[email protected]fe58acc22012-02-29 01:29:58671 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05672 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29673 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]bc66d532012-03-23 01:57:05674 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38675#if defined(OS_WIN)
676 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
677#endif
initial.commit09911bf2008-07-26 23:55:29678 }
679
680 {
[email protected]fe58acc22012-02-29 01:29:58681 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05682 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29683 OPEN_ELEMENT_FOR_SCOPE("os");
[email protected]bc66d532012-03-23 01:57:05684 WriteAttribute("name", base::SysInfo::OperatingSystemName());
685 WriteAttribute("version", base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29686 }
687
688 {
[email protected]e8c287c872010-07-20 00:49:42689 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]fe58acc22012-02-29 01:29:58690 const content::GPUInfo& gpu_info =
691 GpuDataManager::GetInstance()->GetGPUInfo();
[email protected]fe58acc22012-02-29 01:29:58692
693 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05694 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]a094e2c2012-05-10 23:02:42695 WriteIntAttribute("vendorid", gpu_info.gpu.vendor_id);
696 WriteIntAttribute("deviceid", gpu_info.gpu.device_id);
[email protected]e8c287c872010-07-20 00:49:42697 }
698
699 {
[email protected]767c9d92012-03-02 16:04:34700 const gfx::Size display_size = GetScreenSize();
[email protected]fe58acc22012-02-29 01:29:58701
702 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05703 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]fe58acc22012-02-29 01:29:58704 OPEN_ELEMENT_FOR_SCOPE("display");
[email protected]bc66d532012-03-23 01:57:05705 WriteIntAttribute("xsize", display_size.width());
706 WriteIntAttribute("ysize", display_size.height());
707 WriteIntAttribute("screens", GetScreenCount());
initial.commit09911bf2008-07-26 23:55:29708 }
709
710 {
711 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
712 int num_bookmarks_on_bookmark_bar =
713 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
714 int num_folders_on_bookmark_bar =
715 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
716 int num_bookmarks_in_other_bookmarks_folder =
717 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
718 int num_folders_in_other_bookmarks_folder =
719 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
720 {
721 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
722 WriteAttribute("name", "full-tree");
723 WriteIntAttribute("foldercount",
724 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
725 WriteIntAttribute("itemcount",
726 num_bookmarks_on_bookmark_bar +
727 num_bookmarks_in_other_bookmarks_folder);
728 }
729 {
730 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
731 WriteAttribute("name", "toolbar");
732 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
733 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
734 }
735 }
736
737 {
738 OPEN_ELEMENT_FOR_SCOPE("keywords");
739 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
740 }
741
742 if (profile_metrics)
743 WriteAllProfilesMetrics(*profile_metrics);
[email protected]767c9d92012-03-02 16:04:34744
[email protected]197c0772012-05-14 23:50:51745 RecordEnvironmentProto(plugin_list, google_update_metrics);
[email protected]bc66d532012-03-23 01:57:05746}
747
748void MetricsLog::RecordEnvironmentProto(
[email protected]197c0772012-05-14 23:50:51749 const std::vector<webkit::WebPluginInfo>& plugin_list,
750 const GoogleUpdateMetrics& google_update_metrics) {
[email protected]bc66d532012-03-23 01:57:05751 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
752 int install_date;
753 bool success = base::StringToInt(GetInstallDate(GetPrefService()),
754 &install_date);
755 DCHECK(success);
756 system_profile->set_install_date(install_date);
757
758 system_profile->set_application_locale(
759 content::GetContentClient()->browser()->GetApplicationLocale());
760
761 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
762 hardware->set_cpu_architecture(base::SysInfo::CPUArchitecture());
763 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
764#if defined(OS_WIN)
765 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
766#endif
767
768 SystemProfileProto::OS* os = system_profile->mutable_os();
[email protected]1bb25e02012-08-03 22:39:39769 std::string os_name = base::SysInfo::OperatingSystemName();
770#if defined(OS_WIN)
771 // TODO(mad): This only checks whether the main process is a Metro process at
772 // upload time; not whether the collected metrics were all gathered from
773 // Metro. This is ok as an approximation for now, since users will rarely be
774 // switching from Metro to Desktop mode; but we should re-evaluate whether we
775 // can distinguish metrics more cleanly in the future: http://crbug.com/140568
776 if (base::win::IsMetroProcess())
777 os_name += " (Metro)";
778#endif
779 os->set_name(os_name);
[email protected]bc66d532012-03-23 01:57:05780 os->set_version(base::SysInfo::OperatingSystemVersion());
781
782 const content::GPUInfo& gpu_info =
783 GpuDataManager::GetInstance()->GetGPUInfo();
784 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
[email protected]a094e2c2012-05-10 23:02:42785 gpu->set_vendor_id(gpu_info.gpu.vendor_id);
786 gpu->set_device_id(gpu_info.gpu.device_id);
[email protected]bc66d532012-03-23 01:57:05787 gpu->set_driver_version(gpu_info.driver_version);
788 gpu->set_driver_date(gpu_info.driver_date);
789 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
790 gpu_performance = gpu->mutable_performance_statistics();
791 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
792 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
793 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
794
795 const gfx::Size display_size = GetScreenSize();
796 hardware->set_primary_screen_width(display_size.width());
797 hardware->set_primary_screen_height(display_size.height());
[email protected]aa96417972012-08-22 03:16:44798 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor());
[email protected]bc66d532012-03-23 01:57:05799 hardware->set_screen_count(GetScreenCount());
800
[email protected]197c0772012-05-14 23:50:51801 WriteGoogleUpdateProto(google_update_metrics);
802
[email protected]bc66d532012-03-23 01:57:05803 bool write_as_xml = false;
804 WritePluginList(plugin_list, write_as_xml);
805
[email protected]ad2461c2012-04-27 21:11:03806 std::vector<SelectedGroupId> field_trial_ids;
[email protected]767c9d92012-03-02 16:04:34807 GetFieldTrialIds(&field_trial_ids);
808 WriteFieldTrials(field_trial_ids, system_profile);
initial.commit09911bf2008-07-26 23:55:29809}
810
[email protected]ed0fd002012-04-25 23:10:34811void MetricsLog::RecordProfilerData(
812 const tracked_objects::ProcessDataSnapshot& process_data,
813 content::ProcessType process_type) {
814 DCHECK(!locked());
815
[email protected]8f829682012-04-27 00:36:49816 if (tracked_objects::GetTimeSourceType() !=
817 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) {
[email protected]ed0fd002012-04-25 23:10:34818 // We currently only support the default time source, wall clock time.
819 return;
820 }
821
822 ProfilerEventProto* profile;
823 if (!uma_proto()->profiler_event_size()) {
824 // For the first process's data, add a new field to the protocol buffer.
825 profile = uma_proto()->add_profiler_event();
826 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
827 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
828 } else {
829 // For the remaining calls, re-use the existing field.
830 profile = uma_proto()->mutable_profiler_event(0);
831 }
832
833 WriteProfilerData(process_data, process_type, profile);
834}
835
initial.commit09911bf2008-07-26 23:55:29836void MetricsLog::WriteAllProfilesMetrics(
837 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51838 const std::string profile_prefix(prefs::kProfilePrefix);
initial.commit09911bf2008-07-26 23:55:29839 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
840 i != all_profiles_metrics.end_keys(); ++i) {
[email protected]e7b418b2010-07-30 19:47:47841 const std::string& key_name = *i;
initial.commit09911bf2008-07-26 23:55:29842 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
[email protected]a61890e2012-07-27 22:27:11843 const DictionaryValue* profile;
[email protected]4dad9ad82009-11-25 20:47:52844 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
845 &profile))
initial.commit09911bf2008-07-26 23:55:29846 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
847 }
848 }
849}
850
[email protected]e7b418b2010-07-30 19:47:47851void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29852 const DictionaryValue& profile_metrics) {
853 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47854 WriteAttribute("profileidhash", profileidhash);
initial.commit09911bf2008-07-26 23:55:29855 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
856 i != profile_metrics.end_keys(); ++i) {
[email protected]a61890e2012-07-27 22:27:11857 const Value* value;
[email protected]4dad9ad82009-11-25 20:47:52858 if (profile_metrics.GetWithoutPathExpansion(*i, &value)) {
[email protected]e7b418b2010-07-30 19:47:47859 DCHECK(*i != "id");
initial.commit09911bf2008-07-26 23:55:29860 switch (value->GetType()) {
861 case Value::TYPE_STRING: {
[email protected]5e324b72008-12-18 00:07:59862 std::string string_value;
initial.commit09911bf2008-07-26 23:55:29863 if (value->GetAsString(&string_value)) {
864 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47865 WriteAttribute("name", *i);
[email protected]5e324b72008-12-18 00:07:59866 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29867 }
868 break;
869 }
870
871 case Value::TYPE_BOOLEAN: {
872 bool bool_value;
873 if (value->GetAsBoolean(&bool_value)) {
874 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47875 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29876 WriteIntAttribute("value", bool_value ? 1 : 0);
877 }
878 break;
879 }
880
881 case Value::TYPE_INTEGER: {
882 int int_value;
883 if (value->GetAsInteger(&int_value)) {
884 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47885 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29886 WriteIntAttribute("value", int_value);
887 }
888 break;
889 }
890
891 default:
892 NOTREACHED();
893 break;
894 }
895 }
896 }
897}
898
899void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
[email protected]767c9d92012-03-02 16:04:34900 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29901
[email protected]fe58acc22012-02-29 01:29:58902 // Write the XML version.
[email protected]ffaf78a2008-11-12 17:38:33903 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29904 WriteAttribute("action", "autocomplete");
905 WriteAttribute("targetidhash", "");
906 // TODO(kochi): Properly track windows.
907 WriteIntAttribute("window", 0);
[email protected]6ebc3162011-12-19 13:44:00908 if (log.tab_id != -1) {
909 // If we know what tab the autocomplete URL was opened in, log it.
910 WriteIntAttribute("tab", static_cast<int>(log.tab_id));
911 }
initial.commit09911bf2008-07-26 23:55:29912 WriteCommonEventAttributes();
913
[email protected]65956312012-04-19 21:28:12914 std::vector<string16> terms;
915 const int num_terms =
916 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms));
[email protected]ffaf78a2008-11-12 17:38:33917 {
918 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29919
[email protected]ffaf78a2008-11-12 17:38:33920 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
[email protected]65956312012-04-19 21:28:12921 WriteIntAttribute("numterms", num_terms);
[email protected]ffaf78a2008-11-12 17:38:33922 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
923 WriteIntAttribute("completedlength",
924 static_cast<int>(log.inline_autocompleted_length));
[email protected]9e349762012-01-31 03:24:36925 if (log.elapsed_time_since_user_first_modified_omnibox !=
926 base::TimeDelta::FromMilliseconds(-1)) {
927 // Only upload the typing duration if it is set/valid.
928 WriteInt64Attribute("typingduration",
929 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
930 }
[email protected]381e2992008-12-16 01:41:00931 const std::string input_type(
932 AutocompleteInput::TypeToString(log.input_type));
933 if (!input_type.empty())
934 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:29935
[email protected]ffaf78a2008-11-12 17:38:33936 for (AutocompleteResult::const_iterator i(log.result.begin());
937 i != log.result.end(); ++i) {
938 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
939 if (i->provider)
[email protected]35f1f4f02012-09-11 13:17:00940 WriteAttribute("provider", i->provider->GetName());
[email protected]381e2992008-12-16 01:41:00941 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
942 if (!result_type.empty())
943 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:33944 WriteIntAttribute("relevance", i->relevance);
945 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
946 }
initial.commit09911bf2008-07-26 23:55:29947 }
initial.commit09911bf2008-07-26 23:55:29948
[email protected]fe58acc22012-02-29 01:29:58949 // Write the protobuf version.
[email protected]767c9d92012-03-02 16:04:34950 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
[email protected]fe58acc22012-02-29 01:29:58951 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
952 if (log.tab_id != -1) {
953 // If we know what tab the autocomplete URL was opened in, log it.
954 omnibox_event->set_tab_id(log.tab_id);
955 }
956 omnibox_event->set_typed_length(log.text.length());
[email protected]660fe8f32012-05-03 20:01:08957 omnibox_event->set_just_deleted_text(log.just_deleted_text);
[email protected]65956312012-04-19 21:28:12958 omnibox_event->set_num_typed_terms(num_terms);
[email protected]fe58acc22012-02-29 01:29:58959 omnibox_event->set_selected_index(log.selected_index);
960 omnibox_event->set_completed_length(log.inline_autocompleted_length);
[email protected]65956312012-04-19 21:28:12961 if (log.elapsed_time_since_user_first_modified_omnibox !=
962 base::TimeDelta::FromMilliseconds(-1)) {
963 // Only upload the typing duration if it is set/valid.
964 omnibox_event->set_typing_duration_ms(
965 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
966 }
[email protected]ee902532012-05-01 23:54:49967 omnibox_event->set_current_page_classification(
968 log.current_page_classification);
[email protected]fe58acc22012-02-29 01:29:58969 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
970 for (AutocompleteResult::const_iterator i(log.result.begin());
971 i != log.result.end(); ++i) {
972 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
[email protected]0e9e8782012-05-15 23:01:51973 suggestion->set_provider(i->provider->AsOmniboxEventProviderType());
[email protected]fe58acc22012-02-29 01:29:58974 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
975 suggestion->set_relevance(i->relevance);
[email protected]cf6256f2012-06-12 23:36:01976 if (i->typed_count != -1)
977 suggestion->set_typed_count(i->typed_count);
[email protected]fe58acc22012-02-29 01:29:58978 suggestion->set_is_starred(i->starred);
979 }
[email protected]0e9e8782012-05-15 23:01:51980 for (ProvidersInfo::const_iterator i(log.providers_info.begin());
981 i != log.providers_info.end(); ++i) {
982 OmniboxEventProto::ProviderInfo* provider_info =
983 omnibox_event->add_provider_info();
984 provider_info->CopyFrom(*i);
985 }
[email protected]fe58acc22012-02-29 01:29:58986
initial.commit09911bf2008-07-26 23:55:29987 ++num_events_;
988}
[email protected]197c0772012-05-14 23:50:51989
990void MetricsLog::WriteGoogleUpdateProto(
991 const GoogleUpdateMetrics& google_update_metrics) {
992#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
993 SystemProfileProto::GoogleUpdate* google_update =
994 uma_proto()->mutable_system_profile()->mutable_google_update();
995
996 google_update->set_is_system_install(google_update_metrics.is_system_install);
997
998 if (!google_update_metrics.last_started_au.is_null()) {
999 google_update->set_last_automatic_start_timestamp(
1000 google_update_metrics.last_started_au.ToTimeT());
1001 }
1002
1003 if (!google_update_metrics.last_checked.is_null()) {
1004 google_update->set_last_update_check_timestamp(
1005 google_update_metrics.last_checked.ToTimeT());
1006 }
1007
1008 if (!google_update_metrics.google_update_data.version.empty()) {
1009 ProductDataToProto(google_update_metrics.google_update_data,
1010 google_update->mutable_google_update_status());
1011 }
1012
1013 if (!google_update_metrics.product_data.version.empty()) {
1014 ProductDataToProto(google_update_metrics.product_data,
1015 google_update->mutable_client_status());
1016 }
1017#endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
1018}