blob: 7ff5b5aa2862d89ec377f695e9036a960bb055b7 [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]cc5d7f42012-10-30 00:30:0973std::string GetMetricsEnabledDate(PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:3474 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]25320602012-10-18 22:05:56130 case AutocompleteMatch::BOOKMARK_TITLE:
131 return OmniboxEventProto::Suggestion::BOOKMARK_TITLE;
[email protected]fe58acc22012-02-29 01:29:58132 default:
133 NOTREACHED();
134 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
135 }
136}
137
[email protected]ed0fd002012-04-25 23:10:34138ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType(
139 content::ProcessType process_type) {
140 switch (process_type) {
141 case content::PROCESS_TYPE_BROWSER:
142 return ProfilerEventProto::TrackedObject::BROWSER;
143 case content::PROCESS_TYPE_RENDERER:
144 return ProfilerEventProto::TrackedObject::RENDERER;
145 case content::PROCESS_TYPE_PLUGIN:
146 return ProfilerEventProto::TrackedObject::PLUGIN;
147 case content::PROCESS_TYPE_WORKER:
148 return ProfilerEventProto::TrackedObject::WORKER;
149 case content::PROCESS_TYPE_NACL_LOADER:
150 return ProfilerEventProto::TrackedObject::NACL_LOADER;
151 case content::PROCESS_TYPE_UTILITY:
152 return ProfilerEventProto::TrackedObject::UTILITY;
153 case content::PROCESS_TYPE_PROFILE_IMPORT:
154 return ProfilerEventProto::TrackedObject::PROFILE_IMPORT;
155 case content::PROCESS_TYPE_ZYGOTE:
156 return ProfilerEventProto::TrackedObject::ZYGOTE;
157 case content::PROCESS_TYPE_SANDBOX_HELPER:
158 return ProfilerEventProto::TrackedObject::SANDBOX_HELPER;
159 case content::PROCESS_TYPE_NACL_BROKER:
160 return ProfilerEventProto::TrackedObject::NACL_BROKER;
161 case content::PROCESS_TYPE_GPU:
162 return ProfilerEventProto::TrackedObject::GPU;
163 case content::PROCESS_TYPE_PPAPI_PLUGIN:
164 return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN;
165 case content::PROCESS_TYPE_PPAPI_BROKER:
166 return ProfilerEventProto::TrackedObject::PPAPI_BROKER;
167 default:
168 NOTREACHED();
169 return ProfilerEventProto::TrackedObject::UNKNOWN;
170 }
171}
172
[email protected]1df44b72012-01-19 05:20:34173// Returns the plugin preferences corresponding for this user, if available.
174// If multiple user profiles are loaded, returns the preferences corresponding
175// to an arbitrary one of the profiles.
176PluginPrefs* GetPluginPrefs() {
177 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]fe58acc22012-02-29 01:29:58178
179 if (!profile_manager) {
180 // The profile manager can be NULL when testing.
181 return NULL;
182 }
183
[email protected]1df44b72012-01-19 05:20:34184 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
185 if (profiles.empty())
186 return NULL;
187
188 return PluginPrefs::GetForProfile(profiles.front());
189}
190
[email protected]fe58acc22012-02-29 01:29:58191// Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
192void SetPluginInfo(const webkit::WebPluginInfo& plugin_info,
193 const PluginPrefs* plugin_prefs,
194 SystemProfileProto::Plugin* plugin) {
195 plugin->set_name(UTF16ToUTF8(plugin_info.name));
196 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
197 plugin->set_version(UTF16ToUTF8(plugin_info.version));
198 if (plugin_prefs)
199 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
200}
201
[email protected]ad2461c2012-04-27 21:11:03202void WriteFieldTrials(const std::vector<SelectedGroupId>& field_trial_ids,
[email protected]767c9d92012-03-02 16:04:34203 SystemProfileProto* system_profile) {
[email protected]ad2461c2012-04-27 21:11:03204 for (std::vector<SelectedGroupId>::const_iterator it =
205 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
[email protected]767c9d92012-03-02 16:04:34206 SystemProfileProto::FieldTrial* field_trial =
207 system_profile->add_field_trial();
208 field_trial->set_name_id(it->name);
209 field_trial->set_group_id(it->group);
210 }
211}
212
[email protected]ed0fd002012-04-25 23:10:34213void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
214 content::ProcessType process_type,
215 ProfilerEventProto* performance_profile) {
216 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it =
217 profiler_data.tasks.begin();
218 it != profiler_data.tasks.end(); ++it) {
219 std::string ignored;
220 uint64 birth_thread_name_hash;
221 uint64 exec_thread_name_hash;
222 uint64 source_file_name_hash;
223 uint64 source_function_name_hash;
224 MetricsLogBase::CreateHashes(it->birth.thread_name,
225 &ignored, &birth_thread_name_hash);
226 MetricsLogBase::CreateHashes(it->death_thread_name,
227 &ignored, &exec_thread_name_hash);
[email protected]ed0fd002012-04-25 23:10:34228 MetricsLogBase::CreateHashes(it->birth.location.file_name,
[email protected]04162262012-10-23 01:17:25229 &ignored, &source_file_name_hash);
230 MetricsLogBase::CreateHashes(it->birth.location.function_name,
[email protected]ed0fd002012-04-25 23:10:34231 &ignored, &source_function_name_hash);
232
233 const tracked_objects::DeathDataSnapshot& death_data = it->death_data;
234 ProfilerEventProto::TrackedObject* tracked_object =
235 performance_profile->add_tracked_object();
236 tracked_object->set_birth_thread_name_hash(birth_thread_name_hash);
237 tracked_object->set_exec_thread_name_hash(exec_thread_name_hash);
238 tracked_object->set_source_file_name_hash(source_file_name_hash);
239 tracked_object->set_source_function_name_hash(source_function_name_hash);
240 tracked_object->set_source_line_number(it->birth.location.line_number);
241 tracked_object->set_exec_count(death_data.count);
242 tracked_object->set_exec_time_total(death_data.run_duration_sum);
243 tracked_object->set_exec_time_sampled(death_data.run_duration_sample);
244 tracked_object->set_queue_time_total(death_data.queue_duration_sum);
245 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample);
246 tracked_object->set_process_type(AsProtobufProcessType(process_type));
247 tracked_object->set_process_id(profiler_data.process_id);
248 }
249}
250
[email protected]59a7ae4e2012-10-01 23:54:44251#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
[email protected]197c0772012-05-14 23:50:51252void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data,
253 ProductInfo* product_info) {
254 product_info->set_version(product_data.version);
255 product_info->set_last_update_success_timestamp(
256 product_data.last_success.ToTimeT());
257 product_info->set_last_error(product_data.last_error_code);
258 product_info->set_last_extra_error(product_data.last_extra_code);
259 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) {
260 product_info->set_last_result(
261 static_cast<ProductInfo::InstallResult>(product_data.last_result));
262 }
263}
[email protected]59a7ae4e2012-10-01 23:54:44264#endif
[email protected]197c0772012-05-14 23:50:51265
[email protected]1df44b72012-01-19 05:20:34266} // namespace
267
[email protected]197c0772012-05-14 23:50:51268GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {}
269
270GoogleUpdateMetrics::~GoogleUpdateMetrics() {}
271
[email protected]67f92bc32012-01-26 01:56:19272static base::LazyInstance<std::string>::Leaky
[email protected]054c8012011-11-16 00:12:42273 g_version_extension = LAZY_INSTANCE_INITIALIZER;
274
[email protected]1226abb2010-06-10 18:01:28275MetricsLog::MetricsLog(const std::string& client_id, int session_id)
276 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:41277
[email protected]1226abb2010-06-10 18:01:28278MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:29279
280// static
281void MetricsLog::RegisterPrefs(PrefService* local_state) {
282 local_state->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29283}
284
[email protected]1df44b72012-01-19 05:20:34285// static
[email protected]9165f742010-03-10 22:55:01286int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
287 base::TimeTicks now = base::TimeTicks::Now();
288 static base::TimeTicks last_updated_time(now);
289 int64 incremental_time = (now - last_updated_time).InSeconds();
290 last_updated_time = now;
291
292 if (incremental_time > 0) {
293 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
294 metrics_uptime += incremental_time;
295 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
296 }
297
298 return incremental_time;
299}
300
[email protected]1226abb2010-06-10 18:01:28301// static
302std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:42303 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:17304 if (!version_info.is_valid()) {
305 NOTREACHED() << "Unable to retrieve version info.";
306 return std::string();
307 }
308
[email protected]0211f57e2010-08-27 20:28:42309 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:42310 if (!version_extension().empty())
311 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:42312 if (!version_info.IsOfficialBuild())
313 version.append("-devel");
314 return version;
[email protected]1226abb2010-06-10 18:01:28315}
316
[email protected]054c8012011-11-16 00:12:42317// static
318void MetricsLog::set_version_extension(const std::string& extension) {
319 g_version_extension.Get() = extension;
320}
321
322// static
323const std::string& MetricsLog::version_extension() {
324 return g_version_extension.Get();
325}
326
[email protected]fe58acc22012-02-29 01:29:58327void MetricsLog::RecordIncrementalStabilityElements(
328 const std::vector<webkit::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34329 DCHECK(!locked());
[email protected]0b33f80b2008-12-17 21:34:36330
[email protected]767c9d92012-03-02 16:04:34331 PrefService* pref = GetPrefService();
[email protected]0b33f80b2008-12-17 21:34:36332 DCHECK(pref);
333
[email protected]147bbc0b2009-01-06 19:37:40334 OPEN_ELEMENT_FOR_SCOPE("profile");
335 WriteCommonEventAttributes();
336
[email protected]9958a322011-03-08 20:04:17337 WriteInstallElement();
[email protected]147bbc0b2009-01-06 19:37:40338
339 {
340 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
341 WriteRequiredStabilityAttributes(pref);
342 WriteRealtimeStabilityAttributes(pref);
343
[email protected]fe58acc22012-02-29 01:29:58344 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40345 }
[email protected]0b33f80b2008-12-17 21:34:36346}
347
[email protected]767c9d92012-03-02 16:04:34348PrefService* MetricsLog::GetPrefService() {
349 return g_browser_process->local_state();
350}
351
352gfx::Size MetricsLog::GetScreenSize() const {
[email protected]ffabb1e2012-10-12 19:51:17353 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel();
[email protected]767c9d92012-03-02 16:04:34354}
355
[email protected]aa96417972012-08-22 03:16:44356float MetricsLog::GetScreenDeviceScaleFactor() const {
[email protected]ffabb1e2012-10-12 19:51:17357 return gfx::Screen::GetNativeScreen()->
358 GetPrimaryDisplay().device_scale_factor();
[email protected]aa96417972012-08-22 03:16:44359}
360
[email protected]767c9d92012-03-02 16:04:34361int MetricsLog::GetScreenCount() const {
[email protected]ffabb1e2012-10-12 19:51:17362 // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312
363 return gfx::Screen::GetNativeScreen()->GetNumDisplays();
[email protected]767c9d92012-03-02 16:04:34364}
365
[email protected]767c9d92012-03-02 16:04:34366void MetricsLog::GetFieldTrialIds(
[email protected]ad2461c2012-04-27 21:11:03367 std::vector<SelectedGroupId>* field_trial_ids) const {
[email protected]2ac73f62012-08-13 21:49:07368 chrome_variations::GetFieldTrialSelectedGroupIds(field_trial_ids);
[email protected]767c9d92012-03-02 16:04:34369}
370
[email protected]fe58acc22012-02-29 01:29:58371void MetricsLog::WriteStabilityElement(
372 const std::vector<webkit::WebPluginInfo>& plugin_list,
373 PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:34374 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29375
initial.commit09911bf2008-07-26 23:55:29376 // Get stability attributes out of Local State, zeroing out stored values.
377 // NOTE: This could lead to some data loss if this report isn't successfully
378 // sent, but that's true for all the metrics.
379
[email protected]ffaf78a2008-11-12 17:38:33380 OPEN_ELEMENT_FOR_SCOPE("stability");
[email protected]147bbc0b2009-01-06 19:37:40381 WriteRequiredStabilityAttributes(pref);
382 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29383
[email protected]fe58acc22012-02-29 01:29:58384 int incomplete_shutdown_count =
385 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
[email protected]e324f6b2012-02-28 05:43:37386 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58387 int breakpad_registration_success_count =
388 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
[email protected]e324f6b2012-02-28 05:43:37389 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58390 int breakpad_registration_failure_count =
391 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
[email protected]e324f6b2012-02-28 05:43:37392 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58393 int debugger_present_count =
394 pref->GetInteger(prefs::kStabilityDebuggerPresent);
[email protected]e324f6b2012-02-28 05:43:37395 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58396 int debugger_not_present_count =
397 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
[email protected]e324f6b2012-02-28 05:43:37398 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31399
[email protected]fe58acc22012-02-29 01:29:58400 // TODO(jar): The following are all optional, so we *could* optimize them for
401 // values of zero (and not include them).
402
403 // Write the XML version.
404 WriteIntAttribute("incompleteshutdowncount", incomplete_shutdown_count);
405 WriteIntAttribute("breakpadregistrationok",
406 breakpad_registration_success_count);
407 WriteIntAttribute("breakpadregistrationfail",
408 breakpad_registration_failure_count);
409 WriteIntAttribute("debuggerpresent", debugger_present_count);
410 WriteIntAttribute("debuggernotpresent", debugger_not_present_count);
411
412 // Write the protobuf version.
413 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34414 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58415 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
416 stability->set_breakpad_registration_success_count(
417 breakpad_registration_success_count);
418 stability->set_breakpad_registration_failure_count(
419 breakpad_registration_failure_count);
420 stability->set_debugger_present_count(debugger_present_count);
421 stability->set_debugger_not_present_count(debugger_not_present_count);
422
423 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40424}
425
[email protected]fe58acc22012-02-29 01:29:58426void MetricsLog::WritePluginStabilityElements(
427 const std::vector<webkit::WebPluginInfo>& plugin_list,
428 PrefService* pref) {
[email protected]147bbc0b2009-01-06 19:37:40429 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29430 const ListValue* plugin_stats_list = pref->GetList(
431 prefs::kStabilityPluginStats);
[email protected]1df44b72012-01-19 05:20:34432 if (!plugin_stats_list)
433 return;
initial.commit09911bf2008-07-26 23:55:29434
[email protected]1df44b72012-01-19 05:20:34435 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]fe58acc22012-02-29 01:29:58436 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34437 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58438 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]1df44b72012-01-19 05:20:34439 for (ListValue::const_iterator iter = plugin_stats_list->begin();
440 iter != plugin_stats_list->end(); ++iter) {
441 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
442 NOTREACHED();
443 continue;
initial.commit09911bf2008-07-26 23:55:29444 }
[email protected]1df44b72012-01-19 05:20:34445 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29446
[email protected]1df44b72012-01-19 05:20:34447 std::string plugin_name;
448 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
449
[email protected]fe58acc22012-02-29 01:29:58450 std::string base64_name_hash;
451 uint64 numeric_name_hash_ignored;
452 CreateHashes(plugin_name, &base64_name_hash, &numeric_name_hash_ignored);
453
454 // Write the XML verison.
[email protected]1df44b72012-01-19 05:20:34455 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
456 // Use "filename" instead of "name", otherwise we need to update the
457 // UMA servers.
[email protected]fe58acc22012-02-29 01:29:58458 WriteAttribute("filename", base64_name_hash);
[email protected]1df44b72012-01-19 05:20:34459
460 int launches = 0;
461 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
462 WriteIntAttribute("launchcount", launches);
463
464 int instances = 0;
465 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
466 WriteIntAttribute("instancecount", instances);
467
468 int crashes = 0;
469 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
470 WriteIntAttribute("crashcount", crashes);
[email protected]fe58acc22012-02-29 01:29:58471
472 // Write the protobuf version.
473 // Note that this search is potentially a quadratic operation, but given the
474 // low number of plugins installed on a "reasonable" setup, this should be
475 // fine.
476 // TODO(isherman): Verify that this does not show up as a hotspot in
477 // profiler runs.
478 const webkit::WebPluginInfo* plugin_info = NULL;
479 const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name);
480 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
481 plugin_list.begin();
482 iter != plugin_list.end(); ++iter) {
483 if (iter->name == plugin_name_utf16) {
484 plugin_info = &(*iter);
485 break;
486 }
487 }
488
489 if (!plugin_info) {
490 NOTREACHED();
491 continue;
492 }
[email protected]cd937072012-07-02 09:00:29493 int loading_errors = 0;
494 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors,
495 &loading_errors);
496 WriteIntAttribute("loadingerrorcount", loading_errors);
[email protected]fe58acc22012-02-29 01:29:58497
[email protected]cd937072012-07-02 09:00:29498 // Write the protobuf version.
[email protected]fe58acc22012-02-29 01:29:58499 SystemProfileProto::Stability::PluginStability* plugin_stability =
500 stability->add_plugin_stability();
501 SetPluginInfo(*plugin_info, plugin_prefs,
502 plugin_stability->mutable_plugin());
503 plugin_stability->set_launch_count(launches);
504 plugin_stability->set_instance_count(instances);
505 plugin_stability->set_crash_count(crashes);
[email protected]cd937072012-07-02 09:00:29506 plugin_stability->set_loading_error_count(loading_errors);
initial.commit09911bf2008-07-26 23:55:29507 }
[email protected]1df44b72012-01-19 05:20:34508
509 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29510}
511
[email protected]fe58acc22012-02-29 01:29:58512// The server refuses data that doesn't have certain values. crashcount and
513// launchcount are currently "required" in the "stability" group.
514// TODO(isherman): Stop writing these attributes specially once the migration to
515// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40516void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]fe58acc22012-02-29 01:29:58517 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
[email protected]0b33f80b2008-12-17 21:34:36518 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
[email protected]fe58acc22012-02-29 01:29:58519 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
[email protected]0b33f80b2008-12-17 21:34:36520 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58521
522 // Write the XML version.
523 WriteIntAttribute("launchcount", launch_count);
524 WriteIntAttribute("crashcount", crash_count);
525
526 // Write the protobuf version.
527 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34528 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58529 stability->set_launch_count(launch_count);
530 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36531}
532
[email protected]147bbc0b2009-01-06 19:37:40533void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36534 // Update the stats which are critical for real-time stability monitoring.
535 // Since these are "optional," only list ones that are non-zero, as the counts
536 // are aggergated (summed) server side.
537
[email protected]fe58acc22012-02-29 01:29:58538 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34539 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36540 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
541 if (count) {
542 WriteIntAttribute("pageloadcount", count);
[email protected]fe58acc22012-02-29 01:29:58543 stability->set_page_load_count(count);
[email protected]0b33f80b2008-12-17 21:34:36544 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
545 }
546
547 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
548 if (count) {
549 WriteIntAttribute("renderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58550 stability->set_renderer_crash_count(count);
[email protected]0b33f80b2008-12-17 21:34:36551 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
552 }
553
[email protected]1f085622009-12-04 05:33:45554 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
555 if (count) {
556 WriteIntAttribute("extensionrenderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58557 stability->set_extension_renderer_crash_count(count);
[email protected]1f085622009-12-04 05:33:45558 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
559 }
560
[email protected]0b33f80b2008-12-17 21:34:36561 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
562 if (count) {
563 WriteIntAttribute("rendererhangcount", count);
[email protected]fe58acc22012-02-29 01:29:58564 stability->set_renderer_hang_count(count);
[email protected]0b33f80b2008-12-17 21:34:36565 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
566 }
[email protected]1f085622009-12-04 05:33:45567
568 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
569 if (count) {
570 WriteIntAttribute("childprocesscrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58571 stability->set_child_process_crash_count(count);
[email protected]1f085622009-12-04 05:33:45572 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
573 }
[email protected]9165f742010-03-10 22:55:01574
[email protected]c1834a92011-01-21 18:21:03575#if defined(OS_CHROMEOS)
576 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
577 if (count) {
[email protected]fe58acc22012-02-29 01:29:58578 stability->set_other_user_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03579 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
580 }
581
582 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
583 if (count) {
[email protected]fe58acc22012-02-29 01:29:58584 stability->set_kernel_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03585 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
586 }
587
588 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
589 if (count) {
[email protected]fe58acc22012-02-29 01:29:58590 stability->set_unclean_system_shutdown_count(count);
[email protected]c1834a92011-01-21 18:21:03591 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
592 }
593#endif // OS_CHROMEOS
594
[email protected]9165f742010-03-10 22:55:01595 int64 recent_duration = GetIncrementalUptime(pref);
[email protected]fe58acc22012-02-29 01:29:58596 if (recent_duration) {
[email protected]9165f742010-03-10 22:55:01597 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]fe58acc22012-02-29 01:29:58598 stability->set_uptime_sec(recent_duration);
599 }
[email protected]0b33f80b2008-12-17 21:34:36600}
601
initial.commit09911bf2008-07-26 23:55:29602void MetricsLog::WritePluginList(
[email protected]bc66d532012-03-23 01:57:05603 const std::vector<webkit::WebPluginInfo>& plugin_list,
604 bool write_as_xml) {
[email protected]767c9d92012-03-02 16:04:34605 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29606
[email protected]1df44b72012-01-19 05:20:34607 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]10084982011-08-19 17:56:56608
[email protected]ffaf78a2008-11-12 17:38:33609 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]767c9d92012-03-02 16:04:34610 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]91d9f3d2011-08-14 05:24:44611 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50612 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29613 iter != plugin_list.end(); ++iter) {
[email protected]bc66d532012-03-23 01:57:05614 if (write_as_xml) {
615 std::string base64_name_hash;
616 uint64 numeric_hash_ignored;
617 CreateHashes(UTF16ToUTF8(iter->name), &base64_name_hash,
618 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58619
[email protected]bc66d532012-03-23 01:57:05620 std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe();
621 std::string base64_filename_hash;
622 CreateHashes(filename_bytes, &base64_filename_hash,
623 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58624
[email protected]bc66d532012-03-23 01:57:05625 // Write the XML version.
626 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29627
[email protected]bc66d532012-03-23 01:57:05628 // Plugin name and filename are hashed for the privacy of those
629 // testing unreleased new extensions.
630 WriteAttribute("name", base64_name_hash);
631 WriteAttribute("filename", base64_filename_hash);
632 WriteAttribute("version", UTF16ToUTF8(iter->version));
633 if (plugin_prefs)
634 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
635 } else {
636 // Write the protobuf version.
637 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
638 SetPluginInfo(*iter, plugin_prefs, plugin);
639 }
initial.commit09911bf2008-07-26 23:55:29640 }
initial.commit09911bf2008-07-26 23:55:29641}
642
[email protected]147bbc0b2009-01-06 19:37:40643void MetricsLog::WriteInstallElement() {
[email protected]fe58acc22012-02-29 01:29:58644 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05645 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]147bbc0b2009-01-06 19:37:40646 OPEN_ELEMENT_FOR_SCOPE("install");
[email protected]cc5d7f42012-10-30 00:30:09647 WriteAttribute("installdate", GetMetricsEnabledDate(GetPrefService()));
[email protected]147bbc0b2009-01-06 19:37:40648 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40649}
650
initial.commit09911bf2008-07-26 23:55:29651void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44652 const std::vector<webkit::WebPluginInfo>& plugin_list,
[email protected]197c0772012-05-14 23:50:51653 const GoogleUpdateMetrics& google_update_metrics,
initial.commit09911bf2008-07-26 23:55:29654 const DictionaryValue* profile_metrics) {
[email protected]767c9d92012-03-02 16:04:34655 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29656
[email protected]767c9d92012-03-02 16:04:34657 PrefService* pref = GetPrefService();
initial.commit09911bf2008-07-26 23:55:29658
[email protected]ffaf78a2008-11-12 17:38:33659 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29660 WriteCommonEventAttributes();
661
[email protected]147bbc0b2009-01-06 19:37:40662 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29663
[email protected]bc66d532012-03-23 01:57:05664 // Write the XML version.
665 // We'll write the protobuf version in RecordEnvironmentProto().
666 bool write_as_xml = true;
667 WritePluginList(plugin_list, write_as_xml);
initial.commit09911bf2008-07-26 23:55:29668
[email protected]fe58acc22012-02-29 01:29:58669 WriteStabilityElement(plugin_list, pref);
initial.commit09911bf2008-07-26 23:55:29670
671 {
[email protected]fe58acc22012-02-29 01:29:58672 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05673 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29674 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]0b6a4fb2012-10-16 01:58:21675 WriteAttribute("arch", base::SysInfo::OperatingSystemArchitecture());
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("memory");
[email protected]bc66d532012-03-23 01:57:05682 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38683#if defined(OS_WIN)
684 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
685#endif
initial.commit09911bf2008-07-26 23:55:29686 }
687
688 {
[email protected]fe58acc22012-02-29 01:29:58689 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05690 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29691 OPEN_ELEMENT_FOR_SCOPE("os");
[email protected]bc66d532012-03-23 01:57:05692 WriteAttribute("name", base::SysInfo::OperatingSystemName());
693 WriteAttribute("version", base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29694 }
695
696 {
[email protected]e8c287c872010-07-20 00:49:42697 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]fe58acc22012-02-29 01:29:58698 const content::GPUInfo& gpu_info =
699 GpuDataManager::GetInstance()->GetGPUInfo();
[email protected]fe58acc22012-02-29 01:29:58700
701 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05702 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]a094e2c2012-05-10 23:02:42703 WriteIntAttribute("vendorid", gpu_info.gpu.vendor_id);
704 WriteIntAttribute("deviceid", gpu_info.gpu.device_id);
[email protected]e8c287c872010-07-20 00:49:42705 }
706
707 {
[email protected]767c9d92012-03-02 16:04:34708 const gfx::Size display_size = GetScreenSize();
[email protected]fe58acc22012-02-29 01:29:58709
710 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05711 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]fe58acc22012-02-29 01:29:58712 OPEN_ELEMENT_FOR_SCOPE("display");
[email protected]bc66d532012-03-23 01:57:05713 WriteIntAttribute("xsize", display_size.width());
714 WriteIntAttribute("ysize", display_size.height());
715 WriteIntAttribute("screens", GetScreenCount());
initial.commit09911bf2008-07-26 23:55:29716 }
717
718 {
719 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
720 int num_bookmarks_on_bookmark_bar =
721 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
722 int num_folders_on_bookmark_bar =
723 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
724 int num_bookmarks_in_other_bookmarks_folder =
725 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
726 int num_folders_in_other_bookmarks_folder =
727 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
728 {
729 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
730 WriteAttribute("name", "full-tree");
731 WriteIntAttribute("foldercount",
732 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
733 WriteIntAttribute("itemcount",
734 num_bookmarks_on_bookmark_bar +
735 num_bookmarks_in_other_bookmarks_folder);
736 }
737 {
738 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
739 WriteAttribute("name", "toolbar");
740 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
741 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
742 }
743 }
744
745 {
746 OPEN_ELEMENT_FOR_SCOPE("keywords");
747 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
748 }
749
750 if (profile_metrics)
751 WriteAllProfilesMetrics(*profile_metrics);
[email protected]767c9d92012-03-02 16:04:34752
[email protected]197c0772012-05-14 23:50:51753 RecordEnvironmentProto(plugin_list, google_update_metrics);
[email protected]bc66d532012-03-23 01:57:05754}
755
756void MetricsLog::RecordEnvironmentProto(
[email protected]197c0772012-05-14 23:50:51757 const std::vector<webkit::WebPluginInfo>& plugin_list,
758 const GoogleUpdateMetrics& google_update_metrics) {
[email protected]bc66d532012-03-23 01:57:05759 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]cc5d7f42012-10-30 00:30:09760 int enabled_date;
761 bool success = base::StringToInt(GetMetricsEnabledDate(GetPrefService()),
762 &enabled_date);
[email protected]bc66d532012-03-23 01:57:05763 DCHECK(success);
[email protected]cc5d7f42012-10-30 00:30:09764 system_profile->set_uma_enabled_date(enabled_date);
[email protected]bc66d532012-03-23 01:57:05765
766 system_profile->set_application_locale(
767 content::GetContentClient()->browser()->GetApplicationLocale());
768
769 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
[email protected]0b6a4fb2012-10-16 01:58:21770 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
[email protected]bc66d532012-03-23 01:57:05771 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
772#if defined(OS_WIN)
773 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
774#endif
775
776 SystemProfileProto::OS* os = system_profile->mutable_os();
[email protected]1bb25e02012-08-03 22:39:39777 std::string os_name = base::SysInfo::OperatingSystemName();
778#if defined(OS_WIN)
779 // TODO(mad): This only checks whether the main process is a Metro process at
780 // upload time; not whether the collected metrics were all gathered from
781 // Metro. This is ok as an approximation for now, since users will rarely be
782 // switching from Metro to Desktop mode; but we should re-evaluate whether we
783 // can distinguish metrics more cleanly in the future: http://crbug.com/140568
784 if (base::win::IsMetroProcess())
785 os_name += " (Metro)";
786#endif
787 os->set_name(os_name);
[email protected]bc66d532012-03-23 01:57:05788 os->set_version(base::SysInfo::OperatingSystemVersion());
[email protected]5106b3a2012-10-03 20:10:44789#if defined(OS_ANDROID)
790 os->set_fingerprint(
791 base::android::BuildInfo::GetInstance()->android_build_fp());
792#endif
[email protected]bc66d532012-03-23 01:57:05793
794 const content::GPUInfo& gpu_info =
795 GpuDataManager::GetInstance()->GetGPUInfo();
796 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
[email protected]a094e2c2012-05-10 23:02:42797 gpu->set_vendor_id(gpu_info.gpu.vendor_id);
798 gpu->set_device_id(gpu_info.gpu.device_id);
[email protected]bc66d532012-03-23 01:57:05799 gpu->set_driver_version(gpu_info.driver_version);
800 gpu->set_driver_date(gpu_info.driver_date);
801 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
802 gpu_performance = gpu->mutable_performance_statistics();
803 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
804 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
805 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
806
807 const gfx::Size display_size = GetScreenSize();
808 hardware->set_primary_screen_width(display_size.width());
809 hardware->set_primary_screen_height(display_size.height());
[email protected]aa96417972012-08-22 03:16:44810 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor());
[email protected]bc66d532012-03-23 01:57:05811 hardware->set_screen_count(GetScreenCount());
812
[email protected]197c0772012-05-14 23:50:51813 WriteGoogleUpdateProto(google_update_metrics);
814
[email protected]bc66d532012-03-23 01:57:05815 bool write_as_xml = false;
816 WritePluginList(plugin_list, write_as_xml);
817
[email protected]ad2461c2012-04-27 21:11:03818 std::vector<SelectedGroupId> field_trial_ids;
[email protected]767c9d92012-03-02 16:04:34819 GetFieldTrialIds(&field_trial_ids);
820 WriteFieldTrials(field_trial_ids, system_profile);
initial.commit09911bf2008-07-26 23:55:29821}
822
[email protected]ed0fd002012-04-25 23:10:34823void MetricsLog::RecordProfilerData(
824 const tracked_objects::ProcessDataSnapshot& process_data,
825 content::ProcessType process_type) {
826 DCHECK(!locked());
827
[email protected]8f829682012-04-27 00:36:49828 if (tracked_objects::GetTimeSourceType() !=
829 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) {
[email protected]ed0fd002012-04-25 23:10:34830 // We currently only support the default time source, wall clock time.
831 return;
832 }
833
834 ProfilerEventProto* profile;
835 if (!uma_proto()->profiler_event_size()) {
836 // For the first process's data, add a new field to the protocol buffer.
837 profile = uma_proto()->add_profiler_event();
838 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
839 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
840 } else {
841 // For the remaining calls, re-use the existing field.
842 profile = uma_proto()->mutable_profiler_event(0);
843 }
844
845 WriteProfilerData(process_data, process_type, profile);
846}
847
initial.commit09911bf2008-07-26 23:55:29848void MetricsLog::WriteAllProfilesMetrics(
849 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51850 const std::string profile_prefix(prefs::kProfilePrefix);
initial.commit09911bf2008-07-26 23:55:29851 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
852 i != all_profiles_metrics.end_keys(); ++i) {
[email protected]e7b418b2010-07-30 19:47:47853 const std::string& key_name = *i;
initial.commit09911bf2008-07-26 23:55:29854 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
[email protected]a61890e2012-07-27 22:27:11855 const DictionaryValue* profile;
[email protected]4dad9ad82009-11-25 20:47:52856 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
857 &profile))
initial.commit09911bf2008-07-26 23:55:29858 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
859 }
860 }
861}
862
[email protected]e7b418b2010-07-30 19:47:47863void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29864 const DictionaryValue& profile_metrics) {
865 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47866 WriteAttribute("profileidhash", profileidhash);
initial.commit09911bf2008-07-26 23:55:29867 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
868 i != profile_metrics.end_keys(); ++i) {
[email protected]a61890e2012-07-27 22:27:11869 const Value* value;
[email protected]4dad9ad82009-11-25 20:47:52870 if (profile_metrics.GetWithoutPathExpansion(*i, &value)) {
[email protected]0b6a4fb2012-10-16 01:58:21871 DCHECK_NE(*i, "id");
initial.commit09911bf2008-07-26 23:55:29872 switch (value->GetType()) {
873 case Value::TYPE_STRING: {
[email protected]5e324b72008-12-18 00:07:59874 std::string string_value;
initial.commit09911bf2008-07-26 23:55:29875 if (value->GetAsString(&string_value)) {
876 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47877 WriteAttribute("name", *i);
[email protected]5e324b72008-12-18 00:07:59878 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29879 }
880 break;
881 }
882
883 case Value::TYPE_BOOLEAN: {
884 bool bool_value;
885 if (value->GetAsBoolean(&bool_value)) {
886 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47887 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29888 WriteIntAttribute("value", bool_value ? 1 : 0);
889 }
890 break;
891 }
892
893 case Value::TYPE_INTEGER: {
894 int int_value;
895 if (value->GetAsInteger(&int_value)) {
896 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47897 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29898 WriteIntAttribute("value", int_value);
899 }
900 break;
901 }
902
903 default:
904 NOTREACHED();
905 break;
906 }
907 }
908 }
909}
910
911void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
[email protected]767c9d92012-03-02 16:04:34912 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29913
[email protected]fe58acc22012-02-29 01:29:58914 // Write the XML version.
[email protected]ffaf78a2008-11-12 17:38:33915 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29916 WriteAttribute("action", "autocomplete");
917 WriteAttribute("targetidhash", "");
918 // TODO(kochi): Properly track windows.
919 WriteIntAttribute("window", 0);
[email protected]6ebc3162011-12-19 13:44:00920 if (log.tab_id != -1) {
921 // If we know what tab the autocomplete URL was opened in, log it.
922 WriteIntAttribute("tab", static_cast<int>(log.tab_id));
923 }
initial.commit09911bf2008-07-26 23:55:29924 WriteCommonEventAttributes();
925
[email protected]65956312012-04-19 21:28:12926 std::vector<string16> terms;
927 const int num_terms =
928 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms));
[email protected]ffaf78a2008-11-12 17:38:33929 {
930 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29931
[email protected]ffaf78a2008-11-12 17:38:33932 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
[email protected]65956312012-04-19 21:28:12933 WriteIntAttribute("numterms", num_terms);
[email protected]ffaf78a2008-11-12 17:38:33934 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
935 WriteIntAttribute("completedlength",
936 static_cast<int>(log.inline_autocompleted_length));
[email protected]9e349762012-01-31 03:24:36937 if (log.elapsed_time_since_user_first_modified_omnibox !=
938 base::TimeDelta::FromMilliseconds(-1)) {
939 // Only upload the typing duration if it is set/valid.
940 WriteInt64Attribute("typingduration",
941 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
942 }
[email protected]381e2992008-12-16 01:41:00943 const std::string input_type(
944 AutocompleteInput::TypeToString(log.input_type));
945 if (!input_type.empty())
946 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:29947
[email protected]ffaf78a2008-11-12 17:38:33948 for (AutocompleteResult::const_iterator i(log.result.begin());
949 i != log.result.end(); ++i) {
950 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
951 if (i->provider)
[email protected]35f1f4f02012-09-11 13:17:00952 WriteAttribute("provider", i->provider->GetName());
[email protected]381e2992008-12-16 01:41:00953 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
954 if (!result_type.empty())
955 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:33956 WriteIntAttribute("relevance", i->relevance);
957 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
958 }
initial.commit09911bf2008-07-26 23:55:29959 }
initial.commit09911bf2008-07-26 23:55:29960
[email protected]fe58acc22012-02-29 01:29:58961 // Write the protobuf version.
[email protected]767c9d92012-03-02 16:04:34962 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
[email protected]fe58acc22012-02-29 01:29:58963 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
964 if (log.tab_id != -1) {
965 // If we know what tab the autocomplete URL was opened in, log it.
966 omnibox_event->set_tab_id(log.tab_id);
967 }
968 omnibox_event->set_typed_length(log.text.length());
[email protected]660fe8f32012-05-03 20:01:08969 omnibox_event->set_just_deleted_text(log.just_deleted_text);
[email protected]65956312012-04-19 21:28:12970 omnibox_event->set_num_typed_terms(num_terms);
[email protected]fe58acc22012-02-29 01:29:58971 omnibox_event->set_selected_index(log.selected_index);
972 omnibox_event->set_completed_length(log.inline_autocompleted_length);
[email protected]65956312012-04-19 21:28:12973 if (log.elapsed_time_since_user_first_modified_omnibox !=
974 base::TimeDelta::FromMilliseconds(-1)) {
975 // Only upload the typing duration if it is set/valid.
976 omnibox_event->set_typing_duration_ms(
977 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
978 }
[email protected]ee902532012-05-01 23:54:49979 omnibox_event->set_current_page_classification(
980 log.current_page_classification);
[email protected]fe58acc22012-02-29 01:29:58981 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
982 for (AutocompleteResult::const_iterator i(log.result.begin());
983 i != log.result.end(); ++i) {
984 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
[email protected]0e9e8782012-05-15 23:01:51985 suggestion->set_provider(i->provider->AsOmniboxEventProviderType());
[email protected]fe58acc22012-02-29 01:29:58986 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
987 suggestion->set_relevance(i->relevance);
[email protected]cf6256f2012-06-12 23:36:01988 if (i->typed_count != -1)
989 suggestion->set_typed_count(i->typed_count);
[email protected]fe58acc22012-02-29 01:29:58990 suggestion->set_is_starred(i->starred);
991 }
[email protected]0e9e8782012-05-15 23:01:51992 for (ProvidersInfo::const_iterator i(log.providers_info.begin());
993 i != log.providers_info.end(); ++i) {
994 OmniboxEventProto::ProviderInfo* provider_info =
995 omnibox_event->add_provider_info();
996 provider_info->CopyFrom(*i);
997 }
[email protected]fe58acc22012-02-29 01:29:58998
initial.commit09911bf2008-07-26 23:55:29999 ++num_events_;
1000}
[email protected]197c0772012-05-14 23:50:511001
1002void MetricsLog::WriteGoogleUpdateProto(
1003 const GoogleUpdateMetrics& google_update_metrics) {
1004#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
1005 SystemProfileProto::GoogleUpdate* google_update =
1006 uma_proto()->mutable_system_profile()->mutable_google_update();
1007
1008 google_update->set_is_system_install(google_update_metrics.is_system_install);
1009
1010 if (!google_update_metrics.last_started_au.is_null()) {
1011 google_update->set_last_automatic_start_timestamp(
1012 google_update_metrics.last_started_au.ToTimeT());
1013 }
1014
1015 if (!google_update_metrics.last_checked.is_null()) {
1016 google_update->set_last_update_check_timestamp(
1017 google_update_metrics.last_checked.ToTimeT());
1018 }
1019
1020 if (!google_update_metrics.google_update_data.version.empty()) {
1021 ProductDataToProto(google_update_metrics.google_update_data,
1022 google_update->mutable_google_update_status());
1023 }
1024
1025 if (!google_update_metrics.product_data.version.empty()) {
1026 ProductDataToProto(google_update_metrics.product_data,
1027 google_update->mutable_client_status());
1028 }
1029#endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
1030}