blob: 31e5c9803ed2e66b792dc8cc0652ac2fcb39201e [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
[email protected]5106b3a2012-10-03 20:10:4448#if defined(OS_ANDROID)
49#include "base/android/build_info.h"
50#endif
51
initial.commit09911bf2008-07-26 23:55:2952#define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
53
[email protected]d1be67b2008-11-19 20:28:3854#if defined(OS_WIN)
[email protected]1bb25e02012-08-03 22:39:3955#include "base/win/metro.h"
56
57// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
[email protected]d1be67b2008-11-19 20:28:3858extern "C" IMAGE_DOS_HEADER __ImageBase;
59#endif
60
[email protected]79078df2012-02-16 01:22:3261using content::GpuDataManager;
[email protected]fe58acc22012-02-29 01:29:5862using metrics::OmniboxEventProto;
[email protected]ed0fd002012-04-25 23:10:3463using metrics::ProfilerEventProto;
[email protected]fe58acc22012-02-29 01:29:5864using metrics::SystemProfileProto;
[email protected]ed0fd002012-04-25 23:10:3465using tracked_objects::ProcessDataSnapshot;
[email protected]2ac73f62012-08-13 21:49:0766typedef chrome_variations::SelectedGroupId SelectedGroupId;
[email protected]197c0772012-05-14 23:50:5167typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo;
[email protected]79078df2012-02-16 01:22:3268
[email protected]1df44b72012-01-19 05:20:3469namespace {
70
71// Returns the date at which the current metrics client ID was created as
72// a string containing milliseconds since the epoch, or "0" if none was found.
[email protected]767c9d92012-03-02 16:04:3473std::string GetInstallDate(PrefService* pref) {
74 if (!pref) {
[email protected]1df44b72012-01-19 05:20:3475 NOTREACHED();
76 return "0";
77 }
[email protected]767c9d92012-03-02 16:04:3478
79 return pref->GetString(prefs::kMetricsClientIDTimestamp);
[email protected]1df44b72012-01-19 05:20:3480}
81
[email protected]fe58acc22012-02-29 01:29:5882OmniboxEventProto::InputType AsOmniboxEventInputType(
83 AutocompleteInput::Type type) {
84 switch (type) {
85 case AutocompleteInput::INVALID:
86 return OmniboxEventProto::INVALID;
87 case AutocompleteInput::UNKNOWN:
88 return OmniboxEventProto::UNKNOWN;
89 case AutocompleteInput::REQUESTED_URL:
90 return OmniboxEventProto::REQUESTED_URL;
91 case AutocompleteInput::URL:
92 return OmniboxEventProto::URL;
93 case AutocompleteInput::QUERY:
94 return OmniboxEventProto::QUERY;
95 case AutocompleteInput::FORCED_QUERY:
96 return OmniboxEventProto::FORCED_QUERY;
97 default:
98 NOTREACHED();
99 return OmniboxEventProto::INVALID;
100 }
101}
102
[email protected]fe58acc22012-02-29 01:29:58103OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
104 AutocompleteMatch::Type type) {
105 switch (type) {
106 case AutocompleteMatch::URL_WHAT_YOU_TYPED:
107 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
108 case AutocompleteMatch::HISTORY_URL:
109 return OmniboxEventProto::Suggestion::HISTORY_URL;
110 case AutocompleteMatch::HISTORY_TITLE:
111 return OmniboxEventProto::Suggestion::HISTORY_TITLE;
112 case AutocompleteMatch::HISTORY_BODY:
113 return OmniboxEventProto::Suggestion::HISTORY_BODY;
114 case AutocompleteMatch::HISTORY_KEYWORD:
115 return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
116 case AutocompleteMatch::NAVSUGGEST:
117 return OmniboxEventProto::Suggestion::NAVSUGGEST;
118 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
119 return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
120 case AutocompleteMatch::SEARCH_HISTORY:
121 return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
122 case AutocompleteMatch::SEARCH_SUGGEST:
123 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
124 case AutocompleteMatch::SEARCH_OTHER_ENGINE:
125 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
126 case AutocompleteMatch::EXTENSION_APP:
127 return OmniboxEventProto::Suggestion::EXTENSION_APP;
[email protected]dbacefb2012-09-12 03:32:06128 case AutocompleteMatch::CONTACT:
129 return OmniboxEventProto::Suggestion::CONTACT;
[email protected]fe58acc22012-02-29 01:29:58130 default:
131 NOTREACHED();
132 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
133 }
134}
135
[email protected]ed0fd002012-04-25 23:10:34136ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType(
137 content::ProcessType process_type) {
138 switch (process_type) {
139 case content::PROCESS_TYPE_BROWSER:
140 return ProfilerEventProto::TrackedObject::BROWSER;
141 case content::PROCESS_TYPE_RENDERER:
142 return ProfilerEventProto::TrackedObject::RENDERER;
143 case content::PROCESS_TYPE_PLUGIN:
144 return ProfilerEventProto::TrackedObject::PLUGIN;
145 case content::PROCESS_TYPE_WORKER:
146 return ProfilerEventProto::TrackedObject::WORKER;
147 case content::PROCESS_TYPE_NACL_LOADER:
148 return ProfilerEventProto::TrackedObject::NACL_LOADER;
149 case content::PROCESS_TYPE_UTILITY:
150 return ProfilerEventProto::TrackedObject::UTILITY;
151 case content::PROCESS_TYPE_PROFILE_IMPORT:
152 return ProfilerEventProto::TrackedObject::PROFILE_IMPORT;
153 case content::PROCESS_TYPE_ZYGOTE:
154 return ProfilerEventProto::TrackedObject::ZYGOTE;
155 case content::PROCESS_TYPE_SANDBOX_HELPER:
156 return ProfilerEventProto::TrackedObject::SANDBOX_HELPER;
157 case content::PROCESS_TYPE_NACL_BROKER:
158 return ProfilerEventProto::TrackedObject::NACL_BROKER;
159 case content::PROCESS_TYPE_GPU:
160 return ProfilerEventProto::TrackedObject::GPU;
161 case content::PROCESS_TYPE_PPAPI_PLUGIN:
162 return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN;
163 case content::PROCESS_TYPE_PPAPI_BROKER:
164 return ProfilerEventProto::TrackedObject::PPAPI_BROKER;
165 default:
166 NOTREACHED();
167 return ProfilerEventProto::TrackedObject::UNKNOWN;
168 }
169}
170
[email protected]1df44b72012-01-19 05:20:34171// Returns the plugin preferences corresponding for this user, if available.
172// If multiple user profiles are loaded, returns the preferences corresponding
173// to an arbitrary one of the profiles.
174PluginPrefs* GetPluginPrefs() {
175 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]fe58acc22012-02-29 01:29:58176
177 if (!profile_manager) {
178 // The profile manager can be NULL when testing.
179 return NULL;
180 }
181
[email protected]1df44b72012-01-19 05:20:34182 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
183 if (profiles.empty())
184 return NULL;
185
186 return PluginPrefs::GetForProfile(profiles.front());
187}
188
[email protected]fe58acc22012-02-29 01:29:58189// Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
190void SetPluginInfo(const webkit::WebPluginInfo& plugin_info,
191 const PluginPrefs* plugin_prefs,
192 SystemProfileProto::Plugin* plugin) {
193 plugin->set_name(UTF16ToUTF8(plugin_info.name));
194 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
195 plugin->set_version(UTF16ToUTF8(plugin_info.version));
196 if (plugin_prefs)
197 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
198}
199
[email protected]ad2461c2012-04-27 21:11:03200void WriteFieldTrials(const std::vector<SelectedGroupId>& field_trial_ids,
[email protected]767c9d92012-03-02 16:04:34201 SystemProfileProto* system_profile) {
[email protected]ad2461c2012-04-27 21:11:03202 for (std::vector<SelectedGroupId>::const_iterator it =
203 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
[email protected]767c9d92012-03-02 16:04:34204 SystemProfileProto::FieldTrial* field_trial =
205 system_profile->add_field_trial();
206 field_trial->set_name_id(it->name);
207 field_trial->set_group_id(it->group);
208 }
209}
210
[email protected]ed0fd002012-04-25 23:10:34211void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
212 content::ProcessType process_type,
213 ProfilerEventProto* performance_profile) {
214 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it =
215 profiler_data.tasks.begin();
216 it != profiler_data.tasks.end(); ++it) {
217 std::string ignored;
218 uint64 birth_thread_name_hash;
219 uint64 exec_thread_name_hash;
220 uint64 source_file_name_hash;
221 uint64 source_function_name_hash;
222 MetricsLogBase::CreateHashes(it->birth.thread_name,
223 &ignored, &birth_thread_name_hash);
224 MetricsLogBase::CreateHashes(it->death_thread_name,
225 &ignored, &exec_thread_name_hash);
226 MetricsLogBase::CreateHashes(it->birth.location.function_name,
227 &ignored, &source_file_name_hash);
228 MetricsLogBase::CreateHashes(it->birth.location.file_name,
229 &ignored, &source_function_name_hash);
230
231 const tracked_objects::DeathDataSnapshot& death_data = it->death_data;
232 ProfilerEventProto::TrackedObject* tracked_object =
233 performance_profile->add_tracked_object();
234 tracked_object->set_birth_thread_name_hash(birth_thread_name_hash);
235 tracked_object->set_exec_thread_name_hash(exec_thread_name_hash);
236 tracked_object->set_source_file_name_hash(source_file_name_hash);
237 tracked_object->set_source_function_name_hash(source_function_name_hash);
238 tracked_object->set_source_line_number(it->birth.location.line_number);
239 tracked_object->set_exec_count(death_data.count);
240 tracked_object->set_exec_time_total(death_data.run_duration_sum);
241 tracked_object->set_exec_time_sampled(death_data.run_duration_sample);
242 tracked_object->set_queue_time_total(death_data.queue_duration_sum);
243 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample);
244 tracked_object->set_process_type(AsProtobufProcessType(process_type));
245 tracked_object->set_process_id(profiler_data.process_id);
246 }
247}
248
[email protected]59a7ae4e2012-10-01 23:54:44249#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
[email protected]197c0772012-05-14 23:50:51250void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data,
251 ProductInfo* product_info) {
252 product_info->set_version(product_data.version);
253 product_info->set_last_update_success_timestamp(
254 product_data.last_success.ToTimeT());
255 product_info->set_last_error(product_data.last_error_code);
256 product_info->set_last_extra_error(product_data.last_extra_code);
257 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) {
258 product_info->set_last_result(
259 static_cast<ProductInfo::InstallResult>(product_data.last_result));
260 }
261}
[email protected]59a7ae4e2012-10-01 23:54:44262#endif
[email protected]197c0772012-05-14 23:50:51263
[email protected]1df44b72012-01-19 05:20:34264} // namespace
265
[email protected]197c0772012-05-14 23:50:51266GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {}
267
268GoogleUpdateMetrics::~GoogleUpdateMetrics() {}
269
[email protected]67f92bc32012-01-26 01:56:19270static base::LazyInstance<std::string>::Leaky
[email protected]054c8012011-11-16 00:12:42271 g_version_extension = LAZY_INSTANCE_INITIALIZER;
272
[email protected]1226abb2010-06-10 18:01:28273MetricsLog::MetricsLog(const std::string& client_id, int session_id)
274 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:41275
[email protected]1226abb2010-06-10 18:01:28276MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:29277
278// static
279void MetricsLog::RegisterPrefs(PrefService* local_state) {
280 local_state->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29281}
282
[email protected]1df44b72012-01-19 05:20:34283// static
[email protected]9165f742010-03-10 22:55:01284int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
285 base::TimeTicks now = base::TimeTicks::Now();
286 static base::TimeTicks last_updated_time(now);
287 int64 incremental_time = (now - last_updated_time).InSeconds();
288 last_updated_time = now;
289
290 if (incremental_time > 0) {
291 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
292 metrics_uptime += incremental_time;
293 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
294 }
295
296 return incremental_time;
297}
298
[email protected]1226abb2010-06-10 18:01:28299// static
300std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:42301 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:17302 if (!version_info.is_valid()) {
303 NOTREACHED() << "Unable to retrieve version info.";
304 return std::string();
305 }
306
[email protected]0211f57e2010-08-27 20:28:42307 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:42308 if (!version_extension().empty())
309 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:42310 if (!version_info.IsOfficialBuild())
311 version.append("-devel");
312 return version;
[email protected]1226abb2010-06-10 18:01:28313}
314
[email protected]054c8012011-11-16 00:12:42315// static
316void MetricsLog::set_version_extension(const std::string& extension) {
317 g_version_extension.Get() = extension;
318}
319
320// static
321const std::string& MetricsLog::version_extension() {
322 return g_version_extension.Get();
323}
324
[email protected]fe58acc22012-02-29 01:29:58325void MetricsLog::RecordIncrementalStabilityElements(
326 const std::vector<webkit::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34327 DCHECK(!locked());
[email protected]0b33f80b2008-12-17 21:34:36328
[email protected]767c9d92012-03-02 16:04:34329 PrefService* pref = GetPrefService();
[email protected]0b33f80b2008-12-17 21:34:36330 DCHECK(pref);
331
[email protected]147bbc0b2009-01-06 19:37:40332 OPEN_ELEMENT_FOR_SCOPE("profile");
333 WriteCommonEventAttributes();
334
[email protected]9958a322011-03-08 20:04:17335 WriteInstallElement();
[email protected]147bbc0b2009-01-06 19:37:40336
337 {
338 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
339 WriteRequiredStabilityAttributes(pref);
340 WriteRealtimeStabilityAttributes(pref);
341
[email protected]fe58acc22012-02-29 01:29:58342 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40343 }
[email protected]0b33f80b2008-12-17 21:34:36344}
345
[email protected]767c9d92012-03-02 16:04:34346PrefService* MetricsLog::GetPrefService() {
347 return g_browser_process->local_state();
348}
349
350gfx::Size MetricsLog::GetScreenSize() const {
[email protected]ffabb1e2012-10-12 19:51:17351 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel();
[email protected]767c9d92012-03-02 16:04:34352}
353
[email protected]aa96417972012-08-22 03:16:44354float MetricsLog::GetScreenDeviceScaleFactor() const {
[email protected]ffabb1e2012-10-12 19:51:17355 return gfx::Screen::GetNativeScreen()->
356 GetPrimaryDisplay().device_scale_factor();
[email protected]aa96417972012-08-22 03:16:44357}
358
[email protected]767c9d92012-03-02 16:04:34359int MetricsLog::GetScreenCount() const {
[email protected]ffabb1e2012-10-12 19:51:17360 // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312
361 return gfx::Screen::GetNativeScreen()->GetNumDisplays();
[email protected]767c9d92012-03-02 16:04:34362}
363
[email protected]767c9d92012-03-02 16:04:34364void MetricsLog::GetFieldTrialIds(
[email protected]ad2461c2012-04-27 21:11:03365 std::vector<SelectedGroupId>* field_trial_ids) const {
[email protected]2ac73f62012-08-13 21:49:07366 chrome_variations::GetFieldTrialSelectedGroupIds(field_trial_ids);
[email protected]767c9d92012-03-02 16:04:34367}
368
[email protected]fe58acc22012-02-29 01:29:58369void MetricsLog::WriteStabilityElement(
370 const std::vector<webkit::WebPluginInfo>& plugin_list,
371 PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:34372 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29373
initial.commit09911bf2008-07-26 23:55:29374 // Get stability attributes out of Local State, zeroing out stored values.
375 // NOTE: This could lead to some data loss if this report isn't successfully
376 // sent, but that's true for all the metrics.
377
[email protected]ffaf78a2008-11-12 17:38:33378 OPEN_ELEMENT_FOR_SCOPE("stability");
[email protected]147bbc0b2009-01-06 19:37:40379 WriteRequiredStabilityAttributes(pref);
380 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29381
[email protected]fe58acc22012-02-29 01:29:58382 int incomplete_shutdown_count =
383 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
[email protected]e324f6b2012-02-28 05:43:37384 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58385 int breakpad_registration_success_count =
386 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
[email protected]e324f6b2012-02-28 05:43:37387 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58388 int breakpad_registration_failure_count =
389 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
[email protected]e324f6b2012-02-28 05:43:37390 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58391 int debugger_present_count =
392 pref->GetInteger(prefs::kStabilityDebuggerPresent);
[email protected]e324f6b2012-02-28 05:43:37393 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58394 int debugger_not_present_count =
395 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
[email protected]e324f6b2012-02-28 05:43:37396 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31397
[email protected]fe58acc22012-02-29 01:29:58398 // TODO(jar): The following are all optional, so we *could* optimize them for
399 // values of zero (and not include them).
400
401 // Write the XML version.
402 WriteIntAttribute("incompleteshutdowncount", incomplete_shutdown_count);
403 WriteIntAttribute("breakpadregistrationok",
404 breakpad_registration_success_count);
405 WriteIntAttribute("breakpadregistrationfail",
406 breakpad_registration_failure_count);
407 WriteIntAttribute("debuggerpresent", debugger_present_count);
408 WriteIntAttribute("debuggernotpresent", debugger_not_present_count);
409
410 // Write the protobuf version.
411 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34412 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58413 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
414 stability->set_breakpad_registration_success_count(
415 breakpad_registration_success_count);
416 stability->set_breakpad_registration_failure_count(
417 breakpad_registration_failure_count);
418 stability->set_debugger_present_count(debugger_present_count);
419 stability->set_debugger_not_present_count(debugger_not_present_count);
420
421 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40422}
423
[email protected]fe58acc22012-02-29 01:29:58424void MetricsLog::WritePluginStabilityElements(
425 const std::vector<webkit::WebPluginInfo>& plugin_list,
426 PrefService* pref) {
[email protected]147bbc0b2009-01-06 19:37:40427 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29428 const ListValue* plugin_stats_list = pref->GetList(
429 prefs::kStabilityPluginStats);
[email protected]1df44b72012-01-19 05:20:34430 if (!plugin_stats_list)
431 return;
initial.commit09911bf2008-07-26 23:55:29432
[email protected]1df44b72012-01-19 05:20:34433 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]fe58acc22012-02-29 01:29:58434 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34435 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58436 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]1df44b72012-01-19 05:20:34437 for (ListValue::const_iterator iter = plugin_stats_list->begin();
438 iter != plugin_stats_list->end(); ++iter) {
439 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
440 NOTREACHED();
441 continue;
initial.commit09911bf2008-07-26 23:55:29442 }
[email protected]1df44b72012-01-19 05:20:34443 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29444
[email protected]1df44b72012-01-19 05:20:34445 std::string plugin_name;
446 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
447
[email protected]fe58acc22012-02-29 01:29:58448 std::string base64_name_hash;
449 uint64 numeric_name_hash_ignored;
450 CreateHashes(plugin_name, &base64_name_hash, &numeric_name_hash_ignored);
451
452 // Write the XML verison.
[email protected]1df44b72012-01-19 05:20:34453 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
454 // Use "filename" instead of "name", otherwise we need to update the
455 // UMA servers.
[email protected]fe58acc22012-02-29 01:29:58456 WriteAttribute("filename", base64_name_hash);
[email protected]1df44b72012-01-19 05:20:34457
458 int launches = 0;
459 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
460 WriteIntAttribute("launchcount", launches);
461
462 int instances = 0;
463 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
464 WriteIntAttribute("instancecount", instances);
465
466 int crashes = 0;
467 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
468 WriteIntAttribute("crashcount", crashes);
[email protected]fe58acc22012-02-29 01:29:58469
470 // Write the protobuf version.
471 // Note that this search is potentially a quadratic operation, but given the
472 // low number of plugins installed on a "reasonable" setup, this should be
473 // fine.
474 // TODO(isherman): Verify that this does not show up as a hotspot in
475 // profiler runs.
476 const webkit::WebPluginInfo* plugin_info = NULL;
477 const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name);
478 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
479 plugin_list.begin();
480 iter != plugin_list.end(); ++iter) {
481 if (iter->name == plugin_name_utf16) {
482 plugin_info = &(*iter);
483 break;
484 }
485 }
486
487 if (!plugin_info) {
488 NOTREACHED();
489 continue;
490 }
[email protected]cd937072012-07-02 09:00:29491 int loading_errors = 0;
492 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors,
493 &loading_errors);
494 WriteIntAttribute("loadingerrorcount", loading_errors);
[email protected]fe58acc22012-02-29 01:29:58495
[email protected]cd937072012-07-02 09:00:29496 // Write the protobuf version.
[email protected]fe58acc22012-02-29 01:29:58497 SystemProfileProto::Stability::PluginStability* plugin_stability =
498 stability->add_plugin_stability();
499 SetPluginInfo(*plugin_info, plugin_prefs,
500 plugin_stability->mutable_plugin());
501 plugin_stability->set_launch_count(launches);
502 plugin_stability->set_instance_count(instances);
503 plugin_stability->set_crash_count(crashes);
[email protected]cd937072012-07-02 09:00:29504 plugin_stability->set_loading_error_count(loading_errors);
initial.commit09911bf2008-07-26 23:55:29505 }
[email protected]1df44b72012-01-19 05:20:34506
507 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29508}
509
[email protected]fe58acc22012-02-29 01:29:58510// The server refuses data that doesn't have certain values. crashcount and
511// launchcount are currently "required" in the "stability" group.
512// TODO(isherman): Stop writing these attributes specially once the migration to
513// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40514void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]fe58acc22012-02-29 01:29:58515 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
[email protected]0b33f80b2008-12-17 21:34:36516 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
[email protected]fe58acc22012-02-29 01:29:58517 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
[email protected]0b33f80b2008-12-17 21:34:36518 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58519
520 // Write the XML version.
521 WriteIntAttribute("launchcount", launch_count);
522 WriteIntAttribute("crashcount", crash_count);
523
524 // Write the protobuf version.
525 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34526 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58527 stability->set_launch_count(launch_count);
528 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36529}
530
[email protected]147bbc0b2009-01-06 19:37:40531void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36532 // Update the stats which are critical for real-time stability monitoring.
533 // Since these are "optional," only list ones that are non-zero, as the counts
534 // are aggergated (summed) server side.
535
[email protected]fe58acc22012-02-29 01:29:58536 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34537 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36538 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
539 if (count) {
540 WriteIntAttribute("pageloadcount", count);
[email protected]fe58acc22012-02-29 01:29:58541 stability->set_page_load_count(count);
[email protected]0b33f80b2008-12-17 21:34:36542 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
543 }
544
545 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
546 if (count) {
547 WriteIntAttribute("renderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58548 stability->set_renderer_crash_count(count);
[email protected]0b33f80b2008-12-17 21:34:36549 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
550 }
551
[email protected]1f085622009-12-04 05:33:45552 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
553 if (count) {
554 WriteIntAttribute("extensionrenderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58555 stability->set_extension_renderer_crash_count(count);
[email protected]1f085622009-12-04 05:33:45556 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
557 }
558
[email protected]0b33f80b2008-12-17 21:34:36559 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
560 if (count) {
561 WriteIntAttribute("rendererhangcount", count);
[email protected]fe58acc22012-02-29 01:29:58562 stability->set_renderer_hang_count(count);
[email protected]0b33f80b2008-12-17 21:34:36563 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
564 }
[email protected]1f085622009-12-04 05:33:45565
566 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
567 if (count) {
568 WriteIntAttribute("childprocesscrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58569 stability->set_child_process_crash_count(count);
[email protected]1f085622009-12-04 05:33:45570 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
571 }
[email protected]9165f742010-03-10 22:55:01572
[email protected]c1834a92011-01-21 18:21:03573#if defined(OS_CHROMEOS)
574 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
575 if (count) {
[email protected]fe58acc22012-02-29 01:29:58576 stability->set_other_user_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03577 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
578 }
579
580 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
581 if (count) {
[email protected]fe58acc22012-02-29 01:29:58582 stability->set_kernel_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03583 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
584 }
585
586 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
587 if (count) {
[email protected]fe58acc22012-02-29 01:29:58588 stability->set_unclean_system_shutdown_count(count);
[email protected]c1834a92011-01-21 18:21:03589 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
590 }
591#endif // OS_CHROMEOS
592
[email protected]9165f742010-03-10 22:55:01593 int64 recent_duration = GetIncrementalUptime(pref);
[email protected]fe58acc22012-02-29 01:29:58594 if (recent_duration) {
[email protected]9165f742010-03-10 22:55:01595 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]fe58acc22012-02-29 01:29:58596 stability->set_uptime_sec(recent_duration);
597 }
[email protected]0b33f80b2008-12-17 21:34:36598}
599
initial.commit09911bf2008-07-26 23:55:29600void MetricsLog::WritePluginList(
[email protected]bc66d532012-03-23 01:57:05601 const std::vector<webkit::WebPluginInfo>& plugin_list,
602 bool write_as_xml) {
[email protected]767c9d92012-03-02 16:04:34603 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29604
[email protected]1df44b72012-01-19 05:20:34605 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]10084982011-08-19 17:56:56606
[email protected]ffaf78a2008-11-12 17:38:33607 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]767c9d92012-03-02 16:04:34608 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]91d9f3d2011-08-14 05:24:44609 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50610 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29611 iter != plugin_list.end(); ++iter) {
[email protected]bc66d532012-03-23 01:57:05612 if (write_as_xml) {
613 std::string base64_name_hash;
614 uint64 numeric_hash_ignored;
615 CreateHashes(UTF16ToUTF8(iter->name), &base64_name_hash,
616 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58617
[email protected]bc66d532012-03-23 01:57:05618 std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe();
619 std::string base64_filename_hash;
620 CreateHashes(filename_bytes, &base64_filename_hash,
621 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58622
[email protected]bc66d532012-03-23 01:57:05623 // Write the XML version.
624 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29625
[email protected]bc66d532012-03-23 01:57:05626 // Plugin name and filename are hashed for the privacy of those
627 // testing unreleased new extensions.
628 WriteAttribute("name", base64_name_hash);
629 WriteAttribute("filename", base64_filename_hash);
630 WriteAttribute("version", UTF16ToUTF8(iter->version));
631 if (plugin_prefs)
632 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
633 } else {
634 // Write the protobuf version.
635 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
636 SetPluginInfo(*iter, plugin_prefs, plugin);
637 }
initial.commit09911bf2008-07-26 23:55:29638 }
initial.commit09911bf2008-07-26 23:55:29639}
640
[email protected]147bbc0b2009-01-06 19:37:40641void MetricsLog::WriteInstallElement() {
[email protected]fe58acc22012-02-29 01:29:58642 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05643 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]147bbc0b2009-01-06 19:37:40644 OPEN_ELEMENT_FOR_SCOPE("install");
[email protected]bc66d532012-03-23 01:57:05645 WriteAttribute("installdate", GetInstallDate(GetPrefService()));
[email protected]147bbc0b2009-01-06 19:37:40646 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40647}
648
initial.commit09911bf2008-07-26 23:55:29649void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44650 const std::vector<webkit::WebPluginInfo>& plugin_list,
[email protected]197c0772012-05-14 23:50:51651 const GoogleUpdateMetrics& google_update_metrics,
initial.commit09911bf2008-07-26 23:55:29652 const DictionaryValue* profile_metrics) {
[email protected]767c9d92012-03-02 16:04:34653 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29654
[email protected]767c9d92012-03-02 16:04:34655 PrefService* pref = GetPrefService();
initial.commit09911bf2008-07-26 23:55:29656
[email protected]ffaf78a2008-11-12 17:38:33657 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29658 WriteCommonEventAttributes();
659
[email protected]147bbc0b2009-01-06 19:37:40660 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29661
[email protected]bc66d532012-03-23 01:57:05662 // Write the XML version.
663 // We'll write the protobuf version in RecordEnvironmentProto().
664 bool write_as_xml = true;
665 WritePluginList(plugin_list, write_as_xml);
initial.commit09911bf2008-07-26 23:55:29666
[email protected]fe58acc22012-02-29 01:29:58667 WriteStabilityElement(plugin_list, pref);
initial.commit09911bf2008-07-26 23:55:29668
669 {
[email protected]fe58acc22012-02-29 01:29:58670 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05671 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29672 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]0b6a4fb2012-10-16 01:58:21673 WriteAttribute("arch", base::SysInfo::OperatingSystemArchitecture());
initial.commit09911bf2008-07-26 23:55:29674 }
675
676 {
[email protected]fe58acc22012-02-29 01:29:58677 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05678 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29679 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]bc66d532012-03-23 01:57:05680 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38681#if defined(OS_WIN)
682 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
683#endif
initial.commit09911bf2008-07-26 23:55:29684 }
685
686 {
[email protected]fe58acc22012-02-29 01:29:58687 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05688 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29689 OPEN_ELEMENT_FOR_SCOPE("os");
[email protected]bc66d532012-03-23 01:57:05690 WriteAttribute("name", base::SysInfo::OperatingSystemName());
691 WriteAttribute("version", base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29692 }
693
694 {
[email protected]e8c287c872010-07-20 00:49:42695 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]fe58acc22012-02-29 01:29:58696 const content::GPUInfo& gpu_info =
697 GpuDataManager::GetInstance()->GetGPUInfo();
[email protected]fe58acc22012-02-29 01:29:58698
699 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05700 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]a094e2c2012-05-10 23:02:42701 WriteIntAttribute("vendorid", gpu_info.gpu.vendor_id);
702 WriteIntAttribute("deviceid", gpu_info.gpu.device_id);
[email protected]e8c287c872010-07-20 00:49:42703 }
704
705 {
[email protected]767c9d92012-03-02 16:04:34706 const gfx::Size display_size = GetScreenSize();
[email protected]fe58acc22012-02-29 01:29:58707
708 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05709 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]fe58acc22012-02-29 01:29:58710 OPEN_ELEMENT_FOR_SCOPE("display");
[email protected]bc66d532012-03-23 01:57:05711 WriteIntAttribute("xsize", display_size.width());
712 WriteIntAttribute("ysize", display_size.height());
713 WriteIntAttribute("screens", GetScreenCount());
initial.commit09911bf2008-07-26 23:55:29714 }
715
716 {
717 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
718 int num_bookmarks_on_bookmark_bar =
719 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
720 int num_folders_on_bookmark_bar =
721 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
722 int num_bookmarks_in_other_bookmarks_folder =
723 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
724 int num_folders_in_other_bookmarks_folder =
725 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
726 {
727 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
728 WriteAttribute("name", "full-tree");
729 WriteIntAttribute("foldercount",
730 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
731 WriteIntAttribute("itemcount",
732 num_bookmarks_on_bookmark_bar +
733 num_bookmarks_in_other_bookmarks_folder);
734 }
735 {
736 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
737 WriteAttribute("name", "toolbar");
738 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
739 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
740 }
741 }
742
743 {
744 OPEN_ELEMENT_FOR_SCOPE("keywords");
745 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
746 }
747
748 if (profile_metrics)
749 WriteAllProfilesMetrics(*profile_metrics);
[email protected]767c9d92012-03-02 16:04:34750
[email protected]197c0772012-05-14 23:50:51751 RecordEnvironmentProto(plugin_list, google_update_metrics);
[email protected]bc66d532012-03-23 01:57:05752}
753
754void MetricsLog::RecordEnvironmentProto(
[email protected]197c0772012-05-14 23:50:51755 const std::vector<webkit::WebPluginInfo>& plugin_list,
756 const GoogleUpdateMetrics& google_update_metrics) {
[email protected]bc66d532012-03-23 01:57:05757 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
758 int install_date;
759 bool success = base::StringToInt(GetInstallDate(GetPrefService()),
760 &install_date);
761 DCHECK(success);
762 system_profile->set_install_date(install_date);
763
764 system_profile->set_application_locale(
765 content::GetContentClient()->browser()->GetApplicationLocale());
766
767 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
[email protected]0b6a4fb2012-10-16 01:58:21768 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
[email protected]bc66d532012-03-23 01:57:05769 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
770#if defined(OS_WIN)
771 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
772#endif
773
774 SystemProfileProto::OS* os = system_profile->mutable_os();
[email protected]1bb25e02012-08-03 22:39:39775 std::string os_name = base::SysInfo::OperatingSystemName();
776#if defined(OS_WIN)
777 // TODO(mad): This only checks whether the main process is a Metro process at
778 // upload time; not whether the collected metrics were all gathered from
779 // Metro. This is ok as an approximation for now, since users will rarely be
780 // switching from Metro to Desktop mode; but we should re-evaluate whether we
781 // can distinguish metrics more cleanly in the future: http://crbug.com/140568
782 if (base::win::IsMetroProcess())
783 os_name += " (Metro)";
784#endif
785 os->set_name(os_name);
[email protected]bc66d532012-03-23 01:57:05786 os->set_version(base::SysInfo::OperatingSystemVersion());
[email protected]5106b3a2012-10-03 20:10:44787#if defined(OS_ANDROID)
788 os->set_fingerprint(
789 base::android::BuildInfo::GetInstance()->android_build_fp());
790#endif
[email protected]bc66d532012-03-23 01:57:05791
792 const content::GPUInfo& gpu_info =
793 GpuDataManager::GetInstance()->GetGPUInfo();
794 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
[email protected]a094e2c2012-05-10 23:02:42795 gpu->set_vendor_id(gpu_info.gpu.vendor_id);
796 gpu->set_device_id(gpu_info.gpu.device_id);
[email protected]bc66d532012-03-23 01:57:05797 gpu->set_driver_version(gpu_info.driver_version);
798 gpu->set_driver_date(gpu_info.driver_date);
799 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
800 gpu_performance = gpu->mutable_performance_statistics();
801 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
802 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
803 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
804
805 const gfx::Size display_size = GetScreenSize();
806 hardware->set_primary_screen_width(display_size.width());
807 hardware->set_primary_screen_height(display_size.height());
[email protected]aa96417972012-08-22 03:16:44808 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor());
[email protected]bc66d532012-03-23 01:57:05809 hardware->set_screen_count(GetScreenCount());
810
[email protected]197c0772012-05-14 23:50:51811 WriteGoogleUpdateProto(google_update_metrics);
812
[email protected]bc66d532012-03-23 01:57:05813 bool write_as_xml = false;
814 WritePluginList(plugin_list, write_as_xml);
815
[email protected]ad2461c2012-04-27 21:11:03816 std::vector<SelectedGroupId> field_trial_ids;
[email protected]767c9d92012-03-02 16:04:34817 GetFieldTrialIds(&field_trial_ids);
818 WriteFieldTrials(field_trial_ids, system_profile);
initial.commit09911bf2008-07-26 23:55:29819}
820
[email protected]ed0fd002012-04-25 23:10:34821void MetricsLog::RecordProfilerData(
822 const tracked_objects::ProcessDataSnapshot& process_data,
823 content::ProcessType process_type) {
824 DCHECK(!locked());
825
[email protected]8f829682012-04-27 00:36:49826 if (tracked_objects::GetTimeSourceType() !=
827 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) {
[email protected]ed0fd002012-04-25 23:10:34828 // We currently only support the default time source, wall clock time.
829 return;
830 }
831
832 ProfilerEventProto* profile;
833 if (!uma_proto()->profiler_event_size()) {
834 // For the first process's data, add a new field to the protocol buffer.
835 profile = uma_proto()->add_profiler_event();
836 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
837 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
838 } else {
839 // For the remaining calls, re-use the existing field.
840 profile = uma_proto()->mutable_profiler_event(0);
841 }
842
843 WriteProfilerData(process_data, process_type, profile);
844}
845
initial.commit09911bf2008-07-26 23:55:29846void MetricsLog::WriteAllProfilesMetrics(
847 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51848 const std::string profile_prefix(prefs::kProfilePrefix);
initial.commit09911bf2008-07-26 23:55:29849 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
850 i != all_profiles_metrics.end_keys(); ++i) {
[email protected]e7b418b2010-07-30 19:47:47851 const std::string& key_name = *i;
initial.commit09911bf2008-07-26 23:55:29852 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
[email protected]a61890e2012-07-27 22:27:11853 const DictionaryValue* profile;
[email protected]4dad9ad82009-11-25 20:47:52854 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
855 &profile))
initial.commit09911bf2008-07-26 23:55:29856 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
857 }
858 }
859}
860
[email protected]e7b418b2010-07-30 19:47:47861void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29862 const DictionaryValue& profile_metrics) {
863 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47864 WriteAttribute("profileidhash", profileidhash);
initial.commit09911bf2008-07-26 23:55:29865 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
866 i != profile_metrics.end_keys(); ++i) {
[email protected]a61890e2012-07-27 22:27:11867 const Value* value;
[email protected]4dad9ad82009-11-25 20:47:52868 if (profile_metrics.GetWithoutPathExpansion(*i, &value)) {
[email protected]0b6a4fb2012-10-16 01:58:21869 DCHECK_NE(*i, "id");
initial.commit09911bf2008-07-26 23:55:29870 switch (value->GetType()) {
871 case Value::TYPE_STRING: {
[email protected]5e324b72008-12-18 00:07:59872 std::string string_value;
initial.commit09911bf2008-07-26 23:55:29873 if (value->GetAsString(&string_value)) {
874 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47875 WriteAttribute("name", *i);
[email protected]5e324b72008-12-18 00:07:59876 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29877 }
878 break;
879 }
880
881 case Value::TYPE_BOOLEAN: {
882 bool bool_value;
883 if (value->GetAsBoolean(&bool_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", bool_value ? 1 : 0);
887 }
888 break;
889 }
890
891 case Value::TYPE_INTEGER: {
892 int int_value;
893 if (value->GetAsInteger(&int_value)) {
894 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47895 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29896 WriteIntAttribute("value", int_value);
897 }
898 break;
899 }
900
901 default:
902 NOTREACHED();
903 break;
904 }
905 }
906 }
907}
908
909void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
[email protected]767c9d92012-03-02 16:04:34910 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29911
[email protected]fe58acc22012-02-29 01:29:58912 // Write the XML version.
[email protected]ffaf78a2008-11-12 17:38:33913 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29914 WriteAttribute("action", "autocomplete");
915 WriteAttribute("targetidhash", "");
916 // TODO(kochi): Properly track windows.
917 WriteIntAttribute("window", 0);
[email protected]6ebc3162011-12-19 13:44:00918 if (log.tab_id != -1) {
919 // If we know what tab the autocomplete URL was opened in, log it.
920 WriteIntAttribute("tab", static_cast<int>(log.tab_id));
921 }
initial.commit09911bf2008-07-26 23:55:29922 WriteCommonEventAttributes();
923
[email protected]65956312012-04-19 21:28:12924 std::vector<string16> terms;
925 const int num_terms =
926 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms));
[email protected]ffaf78a2008-11-12 17:38:33927 {
928 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29929
[email protected]ffaf78a2008-11-12 17:38:33930 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
[email protected]65956312012-04-19 21:28:12931 WriteIntAttribute("numterms", num_terms);
[email protected]ffaf78a2008-11-12 17:38:33932 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
933 WriteIntAttribute("completedlength",
934 static_cast<int>(log.inline_autocompleted_length));
[email protected]9e349762012-01-31 03:24:36935 if (log.elapsed_time_since_user_first_modified_omnibox !=
936 base::TimeDelta::FromMilliseconds(-1)) {
937 // Only upload the typing duration if it is set/valid.
938 WriteInt64Attribute("typingduration",
939 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
940 }
[email protected]381e2992008-12-16 01:41:00941 const std::string input_type(
942 AutocompleteInput::TypeToString(log.input_type));
943 if (!input_type.empty())
944 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:29945
[email protected]ffaf78a2008-11-12 17:38:33946 for (AutocompleteResult::const_iterator i(log.result.begin());
947 i != log.result.end(); ++i) {
948 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
949 if (i->provider)
[email protected]35f1f4f02012-09-11 13:17:00950 WriteAttribute("provider", i->provider->GetName());
[email protected]381e2992008-12-16 01:41:00951 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
952 if (!result_type.empty())
953 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:33954 WriteIntAttribute("relevance", i->relevance);
955 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
956 }
initial.commit09911bf2008-07-26 23:55:29957 }
initial.commit09911bf2008-07-26 23:55:29958
[email protected]fe58acc22012-02-29 01:29:58959 // Write the protobuf version.
[email protected]767c9d92012-03-02 16:04:34960 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
[email protected]fe58acc22012-02-29 01:29:58961 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
962 if (log.tab_id != -1) {
963 // If we know what tab the autocomplete URL was opened in, log it.
964 omnibox_event->set_tab_id(log.tab_id);
965 }
966 omnibox_event->set_typed_length(log.text.length());
[email protected]660fe8f32012-05-03 20:01:08967 omnibox_event->set_just_deleted_text(log.just_deleted_text);
[email protected]65956312012-04-19 21:28:12968 omnibox_event->set_num_typed_terms(num_terms);
[email protected]fe58acc22012-02-29 01:29:58969 omnibox_event->set_selected_index(log.selected_index);
970 omnibox_event->set_completed_length(log.inline_autocompleted_length);
[email protected]65956312012-04-19 21:28:12971 if (log.elapsed_time_since_user_first_modified_omnibox !=
972 base::TimeDelta::FromMilliseconds(-1)) {
973 // Only upload the typing duration if it is set/valid.
974 omnibox_event->set_typing_duration_ms(
975 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
976 }
[email protected]ee902532012-05-01 23:54:49977 omnibox_event->set_current_page_classification(
978 log.current_page_classification);
[email protected]fe58acc22012-02-29 01:29:58979 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
980 for (AutocompleteResult::const_iterator i(log.result.begin());
981 i != log.result.end(); ++i) {
982 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
[email protected]0e9e8782012-05-15 23:01:51983 suggestion->set_provider(i->provider->AsOmniboxEventProviderType());
[email protected]fe58acc22012-02-29 01:29:58984 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
985 suggestion->set_relevance(i->relevance);
[email protected]cf6256f2012-06-12 23:36:01986 if (i->typed_count != -1)
987 suggestion->set_typed_count(i->typed_count);
[email protected]fe58acc22012-02-29 01:29:58988 suggestion->set_is_starred(i->starred);
989 }
[email protected]0e9e8782012-05-15 23:01:51990 for (ProvidersInfo::const_iterator i(log.providers_info.begin());
991 i != log.providers_info.end(); ++i) {
992 OmniboxEventProto::ProviderInfo* provider_info =
993 omnibox_event->add_provider_info();
994 provider_info->CopyFrom(*i);
995 }
[email protected]fe58acc22012-02-29 01:29:58996
initial.commit09911bf2008-07-26 23:55:29997 ++num_events_;
998}
[email protected]197c0772012-05-14 23:50:51999
1000void MetricsLog::WriteGoogleUpdateProto(
1001 const GoogleUpdateMetrics& google_update_metrics) {
1002#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
1003 SystemProfileProto::GoogleUpdate* google_update =
1004 uma_proto()->mutable_system_profile()->mutable_google_update();
1005
1006 google_update->set_is_system_install(google_update_metrics.is_system_install);
1007
1008 if (!google_update_metrics.last_started_au.is_null()) {
1009 google_update->set_last_automatic_start_timestamp(
1010 google_update_metrics.last_started_au.ToTimeT());
1011 }
1012
1013 if (!google_update_metrics.last_checked.is_null()) {
1014 google_update->set_last_update_check_timestamp(
1015 google_update_metrics.last_checked.ToTimeT());
1016 }
1017
1018 if (!google_update_metrics.google_update_data.version.empty()) {
1019 ProductDataToProto(google_update_metrics.google_update_data,
1020 google_update->mutable_google_update_status());
1021 }
1022
1023 if (!google_update_metrics.product_data.version.empty()) {
1024 ProductDataToProto(google_update_metrics.product_data,
1025 google_update->mutable_client_status());
1026 }
1027#endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
1028}