blob: 141dac880752d8fd2c39ebbbf6495f522a46e1b6 [file] [log] [blame]
[email protected]1df44b72012-01-19 05:20:341// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]cd1adc22009-01-16 01:29:225#include "chrome/browser/metrics/metrics_log.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]76869ff2013-01-15 16:13:477#include <algorithm>
[email protected]1eeb5e02010-07-20 23:02:118#include <string>
9#include <vector>
10
[email protected]d1be67b2008-11-19 20:28:3811#include "base/basictypes.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/file_util.h"
[email protected]054c8012011-11-16 00:12:4213#include "base/lazy_instance.h"
[email protected]3b63f8f42011-03-28 01:54:1514#include "base/memory/scoped_ptr.h"
[email protected]85ed9d42010-06-08 22:37:4415#include "base/perftimer.h"
[email protected]3853a4c2013-02-11 17:15:5716#include "base/prefs/pref_registry_simple.h"
17#include "base/prefs/pref_service.h"
[email protected]ed0fd002012-04-25 23:10:3418#include "base/profiler/alternate_timer.h"
initial.commit09911bf2008-07-26 23:55:2919#include "base/string_util.h"
[email protected]3ea1b182013-02-08 22:38:4120#include "base/strings/string_number_conversions.h"
[email protected]fadf97f2008-09-18 12:18:1421#include "base/sys_info.h"
[email protected]37f39e42010-01-06 17:35:1722#include "base/third_party/nspr/prtime.h"
[email protected]1eeb5e02010-07-20 23:02:1123#include "base/time.h"
[email protected]ed0fd002012-04-25 23:10:3424#include "base/tracked_objects.h"
[email protected]1eeb5e02010-07-20 23:02:1125#include "base/utf_string_conversions.h"
[email protected]9f8bc2f2012-07-03 16:26:5326#include "chrome/browser/autocomplete/autocomplete_input.h"
[email protected]19871a92012-06-27 19:50:3227#include "chrome/browser/autocomplete/autocomplete_log.h"
[email protected]9ac40092010-10-27 23:05:2628#include "chrome/browser/autocomplete/autocomplete_match.h"
[email protected]30f5bc92012-06-26 04:14:5529#include "chrome/browser/autocomplete/autocomplete_provider.h"
[email protected]73c2b1632012-07-02 22:51:3830#include "chrome/browser/autocomplete/autocomplete_result.h"
initial.commit09911bf2008-07-26 23:55:2931#include "chrome/browser/browser_process.h"
[email protected]24b9bb392013-01-29 20:29:2932#include "chrome/browser/google/google_util.h"
[email protected]0f5e57f52012-09-20 20:53:1833#include "chrome/browser/plugins/plugin_prefs.h"
[email protected]10084982011-08-19 17:56:5634#include "chrome/browser/profiles/profile_manager.h"
[email protected]f3b357692013-03-22 05:16:1335#include "chrome/common/chrome_process_type.h"
[email protected]1eeb5e02010-07-20 23:02:1136#include "chrome/common/chrome_version_info.h"
initial.commit09911bf2008-07-26 23:55:2937#include "chrome/common/logging_chrome.h"
[email protected]fe58acc22012-02-29 01:29:5838#include "chrome/common/metrics/proto/omnibox_event.pb.h"
[email protected]ed0fd002012-04-25 23:10:3439#include "chrome/common/metrics/proto/profiler_event.pb.h"
[email protected]fe58acc22012-02-29 01:29:5840#include "chrome/common/metrics/proto/system_profile.pb.h"
[email protected]cf265dc02012-08-15 01:01:1641#include "chrome/common/metrics/variations/variations_util.h"
initial.commit09911bf2008-07-26 23:55:2942#include "chrome/common/pref_names.h"
[email protected]197c0772012-05-14 23:50:5143#include "chrome/installer/util/google_update_settings.h"
[email protected]fe58acc22012-02-29 01:29:5844#include "content/public/browser/content_browser_client.h"
[email protected]79078df2012-02-16 01:22:3245#include "content/public/browser/gpu_data_manager.h"
[email protected]1a838cc2012-04-24 22:06:4946#include "content/public/common/content_client.h"
[email protected]ed0fd002012-04-25 23:10:3447#include "content/public/common/gpu_info.h"
[email protected]46072d42008-07-28 14:49:3548#include "googleurl/src/gurl.h"
[email protected]6b7d954ff2011-10-25 00:39:3549#include "ui/gfx/screen.h"
[email protected]91d9f3d2011-08-14 05:24:4450#include "webkit/plugins/webplugininfo.h"
initial.commit09911bf2008-07-26 23:55:2951
[email protected]5106b3a2012-10-03 20:10:4452#if defined(OS_ANDROID)
53#include "base/android/build_info.h"
54#endif
55
initial.commit09911bf2008-07-26 23:55:2956#define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
57
[email protected]d1be67b2008-11-19 20:28:3858#if defined(OS_WIN)
[email protected]1bb25e02012-08-03 22:39:3959#include "base/win/metro.h"
60
61// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
[email protected]d1be67b2008-11-19 20:28:3862extern "C" IMAGE_DOS_HEADER __ImageBase;
63#endif
64
[email protected]79078df2012-02-16 01:22:3265using content::GpuDataManager;
[email protected]fe58acc22012-02-29 01:29:5866using metrics::OmniboxEventProto;
[email protected]f65859e2013-02-04 20:00:2567using metrics::PerfDataProto;
[email protected]ed0fd002012-04-25 23:10:3468using metrics::ProfilerEventProto;
[email protected]fe58acc22012-02-29 01:29:5869using metrics::SystemProfileProto;
[email protected]ed0fd002012-04-25 23:10:3470using tracked_objects::ProcessDataSnapshot;
[email protected]0c8b7ad2012-11-06 07:08:1471typedef chrome_variations::ActiveGroupId ActiveGroupId;
[email protected]197c0772012-05-14 23:50:5172typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo;
[email protected]79078df2012-02-16 01:22:3273
[email protected]1df44b72012-01-19 05:20:3474namespace {
75
76// Returns the date at which the current metrics client ID was created as
[email protected]ca5ac4b2012-12-14 07:46:4077// a string containing seconds since the epoch, or "0" if none was found.
[email protected]cc5d7f42012-10-30 00:30:0978std::string GetMetricsEnabledDate(PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:3479 if (!pref) {
[email protected]1df44b72012-01-19 05:20:3480 NOTREACHED();
81 return "0";
82 }
[email protected]767c9d92012-03-02 16:04:3483
84 return pref->GetString(prefs::kMetricsClientIDTimestamp);
[email protected]1df44b72012-01-19 05:20:3485}
86
[email protected]fe58acc22012-02-29 01:29:5887OmniboxEventProto::InputType AsOmniboxEventInputType(
88 AutocompleteInput::Type type) {
89 switch (type) {
90 case AutocompleteInput::INVALID:
91 return OmniboxEventProto::INVALID;
92 case AutocompleteInput::UNKNOWN:
93 return OmniboxEventProto::UNKNOWN;
[email protected]fe58acc22012-02-29 01:29:5894 case AutocompleteInput::URL:
95 return OmniboxEventProto::URL;
96 case AutocompleteInput::QUERY:
97 return OmniboxEventProto::QUERY;
98 case AutocompleteInput::FORCED_QUERY:
99 return OmniboxEventProto::FORCED_QUERY;
100 default:
101 NOTREACHED();
102 return OmniboxEventProto::INVALID;
103 }
104}
105
[email protected]fe58acc22012-02-29 01:29:58106OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
107 AutocompleteMatch::Type type) {
108 switch (type) {
109 case AutocompleteMatch::URL_WHAT_YOU_TYPED:
110 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
111 case AutocompleteMatch::HISTORY_URL:
112 return OmniboxEventProto::Suggestion::HISTORY_URL;
113 case AutocompleteMatch::HISTORY_TITLE:
114 return OmniboxEventProto::Suggestion::HISTORY_TITLE;
115 case AutocompleteMatch::HISTORY_BODY:
116 return OmniboxEventProto::Suggestion::HISTORY_BODY;
117 case AutocompleteMatch::HISTORY_KEYWORD:
118 return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
119 case AutocompleteMatch::NAVSUGGEST:
120 return OmniboxEventProto::Suggestion::NAVSUGGEST;
121 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
122 return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
123 case AutocompleteMatch::SEARCH_HISTORY:
124 return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
125 case AutocompleteMatch::SEARCH_SUGGEST:
126 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
127 case AutocompleteMatch::SEARCH_OTHER_ENGINE:
128 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
129 case AutocompleteMatch::EXTENSION_APP:
130 return OmniboxEventProto::Suggestion::EXTENSION_APP;
[email protected]dbacefb2012-09-12 03:32:06131 case AutocompleteMatch::CONTACT:
132 return OmniboxEventProto::Suggestion::CONTACT;
[email protected]25320602012-10-18 22:05:56133 case AutocompleteMatch::BOOKMARK_TITLE:
134 return OmniboxEventProto::Suggestion::BOOKMARK_TITLE;
[email protected]fe58acc22012-02-29 01:29:58135 default:
136 NOTREACHED();
137 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
138 }
139}
140
[email protected]ed0fd002012-04-25 23:10:34141ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType(
[email protected]f3b357692013-03-22 05:16:13142 int process_type) {
[email protected]ed0fd002012-04-25 23:10:34143 switch (process_type) {
144 case content::PROCESS_TYPE_BROWSER:
145 return ProfilerEventProto::TrackedObject::BROWSER;
146 case content::PROCESS_TYPE_RENDERER:
147 return ProfilerEventProto::TrackedObject::RENDERER;
148 case content::PROCESS_TYPE_PLUGIN:
149 return ProfilerEventProto::TrackedObject::PLUGIN;
150 case content::PROCESS_TYPE_WORKER:
151 return ProfilerEventProto::TrackedObject::WORKER;
[email protected]ed0fd002012-04-25 23:10:34152 case content::PROCESS_TYPE_UTILITY:
153 return ProfilerEventProto::TrackedObject::UTILITY;
[email protected]ed0fd002012-04-25 23:10:34154 case content::PROCESS_TYPE_ZYGOTE:
155 return ProfilerEventProto::TrackedObject::ZYGOTE;
156 case content::PROCESS_TYPE_SANDBOX_HELPER:
157 return ProfilerEventProto::TrackedObject::SANDBOX_HELPER;
[email protected]ed0fd002012-04-25 23:10:34158 case content::PROCESS_TYPE_GPU:
159 return ProfilerEventProto::TrackedObject::GPU;
160 case content::PROCESS_TYPE_PPAPI_PLUGIN:
161 return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN;
162 case content::PROCESS_TYPE_PPAPI_BROKER:
163 return ProfilerEventProto::TrackedObject::PPAPI_BROKER;
[email protected]f3b357692013-03-22 05:16:13164 case PROCESS_TYPE_PROFILE_IMPORT:
165 return ProfilerEventProto::TrackedObject::PROFILE_IMPORT;
166 case PROCESS_TYPE_NACL_LOADER:
167 return ProfilerEventProto::TrackedObject::NACL_LOADER;
168 case PROCESS_TYPE_NACL_BROKER:
169 return ProfilerEventProto::TrackedObject::NACL_BROKER;
[email protected]ed0fd002012-04-25 23:10:34170 default:
171 NOTREACHED();
172 return ProfilerEventProto::TrackedObject::UNKNOWN;
173 }
174}
175
[email protected]1df44b72012-01-19 05:20:34176// Returns the plugin preferences corresponding for this user, if available.
177// If multiple user profiles are loaded, returns the preferences corresponding
178// to an arbitrary one of the profiles.
179PluginPrefs* GetPluginPrefs() {
180 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]fe58acc22012-02-29 01:29:58181
182 if (!profile_manager) {
183 // The profile manager can be NULL when testing.
184 return NULL;
185 }
186
[email protected]1df44b72012-01-19 05:20:34187 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
188 if (profiles.empty())
189 return NULL;
190
191 return PluginPrefs::GetForProfile(profiles.front());
192}
193
[email protected]fe58acc22012-02-29 01:29:58194// Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
195void SetPluginInfo(const webkit::WebPluginInfo& plugin_info,
196 const PluginPrefs* plugin_prefs,
197 SystemProfileProto::Plugin* plugin) {
198 plugin->set_name(UTF16ToUTF8(plugin_info.name));
199 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
200 plugin->set_version(UTF16ToUTF8(plugin_info.version));
201 if (plugin_prefs)
202 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
203}
204
[email protected]0c8b7ad2012-11-06 07:08:14205void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids,
[email protected]767c9d92012-03-02 16:04:34206 SystemProfileProto* system_profile) {
[email protected]0c8b7ad2012-11-06 07:08:14207 for (std::vector<ActiveGroupId>::const_iterator it =
[email protected]ad2461c2012-04-27 21:11:03208 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
[email protected]767c9d92012-03-02 16:04:34209 SystemProfileProto::FieldTrial* field_trial =
210 system_profile->add_field_trial();
211 field_trial->set_name_id(it->name);
212 field_trial->set_group_id(it->group);
213 }
214}
215
[email protected]ed0fd002012-04-25 23:10:34216void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
[email protected]f3b357692013-03-22 05:16:13217 int process_type,
[email protected]ed0fd002012-04-25 23:10:34218 ProfilerEventProto* performance_profile) {
219 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it =
220 profiler_data.tasks.begin();
221 it != profiler_data.tasks.end(); ++it) {
222 std::string ignored;
223 uint64 birth_thread_name_hash;
224 uint64 exec_thread_name_hash;
225 uint64 source_file_name_hash;
226 uint64 source_function_name_hash;
227 MetricsLogBase::CreateHashes(it->birth.thread_name,
228 &ignored, &birth_thread_name_hash);
229 MetricsLogBase::CreateHashes(it->death_thread_name,
230 &ignored, &exec_thread_name_hash);
[email protected]ed0fd002012-04-25 23:10:34231 MetricsLogBase::CreateHashes(it->birth.location.file_name,
[email protected]04162262012-10-23 01:17:25232 &ignored, &source_file_name_hash);
233 MetricsLogBase::CreateHashes(it->birth.location.function_name,
[email protected]ed0fd002012-04-25 23:10:34234 &ignored, &source_function_name_hash);
235
236 const tracked_objects::DeathDataSnapshot& death_data = it->death_data;
237 ProfilerEventProto::TrackedObject* tracked_object =
238 performance_profile->add_tracked_object();
239 tracked_object->set_birth_thread_name_hash(birth_thread_name_hash);
240 tracked_object->set_exec_thread_name_hash(exec_thread_name_hash);
241 tracked_object->set_source_file_name_hash(source_file_name_hash);
242 tracked_object->set_source_function_name_hash(source_function_name_hash);
243 tracked_object->set_source_line_number(it->birth.location.line_number);
244 tracked_object->set_exec_count(death_data.count);
245 tracked_object->set_exec_time_total(death_data.run_duration_sum);
246 tracked_object->set_exec_time_sampled(death_data.run_duration_sample);
247 tracked_object->set_queue_time_total(death_data.queue_duration_sum);
248 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample);
249 tracked_object->set_process_type(AsProtobufProcessType(process_type));
250 tracked_object->set_process_id(profiler_data.process_id);
251 }
252}
253
[email protected]59a7ae4e2012-10-01 23:54:44254#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
[email protected]197c0772012-05-14 23:50:51255void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data,
256 ProductInfo* product_info) {
257 product_info->set_version(product_data.version);
258 product_info->set_last_update_success_timestamp(
259 product_data.last_success.ToTimeT());
260 product_info->set_last_error(product_data.last_error_code);
261 product_info->set_last_extra_error(product_data.last_extra_code);
262 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) {
263 product_info->set_last_result(
264 static_cast<ProductInfo::InstallResult>(product_data.last_result));
265 }
266}
[email protected]59a7ae4e2012-10-01 23:54:44267#endif
[email protected]197c0772012-05-14 23:50:51268
[email protected]76869ff2013-01-15 16:13:47269#if defined(OS_WIN)
270struct ScreenDPIInformation{
271 double max_dpi_x;
272 double max_dpi_y;
273};
274
275// Called once for each connected monitor.
276BOOL CALLBACK GetMonitorDPICallback(HMONITOR, HDC hdc, LPRECT, LPARAM dwData) {
277 const double kMillimetersPerInch = 25.4;
278 ScreenDPIInformation* screen_info =
279 reinterpret_cast<ScreenDPIInformation*>(dwData);
280 // Size of screen, in mm.
281 DWORD size_x = GetDeviceCaps(hdc, HORZSIZE);
282 DWORD size_y = GetDeviceCaps(hdc, VERTSIZE);
283 double dpi_x = (size_x > 0) ?
284 GetDeviceCaps(hdc, HORZRES) / (size_x / kMillimetersPerInch) : 0;
285 double dpi_y = (size_y > 0) ?
286 GetDeviceCaps(hdc, VERTRES) / (size_y / kMillimetersPerInch) : 0;
287 screen_info->max_dpi_x = std::max(dpi_x, screen_info->max_dpi_x);
288 screen_info->max_dpi_y = std::max(dpi_y, screen_info->max_dpi_y);
289 return TRUE;
290}
291
292void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) {
293 HDC desktop_dc = GetDC(NULL);
294 if (desktop_dc) {
295 ScreenDPIInformation si = {0,0};
296 if (EnumDisplayMonitors(desktop_dc, NULL, GetMonitorDPICallback,
297 reinterpret_cast<LPARAM>(&si))) {
298 hardware->set_max_dpi_x(si.max_dpi_x);
299 hardware->set_max_dpi_y(si.max_dpi_y);
300 }
301 ReleaseDC(GetDesktopWindow(), desktop_dc);
302 }
303}
304
305#endif // defined(OS_WIN)
306
[email protected]1df44b72012-01-19 05:20:34307} // namespace
308
[email protected]197c0772012-05-14 23:50:51309GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {}
310
311GoogleUpdateMetrics::~GoogleUpdateMetrics() {}
312
[email protected]67f92bc32012-01-26 01:56:19313static base::LazyInstance<std::string>::Leaky
[email protected]054c8012011-11-16 00:12:42314 g_version_extension = LAZY_INSTANCE_INITIALIZER;
315
[email protected]1226abb2010-06-10 18:01:28316MetricsLog::MetricsLog(const std::string& client_id, int session_id)
[email protected]5eae204c2013-02-13 15:53:42317 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:41318
[email protected]1226abb2010-06-10 18:01:28319MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:29320
321// static
[email protected]b1de2c72013-02-06 02:45:47322void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) {
323 registry->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29324}
325
[email protected]1df44b72012-01-19 05:20:34326// static
[email protected]9165f742010-03-10 22:55:01327int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
328 base::TimeTicks now = base::TimeTicks::Now();
329 static base::TimeTicks last_updated_time(now);
330 int64 incremental_time = (now - last_updated_time).InSeconds();
331 last_updated_time = now;
332
333 if (incremental_time > 0) {
334 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
335 metrics_uptime += incremental_time;
336 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
337 }
338
339 return incremental_time;
340}
341
[email protected]1226abb2010-06-10 18:01:28342// static
343std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:42344 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:17345 if (!version_info.is_valid()) {
346 NOTREACHED() << "Unable to retrieve version info.";
347 return std::string();
348 }
349
[email protected]0211f57e2010-08-27 20:28:42350 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:42351 if (!version_extension().empty())
352 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:42353 if (!version_info.IsOfficialBuild())
354 version.append("-devel");
355 return version;
[email protected]1226abb2010-06-10 18:01:28356}
357
[email protected]054c8012011-11-16 00:12:42358// static
359void MetricsLog::set_version_extension(const std::string& extension) {
360 g_version_extension.Get() = extension;
361}
362
363// static
364const std::string& MetricsLog::version_extension() {
365 return g_version_extension.Get();
366}
367
[email protected]fe58acc22012-02-29 01:29:58368void MetricsLog::RecordIncrementalStabilityElements(
369 const std::vector<webkit::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34370 DCHECK(!locked());
[email protected]0b33f80b2008-12-17 21:34:36371
[email protected]767c9d92012-03-02 16:04:34372 PrefService* pref = GetPrefService();
[email protected]0b33f80b2008-12-17 21:34:36373 DCHECK(pref);
374
[email protected]147bbc0b2009-01-06 19:37:40375 OPEN_ELEMENT_FOR_SCOPE("profile");
376 WriteCommonEventAttributes();
377
[email protected]9958a322011-03-08 20:04:17378 WriteInstallElement();
[email protected]147bbc0b2009-01-06 19:37:40379
380 {
381 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
382 WriteRequiredStabilityAttributes(pref);
383 WriteRealtimeStabilityAttributes(pref);
[email protected]fe58acc22012-02-29 01:29:58384 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40385 }
[email protected]0b33f80b2008-12-17 21:34:36386}
387
[email protected]767c9d92012-03-02 16:04:34388PrefService* MetricsLog::GetPrefService() {
389 return g_browser_process->local_state();
390}
391
392gfx::Size MetricsLog::GetScreenSize() const {
[email protected]ffabb1e2012-10-12 19:51:17393 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel();
[email protected]767c9d92012-03-02 16:04:34394}
395
[email protected]aa96417972012-08-22 03:16:44396float MetricsLog::GetScreenDeviceScaleFactor() const {
[email protected]ffabb1e2012-10-12 19:51:17397 return gfx::Screen::GetNativeScreen()->
398 GetPrimaryDisplay().device_scale_factor();
[email protected]aa96417972012-08-22 03:16:44399}
400
[email protected]767c9d92012-03-02 16:04:34401int MetricsLog::GetScreenCount() const {
[email protected]ffabb1e2012-10-12 19:51:17402 // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312
403 return gfx::Screen::GetNativeScreen()->GetNumDisplays();
[email protected]767c9d92012-03-02 16:04:34404}
405
[email protected]767c9d92012-03-02 16:04:34406void MetricsLog::GetFieldTrialIds(
[email protected]0c8b7ad2012-11-06 07:08:14407 std::vector<ActiveGroupId>* field_trial_ids) const {
408 chrome_variations::GetFieldTrialActiveGroupIds(field_trial_ids);
[email protected]767c9d92012-03-02 16:04:34409}
410
[email protected]fe58acc22012-02-29 01:29:58411void MetricsLog::WriteStabilityElement(
412 const std::vector<webkit::WebPluginInfo>& plugin_list,
413 PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:34414 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29415
initial.commit09911bf2008-07-26 23:55:29416 // Get stability attributes out of Local State, zeroing out stored values.
417 // NOTE: This could lead to some data loss if this report isn't successfully
418 // sent, but that's true for all the metrics.
419
[email protected]ffaf78a2008-11-12 17:38:33420 OPEN_ELEMENT_FOR_SCOPE("stability");
[email protected]147bbc0b2009-01-06 19:37:40421 WriteRequiredStabilityAttributes(pref);
422 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29423
[email protected]fe58acc22012-02-29 01:29:58424 int incomplete_shutdown_count =
425 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
[email protected]e324f6b2012-02-28 05:43:37426 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58427 int breakpad_registration_success_count =
428 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
[email protected]e324f6b2012-02-28 05:43:37429 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58430 int breakpad_registration_failure_count =
431 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
[email protected]e324f6b2012-02-28 05:43:37432 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58433 int debugger_present_count =
434 pref->GetInteger(prefs::kStabilityDebuggerPresent);
[email protected]e324f6b2012-02-28 05:43:37435 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58436 int debugger_not_present_count =
437 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
[email protected]e324f6b2012-02-28 05:43:37438 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31439
[email protected]fe58acc22012-02-29 01:29:58440 // TODO(jar): The following are all optional, so we *could* optimize them for
441 // values of zero (and not include them).
442
443 // Write the XML version.
444 WriteIntAttribute("incompleteshutdowncount", incomplete_shutdown_count);
445 WriteIntAttribute("breakpadregistrationok",
446 breakpad_registration_success_count);
447 WriteIntAttribute("breakpadregistrationfail",
448 breakpad_registration_failure_count);
449 WriteIntAttribute("debuggerpresent", debugger_present_count);
450 WriteIntAttribute("debuggernotpresent", debugger_not_present_count);
451
452 // Write the protobuf version.
453 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34454 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58455 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
456 stability->set_breakpad_registration_success_count(
457 breakpad_registration_success_count);
458 stability->set_breakpad_registration_failure_count(
459 breakpad_registration_failure_count);
460 stability->set_debugger_present_count(debugger_present_count);
461 stability->set_debugger_not_present_count(debugger_not_present_count);
462
463 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40464}
465
[email protected]fe58acc22012-02-29 01:29:58466void MetricsLog::WritePluginStabilityElements(
467 const std::vector<webkit::WebPluginInfo>& plugin_list,
468 PrefService* pref) {
[email protected]147bbc0b2009-01-06 19:37:40469 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29470 const ListValue* plugin_stats_list = pref->GetList(
471 prefs::kStabilityPluginStats);
[email protected]1df44b72012-01-19 05:20:34472 if (!plugin_stats_list)
473 return;
initial.commit09911bf2008-07-26 23:55:29474
[email protected]1df44b72012-01-19 05:20:34475 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]ebd71962012-12-20 02:56:55476
477#if defined(ENABLE_PLUGINS)
[email protected]fe58acc22012-02-29 01:29:58478 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34479 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58480 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]1df44b72012-01-19 05:20:34481 for (ListValue::const_iterator iter = plugin_stats_list->begin();
482 iter != plugin_stats_list->end(); ++iter) {
483 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
484 NOTREACHED();
485 continue;
initial.commit09911bf2008-07-26 23:55:29486 }
[email protected]1df44b72012-01-19 05:20:34487 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29488
[email protected]1df44b72012-01-19 05:20:34489 std::string plugin_name;
490 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
491
[email protected]fe58acc22012-02-29 01:29:58492 std::string base64_name_hash;
493 uint64 numeric_name_hash_ignored;
494 CreateHashes(plugin_name, &base64_name_hash, &numeric_name_hash_ignored);
495
496 // Write the XML verison.
[email protected]1df44b72012-01-19 05:20:34497 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
498 // Use "filename" instead of "name", otherwise we need to update the
499 // UMA servers.
[email protected]fe58acc22012-02-29 01:29:58500 WriteAttribute("filename", base64_name_hash);
[email protected]1df44b72012-01-19 05:20:34501
502 int launches = 0;
503 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
504 WriteIntAttribute("launchcount", launches);
505
506 int instances = 0;
507 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
508 WriteIntAttribute("instancecount", instances);
509
510 int crashes = 0;
511 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
512 WriteIntAttribute("crashcount", crashes);
[email protected]fe58acc22012-02-29 01:29:58513
514 // Write the protobuf version.
515 // Note that this search is potentially a quadratic operation, but given the
516 // low number of plugins installed on a "reasonable" setup, this should be
517 // fine.
518 // TODO(isherman): Verify that this does not show up as a hotspot in
519 // profiler runs.
520 const webkit::WebPluginInfo* plugin_info = NULL;
521 const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name);
522 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
523 plugin_list.begin();
524 iter != plugin_list.end(); ++iter) {
525 if (iter->name == plugin_name_utf16) {
526 plugin_info = &(*iter);
527 break;
528 }
529 }
530
531 if (!plugin_info) {
532 NOTREACHED();
533 continue;
534 }
[email protected]cd937072012-07-02 09:00:29535 int loading_errors = 0;
536 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors,
537 &loading_errors);
538 WriteIntAttribute("loadingerrorcount", loading_errors);
[email protected]fe58acc22012-02-29 01:29:58539
[email protected]cd937072012-07-02 09:00:29540 // Write the protobuf version.
[email protected]fe58acc22012-02-29 01:29:58541 SystemProfileProto::Stability::PluginStability* plugin_stability =
542 stability->add_plugin_stability();
543 SetPluginInfo(*plugin_info, plugin_prefs,
544 plugin_stability->mutable_plugin());
545 plugin_stability->set_launch_count(launches);
546 plugin_stability->set_instance_count(instances);
547 plugin_stability->set_crash_count(crashes);
[email protected]cd937072012-07-02 09:00:29548 plugin_stability->set_loading_error_count(loading_errors);
initial.commit09911bf2008-07-26 23:55:29549 }
[email protected]ebd71962012-12-20 02:56:55550#endif // defined(ENABLE_PLUGINS)
[email protected]1df44b72012-01-19 05:20:34551
552 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29553}
554
[email protected]fe58acc22012-02-29 01:29:58555// The server refuses data that doesn't have certain values. crashcount and
556// launchcount are currently "required" in the "stability" group.
557// TODO(isherman): Stop writing these attributes specially once the migration to
558// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40559void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]fe58acc22012-02-29 01:29:58560 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
[email protected]0b33f80b2008-12-17 21:34:36561 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
[email protected]fe58acc22012-02-29 01:29:58562 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
[email protected]0b33f80b2008-12-17 21:34:36563 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58564
565 // Write the XML version.
566 WriteIntAttribute("launchcount", launch_count);
567 WriteIntAttribute("crashcount", crash_count);
568
569 // Write the protobuf version.
570 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34571 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58572 stability->set_launch_count(launch_count);
573 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36574}
575
[email protected]147bbc0b2009-01-06 19:37:40576void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36577 // Update the stats which are critical for real-time stability monitoring.
578 // Since these are "optional," only list ones that are non-zero, as the counts
579 // are aggergated (summed) server side.
580
[email protected]fe58acc22012-02-29 01:29:58581 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34582 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36583 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
584 if (count) {
585 WriteIntAttribute("pageloadcount", count);
[email protected]fe58acc22012-02-29 01:29:58586 stability->set_page_load_count(count);
[email protected]0b33f80b2008-12-17 21:34:36587 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
588 }
589
590 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
591 if (count) {
592 WriteIntAttribute("renderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58593 stability->set_renderer_crash_count(count);
[email protected]0b33f80b2008-12-17 21:34:36594 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
595 }
596
[email protected]1f085622009-12-04 05:33:45597 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
598 if (count) {
599 WriteIntAttribute("extensionrenderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58600 stability->set_extension_renderer_crash_count(count);
[email protected]1f085622009-12-04 05:33:45601 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
602 }
603
[email protected]0b33f80b2008-12-17 21:34:36604 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
605 if (count) {
606 WriteIntAttribute("rendererhangcount", count);
[email protected]fe58acc22012-02-29 01:29:58607 stability->set_renderer_hang_count(count);
[email protected]0b33f80b2008-12-17 21:34:36608 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
609 }
[email protected]1f085622009-12-04 05:33:45610
611 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
612 if (count) {
613 WriteIntAttribute("childprocesscrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58614 stability->set_child_process_crash_count(count);
[email protected]1f085622009-12-04 05:33:45615 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
616 }
[email protected]9165f742010-03-10 22:55:01617
[email protected]c1834a92011-01-21 18:21:03618#if defined(OS_CHROMEOS)
619 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
620 if (count) {
[email protected]fe58acc22012-02-29 01:29:58621 stability->set_other_user_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03622 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
623 }
624
625 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
626 if (count) {
[email protected]fe58acc22012-02-29 01:29:58627 stability->set_kernel_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03628 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
629 }
630
631 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
632 if (count) {
[email protected]fe58acc22012-02-29 01:29:58633 stability->set_unclean_system_shutdown_count(count);
[email protected]c1834a92011-01-21 18:21:03634 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
635 }
636#endif // OS_CHROMEOS
637
[email protected]9165f742010-03-10 22:55:01638 int64 recent_duration = GetIncrementalUptime(pref);
[email protected]fe58acc22012-02-29 01:29:58639 if (recent_duration) {
[email protected]9165f742010-03-10 22:55:01640 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]fe58acc22012-02-29 01:29:58641 stability->set_uptime_sec(recent_duration);
642 }
[email protected]0b33f80b2008-12-17 21:34:36643}
644
initial.commit09911bf2008-07-26 23:55:29645void MetricsLog::WritePluginList(
[email protected]bc66d532012-03-23 01:57:05646 const std::vector<webkit::WebPluginInfo>& plugin_list,
647 bool write_as_xml) {
[email protected]767c9d92012-03-02 16:04:34648 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29649
[email protected]ffaf78a2008-11-12 17:38:33650 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]ebd71962012-12-20 02:56:55651
652#if defined(ENABLE_PLUGINS)
653 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]767c9d92012-03-02 16:04:34654 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]91d9f3d2011-08-14 05:24:44655 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50656 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29657 iter != plugin_list.end(); ++iter) {
[email protected]bc66d532012-03-23 01:57:05658 if (write_as_xml) {
659 std::string base64_name_hash;
660 uint64 numeric_hash_ignored;
661 CreateHashes(UTF16ToUTF8(iter->name), &base64_name_hash,
662 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58663
[email protected]bc66d532012-03-23 01:57:05664 std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe();
665 std::string base64_filename_hash;
666 CreateHashes(filename_bytes, &base64_filename_hash,
667 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58668
[email protected]bc66d532012-03-23 01:57:05669 // Write the XML version.
670 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29671
[email protected]bc66d532012-03-23 01:57:05672 // Plugin name and filename are hashed for the privacy of those
673 // testing unreleased new extensions.
674 WriteAttribute("name", base64_name_hash);
675 WriteAttribute("filename", base64_filename_hash);
676 WriteAttribute("version", UTF16ToUTF8(iter->version));
677 if (plugin_prefs)
678 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
679 } else {
680 // Write the protobuf version.
681 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
682 SetPluginInfo(*iter, plugin_prefs, plugin);
683 }
initial.commit09911bf2008-07-26 23:55:29684 }
[email protected]ebd71962012-12-20 02:56:55685#endif // defined(ENABLE_PLUGINS)
initial.commit09911bf2008-07-26 23:55:29686}
687
[email protected]147bbc0b2009-01-06 19:37:40688void MetricsLog::WriteInstallElement() {
[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().
[email protected]147bbc0b2009-01-06 19:37:40691 OPEN_ELEMENT_FOR_SCOPE("install");
[email protected]cc5d7f42012-10-30 00:30:09692 WriteAttribute("installdate", GetMetricsEnabledDate(GetPrefService()));
[email protected]147bbc0b2009-01-06 19:37:40693 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40694}
695
initial.commit09911bf2008-07-26 23:55:29696void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44697 const std::vector<webkit::WebPluginInfo>& plugin_list,
[email protected]197c0772012-05-14 23:50:51698 const GoogleUpdateMetrics& google_update_metrics,
initial.commit09911bf2008-07-26 23:55:29699 const DictionaryValue* profile_metrics) {
[email protected]767c9d92012-03-02 16:04:34700 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29701
[email protected]767c9d92012-03-02 16:04:34702 PrefService* pref = GetPrefService();
initial.commit09911bf2008-07-26 23:55:29703
[email protected]ffaf78a2008-11-12 17:38:33704 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29705 WriteCommonEventAttributes();
706
[email protected]147bbc0b2009-01-06 19:37:40707 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29708
[email protected]bc66d532012-03-23 01:57:05709 // Write the XML version.
710 // We'll write the protobuf version in RecordEnvironmentProto().
711 bool write_as_xml = true;
712 WritePluginList(plugin_list, write_as_xml);
initial.commit09911bf2008-07-26 23:55:29713
[email protected]fe58acc22012-02-29 01:29:58714 WriteStabilityElement(plugin_list, pref);
initial.commit09911bf2008-07-26 23:55:29715
716 {
[email protected]fe58acc22012-02-29 01:29:58717 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05718 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29719 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]0b6a4fb2012-10-16 01:58:21720 WriteAttribute("arch", base::SysInfo::OperatingSystemArchitecture());
initial.commit09911bf2008-07-26 23:55:29721 }
722
723 {
[email protected]fe58acc22012-02-29 01:29:58724 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05725 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29726 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]bc66d532012-03-23 01:57:05727 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38728#if defined(OS_WIN)
729 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
730#endif
initial.commit09911bf2008-07-26 23:55:29731 }
732
733 {
[email protected]fe58acc22012-02-29 01:29:58734 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05735 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29736 OPEN_ELEMENT_FOR_SCOPE("os");
[email protected]bc66d532012-03-23 01:57:05737 WriteAttribute("name", base::SysInfo::OperatingSystemName());
738 WriteAttribute("version", base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29739 }
740
741 {
[email protected]e8c287c872010-07-20 00:49:42742 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]fe58acc22012-02-29 01:29:58743 const content::GPUInfo& gpu_info =
744 GpuDataManager::GetInstance()->GetGPUInfo();
[email protected]fe58acc22012-02-29 01:29:58745
746 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05747 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]a094e2c2012-05-10 23:02:42748 WriteIntAttribute("vendorid", gpu_info.gpu.vendor_id);
749 WriteIntAttribute("deviceid", gpu_info.gpu.device_id);
[email protected]e8c287c872010-07-20 00:49:42750 }
751
752 {
[email protected]767c9d92012-03-02 16:04:34753 const gfx::Size display_size = GetScreenSize();
[email protected]fe58acc22012-02-29 01:29:58754
755 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05756 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]fe58acc22012-02-29 01:29:58757 OPEN_ELEMENT_FOR_SCOPE("display");
[email protected]bc66d532012-03-23 01:57:05758 WriteIntAttribute("xsize", display_size.width());
759 WriteIntAttribute("ysize", display_size.height());
760 WriteIntAttribute("screens", GetScreenCount());
initial.commit09911bf2008-07-26 23:55:29761 }
762
763 {
764 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
initial.commit09911bf2008-07-26 23:55:29765 {
766 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
767 WriteAttribute("name", "full-tree");
[email protected]8542bcc2013-01-30 00:15:36768 WriteIntAttribute("foldercount", 0);
769 WriteIntAttribute("itemcount", 0);
initial.commit09911bf2008-07-26 23:55:29770 }
771 {
772 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
773 WriteAttribute("name", "toolbar");
[email protected]8542bcc2013-01-30 00:15:36774 WriteIntAttribute("foldercount", 0);
775 WriteIntAttribute("itemcount", 0);
initial.commit09911bf2008-07-26 23:55:29776 }
777 }
778
779 {
780 OPEN_ELEMENT_FOR_SCOPE("keywords");
781 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
782 }
783
784 if (profile_metrics)
785 WriteAllProfilesMetrics(*profile_metrics);
[email protected]767c9d92012-03-02 16:04:34786
[email protected]197c0772012-05-14 23:50:51787 RecordEnvironmentProto(plugin_list, google_update_metrics);
[email protected]bc66d532012-03-23 01:57:05788}
789
790void MetricsLog::RecordEnvironmentProto(
[email protected]197c0772012-05-14 23:50:51791 const std::vector<webkit::WebPluginInfo>& plugin_list,
792 const GoogleUpdateMetrics& google_update_metrics) {
[email protected]bc66d532012-03-23 01:57:05793 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]24b9bb392013-01-29 20:29:29794
795 std::string brand_code;
796 if (google_util::GetBrand(&brand_code))
797 system_profile->set_brand_code(brand_code);
798
[email protected]cc5d7f42012-10-30 00:30:09799 int enabled_date;
800 bool success = base::StringToInt(GetMetricsEnabledDate(GetPrefService()),
801 &enabled_date);
[email protected]bc66d532012-03-23 01:57:05802 DCHECK(success);
[email protected]cc5d7f42012-10-30 00:30:09803 system_profile->set_uma_enabled_date(enabled_date);
[email protected]bc66d532012-03-23 01:57:05804
805 system_profile->set_application_locale(
806 content::GetContentClient()->browser()->GetApplicationLocale());
807
808 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
[email protected]0b6a4fb2012-10-16 01:58:21809 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
[email protected]bc66d532012-03-23 01:57:05810 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
811#if defined(OS_WIN)
812 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
813#endif
814
[email protected]74b299e2013-01-29 01:24:42815 SystemProfileProto::Network* network = system_profile->mutable_network();
816 network->set_connection_type_is_ambiguous(
[email protected]5eae204c2013-02-13 15:53:42817 network_observer_.connection_type_is_ambiguous());
818 network->set_connection_type(network_observer_.connection_type());
819 network->set_wifi_phy_layer_protocol_is_ambiguous(
820 network_observer_.wifi_phy_layer_protocol_is_ambiguous());
821 network->set_wifi_phy_layer_protocol(
822 network_observer_.wifi_phy_layer_protocol());
823 network_observer_.Reset();
[email protected]74b299e2013-01-29 01:24:42824
[email protected]bc66d532012-03-23 01:57:05825 SystemProfileProto::OS* os = system_profile->mutable_os();
[email protected]1bb25e02012-08-03 22:39:39826 std::string os_name = base::SysInfo::OperatingSystemName();
827#if defined(OS_WIN)
828 // TODO(mad): This only checks whether the main process is a Metro process at
829 // upload time; not whether the collected metrics were all gathered from
830 // Metro. This is ok as an approximation for now, since users will rarely be
831 // switching from Metro to Desktop mode; but we should re-evaluate whether we
832 // can distinguish metrics more cleanly in the future: http://crbug.com/140568
833 if (base::win::IsMetroProcess())
834 os_name += " (Metro)";
835#endif
836 os->set_name(os_name);
[email protected]bc66d532012-03-23 01:57:05837 os->set_version(base::SysInfo::OperatingSystemVersion());
[email protected]5106b3a2012-10-03 20:10:44838#if defined(OS_ANDROID)
839 os->set_fingerprint(
840 base::android::BuildInfo::GetInstance()->android_build_fp());
841#endif
[email protected]bc66d532012-03-23 01:57:05842
843 const content::GPUInfo& gpu_info =
844 GpuDataManager::GetInstance()->GetGPUInfo();
845 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
[email protected]a094e2c2012-05-10 23:02:42846 gpu->set_vendor_id(gpu_info.gpu.vendor_id);
847 gpu->set_device_id(gpu_info.gpu.device_id);
[email protected]bc66d532012-03-23 01:57:05848 gpu->set_driver_version(gpu_info.driver_version);
849 gpu->set_driver_date(gpu_info.driver_date);
850 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
851 gpu_performance = gpu->mutable_performance_statistics();
852 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
853 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
854 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
[email protected]d6bdfae2013-01-18 20:23:01855 gpu->set_gl_vendor(gpu_info.gl_vendor);
856 gpu->set_gl_renderer(gpu_info.gl_renderer);
[email protected]bc66d532012-03-23 01:57:05857
858 const gfx::Size display_size = GetScreenSize();
859 hardware->set_primary_screen_width(display_size.width());
860 hardware->set_primary_screen_height(display_size.height());
[email protected]aa96417972012-08-22 03:16:44861 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor());
[email protected]bc66d532012-03-23 01:57:05862 hardware->set_screen_count(GetScreenCount());
863
[email protected]76869ff2013-01-15 16:13:47864#if defined(OS_WIN)
865 WriteScreenDPIInformationProto(hardware);
866#endif
867
[email protected]197c0772012-05-14 23:50:51868 WriteGoogleUpdateProto(google_update_metrics);
869
[email protected]bc66d532012-03-23 01:57:05870 bool write_as_xml = false;
871 WritePluginList(plugin_list, write_as_xml);
872
[email protected]0c8b7ad2012-11-06 07:08:14873 std::vector<ActiveGroupId> field_trial_ids;
[email protected]767c9d92012-03-02 16:04:34874 GetFieldTrialIds(&field_trial_ids);
875 WriteFieldTrials(field_trial_ids, system_profile);
[email protected]f65859e2013-02-04 20:00:25876
877#if defined(OS_CHROMEOS)
878 PerfDataProto perf_data_proto;
879 if (perf_provider_.GetPerfData(&perf_data_proto))
880 uma_proto()->add_perf_data()->Swap(&perf_data_proto);
881#endif
initial.commit09911bf2008-07-26 23:55:29882}
883
[email protected]ed0fd002012-04-25 23:10:34884void MetricsLog::RecordProfilerData(
885 const tracked_objects::ProcessDataSnapshot& process_data,
[email protected]f3b357692013-03-22 05:16:13886 int process_type) {
[email protected]ed0fd002012-04-25 23:10:34887 DCHECK(!locked());
888
[email protected]8f829682012-04-27 00:36:49889 if (tracked_objects::GetTimeSourceType() !=
890 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) {
[email protected]ed0fd002012-04-25 23:10:34891 // We currently only support the default time source, wall clock time.
892 return;
893 }
894
895 ProfilerEventProto* profile;
896 if (!uma_proto()->profiler_event_size()) {
897 // For the first process's data, add a new field to the protocol buffer.
898 profile = uma_proto()->add_profiler_event();
899 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
900 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
901 } else {
902 // For the remaining calls, re-use the existing field.
903 profile = uma_proto()->mutable_profiler_event(0);
904 }
905
906 WriteProfilerData(process_data, process_type, profile);
907}
908
initial.commit09911bf2008-07-26 23:55:29909void MetricsLog::WriteAllProfilesMetrics(
910 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51911 const std::string profile_prefix(prefs::kProfilePrefix);
[email protected]a703e71e2013-02-26 23:58:14912 for (DictionaryValue::Iterator i(all_profiles_metrics); !i.IsAtEnd();
913 i.Advance()) {
914 if (i.key().compare(0, profile_prefix.size(), profile_prefix) == 0) {
[email protected]a61890e2012-07-27 22:27:11915 const DictionaryValue* profile;
[email protected]a703e71e2013-02-26 23:58:14916 if (i.value().GetAsDictionary(&profile))
917 WriteProfileMetrics(i.key().substr(profile_prefix.size()), *profile);
initial.commit09911bf2008-07-26 23:55:29918 }
919 }
920}
921
[email protected]e7b418b2010-07-30 19:47:47922void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29923 const DictionaryValue& profile_metrics) {
924 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47925 WriteAttribute("profileidhash", profileidhash);
[email protected]a703e71e2013-02-26 23:58:14926 for (DictionaryValue::Iterator i(profile_metrics); !i.IsAtEnd();
927 i.Advance()) {
928 DCHECK_NE(i.key(), "id");
929 switch (i.value().GetType()) {
930 case Value::TYPE_STRING: {
931 std::string string_value;
932 if (i.value().GetAsString(&string_value)) {
933 OPEN_ELEMENT_FOR_SCOPE("profileparam");
934 WriteAttribute("name", i.key());
935 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29936 }
[email protected]a703e71e2013-02-26 23:58:14937 break;
initial.commit09911bf2008-07-26 23:55:29938 }
[email protected]a703e71e2013-02-26 23:58:14939
940 case Value::TYPE_BOOLEAN: {
941 bool bool_value;
942 if (i.value().GetAsBoolean(&bool_value)) {
943 OPEN_ELEMENT_FOR_SCOPE("profileparam");
944 WriteAttribute("name", i.key());
945 WriteIntAttribute("value", bool_value ? 1 : 0);
946 }
947 break;
948 }
949
950 case Value::TYPE_INTEGER: {
951 int int_value;
952 if (i.value().GetAsInteger(&int_value)) {
953 OPEN_ELEMENT_FOR_SCOPE("profileparam");
954 WriteAttribute("name", i.key());
955 WriteIntAttribute("value", int_value);
956 }
957 break;
958 }
959
960 default:
961 NOTREACHED();
962 break;
initial.commit09911bf2008-07-26 23:55:29963 }
964 }
965}
966
967void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
[email protected]767c9d92012-03-02 16:04:34968 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29969
[email protected]fe58acc22012-02-29 01:29:58970 // Write the XML version.
[email protected]ffaf78a2008-11-12 17:38:33971 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29972 WriteAttribute("action", "autocomplete");
973 WriteAttribute("targetidhash", "");
974 // TODO(kochi): Properly track windows.
975 WriteIntAttribute("window", 0);
[email protected]6ebc3162011-12-19 13:44:00976 if (log.tab_id != -1) {
977 // If we know what tab the autocomplete URL was opened in, log it.
978 WriteIntAttribute("tab", static_cast<int>(log.tab_id));
979 }
initial.commit09911bf2008-07-26 23:55:29980 WriteCommonEventAttributes();
981
[email protected]65956312012-04-19 21:28:12982 std::vector<string16> terms;
983 const int num_terms =
984 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms));
[email protected]ffaf78a2008-11-12 17:38:33985 {
986 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29987
[email protected]ffaf78a2008-11-12 17:38:33988 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
[email protected]65956312012-04-19 21:28:12989 WriteIntAttribute("numterms", num_terms);
[email protected]ffaf78a2008-11-12 17:38:33990 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
991 WriteIntAttribute("completedlength",
[email protected]62b3ef52013-01-18 00:13:02992 log.completed_length != string16::npos ?
993 static_cast<int>(log.completed_length) : 0);
[email protected]9e349762012-01-31 03:24:36994 if (log.elapsed_time_since_user_first_modified_omnibox !=
995 base::TimeDelta::FromMilliseconds(-1)) {
996 // Only upload the typing duration if it is set/valid.
997 WriteInt64Attribute("typingduration",
998 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
999 }
[email protected]381e2992008-12-16 01:41:001000 const std::string input_type(
1001 AutocompleteInput::TypeToString(log.input_type));
1002 if (!input_type.empty())
1003 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:291004
[email protected]ffaf78a2008-11-12 17:38:331005 for (AutocompleteResult::const_iterator i(log.result.begin());
1006 i != log.result.end(); ++i) {
1007 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
1008 if (i->provider)
[email protected]35f1f4f02012-09-11 13:17:001009 WriteAttribute("provider", i->provider->GetName());
[email protected]381e2992008-12-16 01:41:001010 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
1011 if (!result_type.empty())
1012 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:331013 WriteIntAttribute("relevance", i->relevance);
1014 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
1015 }
initial.commit09911bf2008-07-26 23:55:291016 }
initial.commit09911bf2008-07-26 23:55:291017
[email protected]fe58acc22012-02-29 01:29:581018 // Write the protobuf version.
[email protected]767c9d92012-03-02 16:04:341019 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
[email protected]fe58acc22012-02-29 01:29:581020 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
1021 if (log.tab_id != -1) {
1022 // If we know what tab the autocomplete URL was opened in, log it.
1023 omnibox_event->set_tab_id(log.tab_id);
1024 }
1025 omnibox_event->set_typed_length(log.text.length());
[email protected]660fe8f32012-05-03 20:01:081026 omnibox_event->set_just_deleted_text(log.just_deleted_text);
[email protected]65956312012-04-19 21:28:121027 omnibox_event->set_num_typed_terms(num_terms);
[email protected]fe58acc22012-02-29 01:29:581028 omnibox_event->set_selected_index(log.selected_index);
[email protected]62b3ef52013-01-18 00:13:021029 if (log.completed_length != string16::npos)
1030 omnibox_event->set_completed_length(log.completed_length);
[email protected]65956312012-04-19 21:28:121031 if (log.elapsed_time_since_user_first_modified_omnibox !=
1032 base::TimeDelta::FromMilliseconds(-1)) {
1033 // Only upload the typing duration if it is set/valid.
1034 omnibox_event->set_typing_duration_ms(
1035 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
1036 }
[email protected]35d55602012-11-20 23:49:031037 omnibox_event->set_duration_since_last_default_match_update_ms(
1038 log.elapsed_time_since_last_change_to_default_match.InMilliseconds());
[email protected]ee902532012-05-01 23:54:491039 omnibox_event->set_current_page_classification(
1040 log.current_page_classification);
[email protected]fe58acc22012-02-29 01:29:581041 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
1042 for (AutocompleteResult::const_iterator i(log.result.begin());
1043 i != log.result.end(); ++i) {
1044 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
[email protected]0e9e8782012-05-15 23:01:511045 suggestion->set_provider(i->provider->AsOmniboxEventProviderType());
[email protected]fe58acc22012-02-29 01:29:581046 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
1047 suggestion->set_relevance(i->relevance);
[email protected]cf6256f2012-06-12 23:36:011048 if (i->typed_count != -1)
1049 suggestion->set_typed_count(i->typed_count);
[email protected]fe58acc22012-02-29 01:29:581050 suggestion->set_is_starred(i->starred);
1051 }
[email protected]0e9e8782012-05-15 23:01:511052 for (ProvidersInfo::const_iterator i(log.providers_info.begin());
1053 i != log.providers_info.end(); ++i) {
1054 OmniboxEventProto::ProviderInfo* provider_info =
1055 omnibox_event->add_provider_info();
1056 provider_info->CopyFrom(*i);
1057 }
[email protected]fe58acc22012-02-29 01:29:581058
initial.commit09911bf2008-07-26 23:55:291059 ++num_events_;
1060}
[email protected]197c0772012-05-14 23:50:511061
1062void MetricsLog::WriteGoogleUpdateProto(
1063 const GoogleUpdateMetrics& google_update_metrics) {
1064#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
1065 SystemProfileProto::GoogleUpdate* google_update =
1066 uma_proto()->mutable_system_profile()->mutable_google_update();
1067
1068 google_update->set_is_system_install(google_update_metrics.is_system_install);
1069
1070 if (!google_update_metrics.last_started_au.is_null()) {
1071 google_update->set_last_automatic_start_timestamp(
1072 google_update_metrics.last_started_au.ToTimeT());
1073 }
1074
1075 if (!google_update_metrics.last_checked.is_null()) {
1076 google_update->set_last_update_check_timestamp(
1077 google_update_metrics.last_checked.ToTimeT());
1078 }
1079
1080 if (!google_update_metrics.google_update_data.version.empty()) {
1081 ProductDataToProto(google_update_metrics.google_update_data,
1082 google_update->mutable_google_update_status());
1083 }
1084
1085 if (!google_update_metrics.product_data.version.empty()) {
1086 ProductDataToProto(google_update_metrics.product_data,
1087 google_update->mutable_client_status());
1088 }
1089#endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
1090}