blob: f88383b43b836d5962b98fc957def8772e175333 [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]10084982011-08-19 17:56:5629#include "chrome/browser/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]197c0772012-05-14 23:50:51245void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data,
246 ProductInfo* product_info) {
247 product_info->set_version(product_data.version);
248 product_info->set_last_update_success_timestamp(
249 product_data.last_success.ToTimeT());
250 product_info->set_last_error(product_data.last_error_code);
251 product_info->set_last_extra_error(product_data.last_extra_code);
252 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) {
253 product_info->set_last_result(
254 static_cast<ProductInfo::InstallResult>(product_data.last_result));
255 }
256}
257
[email protected]1df44b72012-01-19 05:20:34258} // namespace
259
[email protected]197c0772012-05-14 23:50:51260GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {}
261
262GoogleUpdateMetrics::~GoogleUpdateMetrics() {}
263
[email protected]67f92bc32012-01-26 01:56:19264static base::LazyInstance<std::string>::Leaky
[email protected]054c8012011-11-16 00:12:42265 g_version_extension = LAZY_INSTANCE_INITIALIZER;
266
[email protected]1226abb2010-06-10 18:01:28267MetricsLog::MetricsLog(const std::string& client_id, int session_id)
268 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:41269
[email protected]1226abb2010-06-10 18:01:28270MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:29271
272// static
273void MetricsLog::RegisterPrefs(PrefService* local_state) {
274 local_state->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29275}
276
[email protected]1df44b72012-01-19 05:20:34277// static
[email protected]9165f742010-03-10 22:55:01278int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
279 base::TimeTicks now = base::TimeTicks::Now();
280 static base::TimeTicks last_updated_time(now);
281 int64 incremental_time = (now - last_updated_time).InSeconds();
282 last_updated_time = now;
283
284 if (incremental_time > 0) {
285 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
286 metrics_uptime += incremental_time;
287 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
288 }
289
290 return incremental_time;
291}
292
[email protected]1226abb2010-06-10 18:01:28293// static
294std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:42295 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:17296 if (!version_info.is_valid()) {
297 NOTREACHED() << "Unable to retrieve version info.";
298 return std::string();
299 }
300
[email protected]0211f57e2010-08-27 20:28:42301 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:42302 if (!version_extension().empty())
303 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:42304 if (!version_info.IsOfficialBuild())
305 version.append("-devel");
306 return version;
[email protected]1226abb2010-06-10 18:01:28307}
308
[email protected]054c8012011-11-16 00:12:42309// static
310void MetricsLog::set_version_extension(const std::string& extension) {
311 g_version_extension.Get() = extension;
312}
313
314// static
315const std::string& MetricsLog::version_extension() {
316 return g_version_extension.Get();
317}
318
[email protected]fe58acc22012-02-29 01:29:58319void MetricsLog::RecordIncrementalStabilityElements(
320 const std::vector<webkit::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34321 DCHECK(!locked());
[email protected]0b33f80b2008-12-17 21:34:36322
[email protected]767c9d92012-03-02 16:04:34323 PrefService* pref = GetPrefService();
[email protected]0b33f80b2008-12-17 21:34:36324 DCHECK(pref);
325
[email protected]147bbc0b2009-01-06 19:37:40326 OPEN_ELEMENT_FOR_SCOPE("profile");
327 WriteCommonEventAttributes();
328
[email protected]9958a322011-03-08 20:04:17329 WriteInstallElement();
[email protected]147bbc0b2009-01-06 19:37:40330
331 {
332 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
333 WriteRequiredStabilityAttributes(pref);
334 WriteRealtimeStabilityAttributes(pref);
335
[email protected]fe58acc22012-02-29 01:29:58336 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40337 }
[email protected]0b33f80b2008-12-17 21:34:36338}
339
[email protected]767c9d92012-03-02 16:04:34340PrefService* MetricsLog::GetPrefService() {
341 return g_browser_process->local_state();
342}
343
344gfx::Size MetricsLog::GetScreenSize() const {
[email protected]42c0a0c62012-06-17 03:50:33345 return gfx::Screen::GetPrimaryDisplay().GetSizeInPixel();
[email protected]767c9d92012-03-02 16:04:34346}
347
[email protected]aa96417972012-08-22 03:16:44348float MetricsLog::GetScreenDeviceScaleFactor() const {
349 return gfx::Screen::GetPrimaryDisplay().device_scale_factor();
350}
351
[email protected]767c9d92012-03-02 16:04:34352int MetricsLog::GetScreenCount() const {
[email protected]42c0a0c62012-06-17 03:50:33353 return gfx::Screen::GetNumDisplays();
[email protected]767c9d92012-03-02 16:04:34354}
355
[email protected]767c9d92012-03-02 16:04:34356void MetricsLog::GetFieldTrialIds(
[email protected]ad2461c2012-04-27 21:11:03357 std::vector<SelectedGroupId>* field_trial_ids) const {
[email protected]2ac73f62012-08-13 21:49:07358 chrome_variations::GetFieldTrialSelectedGroupIds(field_trial_ids);
[email protected]767c9d92012-03-02 16:04:34359}
360
[email protected]fe58acc22012-02-29 01:29:58361void MetricsLog::WriteStabilityElement(
362 const std::vector<webkit::WebPluginInfo>& plugin_list,
363 PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:34364 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29365
initial.commit09911bf2008-07-26 23:55:29366 // Get stability attributes out of Local State, zeroing out stored values.
367 // NOTE: This could lead to some data loss if this report isn't successfully
368 // sent, but that's true for all the metrics.
369
[email protected]ffaf78a2008-11-12 17:38:33370 OPEN_ELEMENT_FOR_SCOPE("stability");
[email protected]147bbc0b2009-01-06 19:37:40371 WriteRequiredStabilityAttributes(pref);
372 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29373
[email protected]fe58acc22012-02-29 01:29:58374 int incomplete_shutdown_count =
375 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
[email protected]e324f6b2012-02-28 05:43:37376 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58377 int breakpad_registration_success_count =
378 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
[email protected]e324f6b2012-02-28 05:43:37379 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58380 int breakpad_registration_failure_count =
381 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
[email protected]e324f6b2012-02-28 05:43:37382 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58383 int debugger_present_count =
384 pref->GetInteger(prefs::kStabilityDebuggerPresent);
[email protected]e324f6b2012-02-28 05:43:37385 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58386 int debugger_not_present_count =
387 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
[email protected]e324f6b2012-02-28 05:43:37388 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31389
[email protected]fe58acc22012-02-29 01:29:58390 // TODO(jar): The following are all optional, so we *could* optimize them for
391 // values of zero (and not include them).
392
393 // Write the XML version.
394 WriteIntAttribute("incompleteshutdowncount", incomplete_shutdown_count);
395 WriteIntAttribute("breakpadregistrationok",
396 breakpad_registration_success_count);
397 WriteIntAttribute("breakpadregistrationfail",
398 breakpad_registration_failure_count);
399 WriteIntAttribute("debuggerpresent", debugger_present_count);
400 WriteIntAttribute("debuggernotpresent", debugger_not_present_count);
401
402 // Write the protobuf version.
403 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34404 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58405 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
406 stability->set_breakpad_registration_success_count(
407 breakpad_registration_success_count);
408 stability->set_breakpad_registration_failure_count(
409 breakpad_registration_failure_count);
410 stability->set_debugger_present_count(debugger_present_count);
411 stability->set_debugger_not_present_count(debugger_not_present_count);
412
413 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40414}
415
[email protected]fe58acc22012-02-29 01:29:58416void MetricsLog::WritePluginStabilityElements(
417 const std::vector<webkit::WebPluginInfo>& plugin_list,
418 PrefService* pref) {
[email protected]147bbc0b2009-01-06 19:37:40419 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29420 const ListValue* plugin_stats_list = pref->GetList(
421 prefs::kStabilityPluginStats);
[email protected]1df44b72012-01-19 05:20:34422 if (!plugin_stats_list)
423 return;
initial.commit09911bf2008-07-26 23:55:29424
[email protected]1df44b72012-01-19 05:20:34425 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]fe58acc22012-02-29 01:29:58426 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34427 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58428 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]1df44b72012-01-19 05:20:34429 for (ListValue::const_iterator iter = plugin_stats_list->begin();
430 iter != plugin_stats_list->end(); ++iter) {
431 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
432 NOTREACHED();
433 continue;
initial.commit09911bf2008-07-26 23:55:29434 }
[email protected]1df44b72012-01-19 05:20:34435 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29436
[email protected]1df44b72012-01-19 05:20:34437 std::string plugin_name;
438 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
439
[email protected]fe58acc22012-02-29 01:29:58440 std::string base64_name_hash;
441 uint64 numeric_name_hash_ignored;
442 CreateHashes(plugin_name, &base64_name_hash, &numeric_name_hash_ignored);
443
444 // Write the XML verison.
[email protected]1df44b72012-01-19 05:20:34445 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
446 // Use "filename" instead of "name", otherwise we need to update the
447 // UMA servers.
[email protected]fe58acc22012-02-29 01:29:58448 WriteAttribute("filename", base64_name_hash);
[email protected]1df44b72012-01-19 05:20:34449
450 int launches = 0;
451 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
452 WriteIntAttribute("launchcount", launches);
453
454 int instances = 0;
455 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
456 WriteIntAttribute("instancecount", instances);
457
458 int crashes = 0;
459 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
460 WriteIntAttribute("crashcount", crashes);
[email protected]fe58acc22012-02-29 01:29:58461
462 // Write the protobuf version.
463 // Note that this search is potentially a quadratic operation, but given the
464 // low number of plugins installed on a "reasonable" setup, this should be
465 // fine.
466 // TODO(isherman): Verify that this does not show up as a hotspot in
467 // profiler runs.
468 const webkit::WebPluginInfo* plugin_info = NULL;
469 const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name);
470 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
471 plugin_list.begin();
472 iter != plugin_list.end(); ++iter) {
473 if (iter->name == plugin_name_utf16) {
474 plugin_info = &(*iter);
475 break;
476 }
477 }
478
479 if (!plugin_info) {
480 NOTREACHED();
481 continue;
482 }
[email protected]cd937072012-07-02 09:00:29483 int loading_errors = 0;
484 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors,
485 &loading_errors);
486 WriteIntAttribute("loadingerrorcount", loading_errors);
[email protected]fe58acc22012-02-29 01:29:58487
[email protected]cd937072012-07-02 09:00:29488 // Write the protobuf version.
[email protected]fe58acc22012-02-29 01:29:58489 SystemProfileProto::Stability::PluginStability* plugin_stability =
490 stability->add_plugin_stability();
491 SetPluginInfo(*plugin_info, plugin_prefs,
492 plugin_stability->mutable_plugin());
493 plugin_stability->set_launch_count(launches);
494 plugin_stability->set_instance_count(instances);
495 plugin_stability->set_crash_count(crashes);
[email protected]cd937072012-07-02 09:00:29496 plugin_stability->set_loading_error_count(loading_errors);
initial.commit09911bf2008-07-26 23:55:29497 }
[email protected]1df44b72012-01-19 05:20:34498
499 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29500}
501
[email protected]fe58acc22012-02-29 01:29:58502// The server refuses data that doesn't have certain values. crashcount and
503// launchcount are currently "required" in the "stability" group.
504// TODO(isherman): Stop writing these attributes specially once the migration to
505// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40506void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]fe58acc22012-02-29 01:29:58507 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
[email protected]0b33f80b2008-12-17 21:34:36508 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
[email protected]fe58acc22012-02-29 01:29:58509 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
[email protected]0b33f80b2008-12-17 21:34:36510 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58511
512 // Write the XML version.
513 WriteIntAttribute("launchcount", launch_count);
514 WriteIntAttribute("crashcount", crash_count);
515
516 // Write the protobuf version.
517 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34518 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58519 stability->set_launch_count(launch_count);
520 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36521}
522
[email protected]147bbc0b2009-01-06 19:37:40523void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36524 // Update the stats which are critical for real-time stability monitoring.
525 // Since these are "optional," only list ones that are non-zero, as the counts
526 // are aggergated (summed) server side.
527
[email protected]fe58acc22012-02-29 01:29:58528 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34529 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36530 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
531 if (count) {
532 WriteIntAttribute("pageloadcount", count);
[email protected]fe58acc22012-02-29 01:29:58533 stability->set_page_load_count(count);
[email protected]0b33f80b2008-12-17 21:34:36534 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
535 }
536
537 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
538 if (count) {
539 WriteIntAttribute("renderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58540 stability->set_renderer_crash_count(count);
[email protected]0b33f80b2008-12-17 21:34:36541 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
542 }
543
[email protected]1f085622009-12-04 05:33:45544 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
545 if (count) {
546 WriteIntAttribute("extensionrenderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58547 stability->set_extension_renderer_crash_count(count);
[email protected]1f085622009-12-04 05:33:45548 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
549 }
550
[email protected]0b33f80b2008-12-17 21:34:36551 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
552 if (count) {
553 WriteIntAttribute("rendererhangcount", count);
[email protected]fe58acc22012-02-29 01:29:58554 stability->set_renderer_hang_count(count);
[email protected]0b33f80b2008-12-17 21:34:36555 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
556 }
[email protected]1f085622009-12-04 05:33:45557
558 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
559 if (count) {
560 WriteIntAttribute("childprocesscrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58561 stability->set_child_process_crash_count(count);
[email protected]1f085622009-12-04 05:33:45562 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
563 }
[email protected]9165f742010-03-10 22:55:01564
[email protected]c1834a92011-01-21 18:21:03565#if defined(OS_CHROMEOS)
566 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
567 if (count) {
[email protected]fe58acc22012-02-29 01:29:58568 stability->set_other_user_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03569 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
570 }
571
572 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
573 if (count) {
[email protected]fe58acc22012-02-29 01:29:58574 stability->set_kernel_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03575 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
576 }
577
578 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
579 if (count) {
[email protected]fe58acc22012-02-29 01:29:58580 stability->set_unclean_system_shutdown_count(count);
[email protected]c1834a92011-01-21 18:21:03581 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
582 }
583#endif // OS_CHROMEOS
584
[email protected]9165f742010-03-10 22:55:01585 int64 recent_duration = GetIncrementalUptime(pref);
[email protected]fe58acc22012-02-29 01:29:58586 if (recent_duration) {
[email protected]9165f742010-03-10 22:55:01587 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]fe58acc22012-02-29 01:29:58588 stability->set_uptime_sec(recent_duration);
589 }
[email protected]0b33f80b2008-12-17 21:34:36590}
591
initial.commit09911bf2008-07-26 23:55:29592void MetricsLog::WritePluginList(
[email protected]bc66d532012-03-23 01:57:05593 const std::vector<webkit::WebPluginInfo>& plugin_list,
594 bool write_as_xml) {
[email protected]767c9d92012-03-02 16:04:34595 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29596
[email protected]1df44b72012-01-19 05:20:34597 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]10084982011-08-19 17:56:56598
[email protected]ffaf78a2008-11-12 17:38:33599 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]767c9d92012-03-02 16:04:34600 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]91d9f3d2011-08-14 05:24:44601 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50602 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29603 iter != plugin_list.end(); ++iter) {
[email protected]bc66d532012-03-23 01:57:05604 if (write_as_xml) {
605 std::string base64_name_hash;
606 uint64 numeric_hash_ignored;
607 CreateHashes(UTF16ToUTF8(iter->name), &base64_name_hash,
608 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58609
[email protected]bc66d532012-03-23 01:57:05610 std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe();
611 std::string base64_filename_hash;
612 CreateHashes(filename_bytes, &base64_filename_hash,
613 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58614
[email protected]bc66d532012-03-23 01:57:05615 // Write the XML version.
616 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29617
[email protected]bc66d532012-03-23 01:57:05618 // Plugin name and filename are hashed for the privacy of those
619 // testing unreleased new extensions.
620 WriteAttribute("name", base64_name_hash);
621 WriteAttribute("filename", base64_filename_hash);
622 WriteAttribute("version", UTF16ToUTF8(iter->version));
623 if (plugin_prefs)
624 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
625 } else {
626 // Write the protobuf version.
627 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
628 SetPluginInfo(*iter, plugin_prefs, plugin);
629 }
initial.commit09911bf2008-07-26 23:55:29630 }
initial.commit09911bf2008-07-26 23:55:29631}
632
[email protected]147bbc0b2009-01-06 19:37:40633void MetricsLog::WriteInstallElement() {
[email protected]fe58acc22012-02-29 01:29:58634 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05635 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]147bbc0b2009-01-06 19:37:40636 OPEN_ELEMENT_FOR_SCOPE("install");
[email protected]bc66d532012-03-23 01:57:05637 WriteAttribute("installdate", GetInstallDate(GetPrefService()));
[email protected]147bbc0b2009-01-06 19:37:40638 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40639}
640
initial.commit09911bf2008-07-26 23:55:29641void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44642 const std::vector<webkit::WebPluginInfo>& plugin_list,
[email protected]197c0772012-05-14 23:50:51643 const GoogleUpdateMetrics& google_update_metrics,
initial.commit09911bf2008-07-26 23:55:29644 const DictionaryValue* profile_metrics) {
[email protected]767c9d92012-03-02 16:04:34645 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29646
[email protected]767c9d92012-03-02 16:04:34647 PrefService* pref = GetPrefService();
initial.commit09911bf2008-07-26 23:55:29648
[email protected]ffaf78a2008-11-12 17:38:33649 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29650 WriteCommonEventAttributes();
651
[email protected]147bbc0b2009-01-06 19:37:40652 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29653
[email protected]bc66d532012-03-23 01:57:05654 // Write the XML version.
655 // We'll write the protobuf version in RecordEnvironmentProto().
656 bool write_as_xml = true;
657 WritePluginList(plugin_list, write_as_xml);
initial.commit09911bf2008-07-26 23:55:29658
[email protected]fe58acc22012-02-29 01:29:58659 WriteStabilityElement(plugin_list, pref);
initial.commit09911bf2008-07-26 23:55:29660
661 {
[email protected]fe58acc22012-02-29 01:29:58662 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05663 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29664 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]bc66d532012-03-23 01:57:05665 WriteAttribute("arch", base::SysInfo::CPUArchitecture());
initial.commit09911bf2008-07-26 23:55:29666 }
667
668 {
[email protected]fe58acc22012-02-29 01:29:58669 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05670 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29671 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]bc66d532012-03-23 01:57:05672 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38673#if defined(OS_WIN)
674 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
675#endif
initial.commit09911bf2008-07-26 23:55:29676 }
677
678 {
[email protected]fe58acc22012-02-29 01:29:58679 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05680 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29681 OPEN_ELEMENT_FOR_SCOPE("os");
[email protected]bc66d532012-03-23 01:57:05682 WriteAttribute("name", base::SysInfo::OperatingSystemName());
683 WriteAttribute("version", base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29684 }
685
686 {
[email protected]e8c287c872010-07-20 00:49:42687 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]fe58acc22012-02-29 01:29:58688 const content::GPUInfo& gpu_info =
689 GpuDataManager::GetInstance()->GetGPUInfo();
[email protected]fe58acc22012-02-29 01:29:58690
691 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05692 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]a094e2c2012-05-10 23:02:42693 WriteIntAttribute("vendorid", gpu_info.gpu.vendor_id);
694 WriteIntAttribute("deviceid", gpu_info.gpu.device_id);
[email protected]e8c287c872010-07-20 00:49:42695 }
696
697 {
[email protected]767c9d92012-03-02 16:04:34698 const gfx::Size display_size = GetScreenSize();
[email protected]fe58acc22012-02-29 01:29:58699
700 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05701 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]fe58acc22012-02-29 01:29:58702 OPEN_ELEMENT_FOR_SCOPE("display");
[email protected]bc66d532012-03-23 01:57:05703 WriteIntAttribute("xsize", display_size.width());
704 WriteIntAttribute("ysize", display_size.height());
705 WriteIntAttribute("screens", GetScreenCount());
initial.commit09911bf2008-07-26 23:55:29706 }
707
708 {
709 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
710 int num_bookmarks_on_bookmark_bar =
711 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
712 int num_folders_on_bookmark_bar =
713 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
714 int num_bookmarks_in_other_bookmarks_folder =
715 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
716 int num_folders_in_other_bookmarks_folder =
717 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
718 {
719 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
720 WriteAttribute("name", "full-tree");
721 WriteIntAttribute("foldercount",
722 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
723 WriteIntAttribute("itemcount",
724 num_bookmarks_on_bookmark_bar +
725 num_bookmarks_in_other_bookmarks_folder);
726 }
727 {
728 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
729 WriteAttribute("name", "toolbar");
730 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
731 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
732 }
733 }
734
735 {
736 OPEN_ELEMENT_FOR_SCOPE("keywords");
737 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
738 }
739
740 if (profile_metrics)
741 WriteAllProfilesMetrics(*profile_metrics);
[email protected]767c9d92012-03-02 16:04:34742
[email protected]197c0772012-05-14 23:50:51743 RecordEnvironmentProto(plugin_list, google_update_metrics);
[email protected]bc66d532012-03-23 01:57:05744}
745
746void MetricsLog::RecordEnvironmentProto(
[email protected]197c0772012-05-14 23:50:51747 const std::vector<webkit::WebPluginInfo>& plugin_list,
748 const GoogleUpdateMetrics& google_update_metrics) {
[email protected]bc66d532012-03-23 01:57:05749 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
750 int install_date;
751 bool success = base::StringToInt(GetInstallDate(GetPrefService()),
752 &install_date);
753 DCHECK(success);
754 system_profile->set_install_date(install_date);
755
756 system_profile->set_application_locale(
757 content::GetContentClient()->browser()->GetApplicationLocale());
758
759 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
760 hardware->set_cpu_architecture(base::SysInfo::CPUArchitecture());
761 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
762#if defined(OS_WIN)
763 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
764#endif
765
766 SystemProfileProto::OS* os = system_profile->mutable_os();
[email protected]1bb25e02012-08-03 22:39:39767 std::string os_name = base::SysInfo::OperatingSystemName();
768#if defined(OS_WIN)
769 // TODO(mad): This only checks whether the main process is a Metro process at
770 // upload time; not whether the collected metrics were all gathered from
771 // Metro. This is ok as an approximation for now, since users will rarely be
772 // switching from Metro to Desktop mode; but we should re-evaluate whether we
773 // can distinguish metrics more cleanly in the future: http://crbug.com/140568
774 if (base::win::IsMetroProcess())
775 os_name += " (Metro)";
776#endif
777 os->set_name(os_name);
[email protected]bc66d532012-03-23 01:57:05778 os->set_version(base::SysInfo::OperatingSystemVersion());
779
780 const content::GPUInfo& gpu_info =
781 GpuDataManager::GetInstance()->GetGPUInfo();
782 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
[email protected]a094e2c2012-05-10 23:02:42783 gpu->set_vendor_id(gpu_info.gpu.vendor_id);
784 gpu->set_device_id(gpu_info.gpu.device_id);
[email protected]bc66d532012-03-23 01:57:05785 gpu->set_driver_version(gpu_info.driver_version);
786 gpu->set_driver_date(gpu_info.driver_date);
787 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
788 gpu_performance = gpu->mutable_performance_statistics();
789 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
790 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
791 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
792
793 const gfx::Size display_size = GetScreenSize();
794 hardware->set_primary_screen_width(display_size.width());
795 hardware->set_primary_screen_height(display_size.height());
[email protected]aa96417972012-08-22 03:16:44796 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor());
[email protected]bc66d532012-03-23 01:57:05797 hardware->set_screen_count(GetScreenCount());
798
[email protected]197c0772012-05-14 23:50:51799 WriteGoogleUpdateProto(google_update_metrics);
800
[email protected]bc66d532012-03-23 01:57:05801 bool write_as_xml = false;
802 WritePluginList(plugin_list, write_as_xml);
803
[email protected]ad2461c2012-04-27 21:11:03804 std::vector<SelectedGroupId> field_trial_ids;
[email protected]767c9d92012-03-02 16:04:34805 GetFieldTrialIds(&field_trial_ids);
806 WriteFieldTrials(field_trial_ids, system_profile);
initial.commit09911bf2008-07-26 23:55:29807}
808
[email protected]ed0fd002012-04-25 23:10:34809void MetricsLog::RecordProfilerData(
810 const tracked_objects::ProcessDataSnapshot& process_data,
811 content::ProcessType process_type) {
812 DCHECK(!locked());
813
[email protected]8f829682012-04-27 00:36:49814 if (tracked_objects::GetTimeSourceType() !=
815 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) {
[email protected]ed0fd002012-04-25 23:10:34816 // We currently only support the default time source, wall clock time.
817 return;
818 }
819
820 ProfilerEventProto* profile;
821 if (!uma_proto()->profiler_event_size()) {
822 // For the first process's data, add a new field to the protocol buffer.
823 profile = uma_proto()->add_profiler_event();
824 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
825 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
826 } else {
827 // For the remaining calls, re-use the existing field.
828 profile = uma_proto()->mutable_profiler_event(0);
829 }
830
831 WriteProfilerData(process_data, process_type, profile);
832}
833
initial.commit09911bf2008-07-26 23:55:29834void MetricsLog::WriteAllProfilesMetrics(
835 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51836 const std::string profile_prefix(prefs::kProfilePrefix);
initial.commit09911bf2008-07-26 23:55:29837 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
838 i != all_profiles_metrics.end_keys(); ++i) {
[email protected]e7b418b2010-07-30 19:47:47839 const std::string& key_name = *i;
initial.commit09911bf2008-07-26 23:55:29840 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
[email protected]a61890e2012-07-27 22:27:11841 const DictionaryValue* profile;
[email protected]4dad9ad82009-11-25 20:47:52842 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
843 &profile))
initial.commit09911bf2008-07-26 23:55:29844 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
845 }
846 }
847}
848
[email protected]e7b418b2010-07-30 19:47:47849void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29850 const DictionaryValue& profile_metrics) {
851 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47852 WriteAttribute("profileidhash", profileidhash);
initial.commit09911bf2008-07-26 23:55:29853 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
854 i != profile_metrics.end_keys(); ++i) {
[email protected]a61890e2012-07-27 22:27:11855 const Value* value;
[email protected]4dad9ad82009-11-25 20:47:52856 if (profile_metrics.GetWithoutPathExpansion(*i, &value)) {
[email protected]e7b418b2010-07-30 19:47:47857 DCHECK(*i != "id");
initial.commit09911bf2008-07-26 23:55:29858 switch (value->GetType()) {
859 case Value::TYPE_STRING: {
[email protected]5e324b72008-12-18 00:07:59860 std::string string_value;
initial.commit09911bf2008-07-26 23:55:29861 if (value->GetAsString(&string_value)) {
862 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47863 WriteAttribute("name", *i);
[email protected]5e324b72008-12-18 00:07:59864 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29865 }
866 break;
867 }
868
869 case Value::TYPE_BOOLEAN: {
870 bool bool_value;
871 if (value->GetAsBoolean(&bool_value)) {
872 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47873 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29874 WriteIntAttribute("value", bool_value ? 1 : 0);
875 }
876 break;
877 }
878
879 case Value::TYPE_INTEGER: {
880 int int_value;
881 if (value->GetAsInteger(&int_value)) {
882 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47883 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29884 WriteIntAttribute("value", int_value);
885 }
886 break;
887 }
888
889 default:
890 NOTREACHED();
891 break;
892 }
893 }
894 }
895}
896
897void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
[email protected]767c9d92012-03-02 16:04:34898 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29899
[email protected]fe58acc22012-02-29 01:29:58900 // Write the XML version.
[email protected]ffaf78a2008-11-12 17:38:33901 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29902 WriteAttribute("action", "autocomplete");
903 WriteAttribute("targetidhash", "");
904 // TODO(kochi): Properly track windows.
905 WriteIntAttribute("window", 0);
[email protected]6ebc3162011-12-19 13:44:00906 if (log.tab_id != -1) {
907 // If we know what tab the autocomplete URL was opened in, log it.
908 WriteIntAttribute("tab", static_cast<int>(log.tab_id));
909 }
initial.commit09911bf2008-07-26 23:55:29910 WriteCommonEventAttributes();
911
[email protected]65956312012-04-19 21:28:12912 std::vector<string16> terms;
913 const int num_terms =
914 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms));
[email protected]ffaf78a2008-11-12 17:38:33915 {
916 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29917
[email protected]ffaf78a2008-11-12 17:38:33918 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
[email protected]65956312012-04-19 21:28:12919 WriteIntAttribute("numterms", num_terms);
[email protected]ffaf78a2008-11-12 17:38:33920 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
921 WriteIntAttribute("completedlength",
922 static_cast<int>(log.inline_autocompleted_length));
[email protected]9e349762012-01-31 03:24:36923 if (log.elapsed_time_since_user_first_modified_omnibox !=
924 base::TimeDelta::FromMilliseconds(-1)) {
925 // Only upload the typing duration if it is set/valid.
926 WriteInt64Attribute("typingduration",
927 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
928 }
[email protected]381e2992008-12-16 01:41:00929 const std::string input_type(
930 AutocompleteInput::TypeToString(log.input_type));
931 if (!input_type.empty())
932 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:29933
[email protected]ffaf78a2008-11-12 17:38:33934 for (AutocompleteResult::const_iterator i(log.result.begin());
935 i != log.result.end(); ++i) {
936 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
937 if (i->provider)
[email protected]35f1f4f02012-09-11 13:17:00938 WriteAttribute("provider", i->provider->GetName());
[email protected]381e2992008-12-16 01:41:00939 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
940 if (!result_type.empty())
941 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:33942 WriteIntAttribute("relevance", i->relevance);
943 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
944 }
initial.commit09911bf2008-07-26 23:55:29945 }
initial.commit09911bf2008-07-26 23:55:29946
[email protected]fe58acc22012-02-29 01:29:58947 // Write the protobuf version.
[email protected]767c9d92012-03-02 16:04:34948 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
[email protected]fe58acc22012-02-29 01:29:58949 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
950 if (log.tab_id != -1) {
951 // If we know what tab the autocomplete URL was opened in, log it.
952 omnibox_event->set_tab_id(log.tab_id);
953 }
954 omnibox_event->set_typed_length(log.text.length());
[email protected]660fe8f32012-05-03 20:01:08955 omnibox_event->set_just_deleted_text(log.just_deleted_text);
[email protected]65956312012-04-19 21:28:12956 omnibox_event->set_num_typed_terms(num_terms);
[email protected]fe58acc22012-02-29 01:29:58957 omnibox_event->set_selected_index(log.selected_index);
958 omnibox_event->set_completed_length(log.inline_autocompleted_length);
[email protected]65956312012-04-19 21:28:12959 if (log.elapsed_time_since_user_first_modified_omnibox !=
960 base::TimeDelta::FromMilliseconds(-1)) {
961 // Only upload the typing duration if it is set/valid.
962 omnibox_event->set_typing_duration_ms(
963 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
964 }
[email protected]ee902532012-05-01 23:54:49965 omnibox_event->set_current_page_classification(
966 log.current_page_classification);
[email protected]fe58acc22012-02-29 01:29:58967 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
968 for (AutocompleteResult::const_iterator i(log.result.begin());
969 i != log.result.end(); ++i) {
970 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
[email protected]0e9e8782012-05-15 23:01:51971 suggestion->set_provider(i->provider->AsOmniboxEventProviderType());
[email protected]fe58acc22012-02-29 01:29:58972 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
973 suggestion->set_relevance(i->relevance);
[email protected]cf6256f2012-06-12 23:36:01974 if (i->typed_count != -1)
975 suggestion->set_typed_count(i->typed_count);
[email protected]fe58acc22012-02-29 01:29:58976 suggestion->set_is_starred(i->starred);
977 }
[email protected]0e9e8782012-05-15 23:01:51978 for (ProvidersInfo::const_iterator i(log.providers_info.begin());
979 i != log.providers_info.end(); ++i) {
980 OmniboxEventProto::ProviderInfo* provider_info =
981 omnibox_event->add_provider_info();
982 provider_info->CopyFrom(*i);
983 }
[email protected]fe58acc22012-02-29 01:29:58984
initial.commit09911bf2008-07-26 23:55:29985 ++num_events_;
986}
[email protected]197c0772012-05-14 23:50:51987
988void MetricsLog::WriteGoogleUpdateProto(
989 const GoogleUpdateMetrics& google_update_metrics) {
990#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
991 SystemProfileProto::GoogleUpdate* google_update =
992 uma_proto()->mutable_system_profile()->mutable_google_update();
993
994 google_update->set_is_system_install(google_update_metrics.is_system_install);
995
996 if (!google_update_metrics.last_started_au.is_null()) {
997 google_update->set_last_automatic_start_timestamp(
998 google_update_metrics.last_started_au.ToTimeT());
999 }
1000
1001 if (!google_update_metrics.last_checked.is_null()) {
1002 google_update->set_last_update_check_timestamp(
1003 google_update_metrics.last_checked.ToTimeT());
1004 }
1005
1006 if (!google_update_metrics.google_update_data.version.empty()) {
1007 ProductDataToProto(google_update_metrics.google_update_data,
1008 google_update->mutable_google_update_status());
1009 }
1010
1011 if (!google_update_metrics.product_data.version.empty()) {
1012 ProductDataToProto(google_update_metrics.product_data,
1013 google_update->mutable_client_status());
1014 }
1015#endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
1016}