blob: f7a4948cf14c25d58c5b96db5e1bd63c3fdcb2ff [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]ed0fd002012-04-25 23:10:3416#include "base/profiler/alternate_timer.h"
initial.commit09911bf2008-07-26 23:55:2917#include "base/string_util.h"
[email protected]3ea1b182013-02-08 22:38:4118#include "base/strings/string_number_conversions.h"
[email protected]fadf97f2008-09-18 12:18:1419#include "base/sys_info.h"
[email protected]37f39e42010-01-06 17:35:1720#include "base/third_party/nspr/prtime.h"
[email protected]1eeb5e02010-07-20 23:02:1121#include "base/time.h"
[email protected]ed0fd002012-04-25 23:10:3422#include "base/tracked_objects.h"
[email protected]1eeb5e02010-07-20 23:02:1123#include "base/utf_string_conversions.h"
[email protected]9f8bc2f2012-07-03 16:26:5324#include "chrome/browser/autocomplete/autocomplete_input.h"
[email protected]19871a92012-06-27 19:50:3225#include "chrome/browser/autocomplete/autocomplete_log.h"
[email protected]9ac40092010-10-27 23:05:2626#include "chrome/browser/autocomplete/autocomplete_match.h"
[email protected]30f5bc92012-06-26 04:14:5527#include "chrome/browser/autocomplete/autocomplete_provider.h"
[email protected]73c2b1632012-07-02 22:51:3828#include "chrome/browser/autocomplete/autocomplete_result.h"
initial.commit09911bf2008-07-26 23:55:2929#include "chrome/browser/browser_process.h"
[email protected]24b9bb392013-01-29 20:29:2930#include "chrome/browser/google/google_util.h"
[email protected]0f5e57f52012-09-20 20:53:1831#include "chrome/browser/plugins/plugin_prefs.h"
[email protected]b1de2c72013-02-06 02:45:4732#include "chrome/browser/prefs/pref_registry_simple.h"
[email protected]37858e52010-08-26 00:22:0233#include "chrome/browser/prefs/pref_service.h"
[email protected]10084982011-08-19 17:56:5634#include "chrome/browser/profiles/profile_manager.h"
[email protected]1eeb5e02010-07-20 23:02:1135#include "chrome/common/chrome_version_info.h"
initial.commit09911bf2008-07-26 23:55:2936#include "chrome/common/logging_chrome.h"
[email protected]fe58acc22012-02-29 01:29:5837#include "chrome/common/metrics/proto/omnibox_event.pb.h"
[email protected]ed0fd002012-04-25 23:10:3438#include "chrome/common/metrics/proto/profiler_event.pb.h"
[email protected]fe58acc22012-02-29 01:29:5839#include "chrome/common/metrics/proto/system_profile.pb.h"
[email protected]cf265dc02012-08-15 01:01:1640#include "chrome/common/metrics/variations/variations_util.h"
initial.commit09911bf2008-07-26 23:55:2941#include "chrome/common/pref_names.h"
[email protected]197c0772012-05-14 23:50:5142#include "chrome/installer/util/google_update_settings.h"
[email protected]fe58acc22012-02-29 01:29:5843#include "content/public/browser/content_browser_client.h"
[email protected]79078df2012-02-16 01:22:3244#include "content/public/browser/gpu_data_manager.h"
[email protected]1a838cc2012-04-24 22:06:4945#include "content/public/common/content_client.h"
[email protected]ed0fd002012-04-25 23:10:3446#include "content/public/common/gpu_info.h"
[email protected]46072d42008-07-28 14:49:3547#include "googleurl/src/gurl.h"
[email protected]74b299e2013-01-29 01:24:4248#include "net/base/network_change_notifier.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;
94 case AutocompleteInput::REQUESTED_URL:
95 return OmniboxEventProto::REQUESTED_URL;
96 case AutocompleteInput::URL:
97 return OmniboxEventProto::URL;
98 case AutocompleteInput::QUERY:
99 return OmniboxEventProto::QUERY;
100 case AutocompleteInput::FORCED_QUERY:
101 return OmniboxEventProto::FORCED_QUERY;
102 default:
103 NOTREACHED();
104 return OmniboxEventProto::INVALID;
105 }
106}
107
[email protected]fe58acc22012-02-29 01:29:58108OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
109 AutocompleteMatch::Type type) {
110 switch (type) {
111 case AutocompleteMatch::URL_WHAT_YOU_TYPED:
112 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
113 case AutocompleteMatch::HISTORY_URL:
114 return OmniboxEventProto::Suggestion::HISTORY_URL;
115 case AutocompleteMatch::HISTORY_TITLE:
116 return OmniboxEventProto::Suggestion::HISTORY_TITLE;
117 case AutocompleteMatch::HISTORY_BODY:
118 return OmniboxEventProto::Suggestion::HISTORY_BODY;
119 case AutocompleteMatch::HISTORY_KEYWORD:
120 return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
121 case AutocompleteMatch::NAVSUGGEST:
122 return OmniboxEventProto::Suggestion::NAVSUGGEST;
123 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
124 return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
125 case AutocompleteMatch::SEARCH_HISTORY:
126 return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
127 case AutocompleteMatch::SEARCH_SUGGEST:
128 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
129 case AutocompleteMatch::SEARCH_OTHER_ENGINE:
130 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
131 case AutocompleteMatch::EXTENSION_APP:
132 return OmniboxEventProto::Suggestion::EXTENSION_APP;
[email protected]dbacefb2012-09-12 03:32:06133 case AutocompleteMatch::CONTACT:
134 return OmniboxEventProto::Suggestion::CONTACT;
[email protected]25320602012-10-18 22:05:56135 case AutocompleteMatch::BOOKMARK_TITLE:
136 return OmniboxEventProto::Suggestion::BOOKMARK_TITLE;
[email protected]fe58acc22012-02-29 01:29:58137 default:
138 NOTREACHED();
139 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
140 }
141}
142
[email protected]ed0fd002012-04-25 23:10:34143ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType(
144 content::ProcessType process_type) {
145 switch (process_type) {
146 case content::PROCESS_TYPE_BROWSER:
147 return ProfilerEventProto::TrackedObject::BROWSER;
148 case content::PROCESS_TYPE_RENDERER:
149 return ProfilerEventProto::TrackedObject::RENDERER;
150 case content::PROCESS_TYPE_PLUGIN:
151 return ProfilerEventProto::TrackedObject::PLUGIN;
152 case content::PROCESS_TYPE_WORKER:
153 return ProfilerEventProto::TrackedObject::WORKER;
154 case content::PROCESS_TYPE_NACL_LOADER:
155 return ProfilerEventProto::TrackedObject::NACL_LOADER;
156 case content::PROCESS_TYPE_UTILITY:
157 return ProfilerEventProto::TrackedObject::UTILITY;
158 case content::PROCESS_TYPE_PROFILE_IMPORT:
159 return ProfilerEventProto::TrackedObject::PROFILE_IMPORT;
160 case content::PROCESS_TYPE_ZYGOTE:
161 return ProfilerEventProto::TrackedObject::ZYGOTE;
162 case content::PROCESS_TYPE_SANDBOX_HELPER:
163 return ProfilerEventProto::TrackedObject::SANDBOX_HELPER;
164 case content::PROCESS_TYPE_NACL_BROKER:
165 return ProfilerEventProto::TrackedObject::NACL_BROKER;
166 case content::PROCESS_TYPE_GPU:
167 return ProfilerEventProto::TrackedObject::GPU;
168 case content::PROCESS_TYPE_PPAPI_PLUGIN:
169 return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN;
170 case content::PROCESS_TYPE_PPAPI_BROKER:
171 return ProfilerEventProto::TrackedObject::PPAPI_BROKER;
172 default:
173 NOTREACHED();
174 return ProfilerEventProto::TrackedObject::UNKNOWN;
175 }
176}
177
[email protected]1df44b72012-01-19 05:20:34178// Returns the plugin preferences corresponding for this user, if available.
179// If multiple user profiles are loaded, returns the preferences corresponding
180// to an arbitrary one of the profiles.
181PluginPrefs* GetPluginPrefs() {
182 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]fe58acc22012-02-29 01:29:58183
184 if (!profile_manager) {
185 // The profile manager can be NULL when testing.
186 return NULL;
187 }
188
[email protected]1df44b72012-01-19 05:20:34189 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
190 if (profiles.empty())
191 return NULL;
192
193 return PluginPrefs::GetForProfile(profiles.front());
194}
195
[email protected]fe58acc22012-02-29 01:29:58196// Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
197void SetPluginInfo(const webkit::WebPluginInfo& plugin_info,
198 const PluginPrefs* plugin_prefs,
199 SystemProfileProto::Plugin* plugin) {
200 plugin->set_name(UTF16ToUTF8(plugin_info.name));
201 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
202 plugin->set_version(UTF16ToUTF8(plugin_info.version));
203 if (plugin_prefs)
204 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
205}
206
[email protected]0c8b7ad2012-11-06 07:08:14207void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids,
[email protected]767c9d92012-03-02 16:04:34208 SystemProfileProto* system_profile) {
[email protected]0c8b7ad2012-11-06 07:08:14209 for (std::vector<ActiveGroupId>::const_iterator it =
[email protected]ad2461c2012-04-27 21:11:03210 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
[email protected]767c9d92012-03-02 16:04:34211 SystemProfileProto::FieldTrial* field_trial =
212 system_profile->add_field_trial();
213 field_trial->set_name_id(it->name);
214 field_trial->set_group_id(it->group);
215 }
216}
217
[email protected]ed0fd002012-04-25 23:10:34218void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
219 content::ProcessType process_type,
220 ProfilerEventProto* performance_profile) {
221 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it =
222 profiler_data.tasks.begin();
223 it != profiler_data.tasks.end(); ++it) {
224 std::string ignored;
225 uint64 birth_thread_name_hash;
226 uint64 exec_thread_name_hash;
227 uint64 source_file_name_hash;
228 uint64 source_function_name_hash;
229 MetricsLogBase::CreateHashes(it->birth.thread_name,
230 &ignored, &birth_thread_name_hash);
231 MetricsLogBase::CreateHashes(it->death_thread_name,
232 &ignored, &exec_thread_name_hash);
[email protected]ed0fd002012-04-25 23:10:34233 MetricsLogBase::CreateHashes(it->birth.location.file_name,
[email protected]04162262012-10-23 01:17:25234 &ignored, &source_file_name_hash);
235 MetricsLogBase::CreateHashes(it->birth.location.function_name,
[email protected]ed0fd002012-04-25 23:10:34236 &ignored, &source_function_name_hash);
237
238 const tracked_objects::DeathDataSnapshot& death_data = it->death_data;
239 ProfilerEventProto::TrackedObject* tracked_object =
240 performance_profile->add_tracked_object();
241 tracked_object->set_birth_thread_name_hash(birth_thread_name_hash);
242 tracked_object->set_exec_thread_name_hash(exec_thread_name_hash);
243 tracked_object->set_source_file_name_hash(source_file_name_hash);
244 tracked_object->set_source_function_name_hash(source_function_name_hash);
245 tracked_object->set_source_line_number(it->birth.location.line_number);
246 tracked_object->set_exec_count(death_data.count);
247 tracked_object->set_exec_time_total(death_data.run_duration_sum);
248 tracked_object->set_exec_time_sampled(death_data.run_duration_sample);
249 tracked_object->set_queue_time_total(death_data.queue_duration_sum);
250 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample);
251 tracked_object->set_process_type(AsProtobufProcessType(process_type));
252 tracked_object->set_process_id(profiler_data.process_id);
253 }
254}
255
[email protected]59a7ae4e2012-10-01 23:54:44256#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
[email protected]197c0772012-05-14 23:50:51257void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data,
258 ProductInfo* product_info) {
259 product_info->set_version(product_data.version);
260 product_info->set_last_update_success_timestamp(
261 product_data.last_success.ToTimeT());
262 product_info->set_last_error(product_data.last_error_code);
263 product_info->set_last_extra_error(product_data.last_extra_code);
264 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) {
265 product_info->set_last_result(
266 static_cast<ProductInfo::InstallResult>(product_data.last_result));
267 }
268}
[email protected]59a7ae4e2012-10-01 23:54:44269#endif
[email protected]197c0772012-05-14 23:50:51270
[email protected]76869ff2013-01-15 16:13:47271#if defined(OS_WIN)
272struct ScreenDPIInformation{
273 double max_dpi_x;
274 double max_dpi_y;
275};
276
277// Called once for each connected monitor.
278BOOL CALLBACK GetMonitorDPICallback(HMONITOR, HDC hdc, LPRECT, LPARAM dwData) {
279 const double kMillimetersPerInch = 25.4;
280 ScreenDPIInformation* screen_info =
281 reinterpret_cast<ScreenDPIInformation*>(dwData);
282 // Size of screen, in mm.
283 DWORD size_x = GetDeviceCaps(hdc, HORZSIZE);
284 DWORD size_y = GetDeviceCaps(hdc, VERTSIZE);
285 double dpi_x = (size_x > 0) ?
286 GetDeviceCaps(hdc, HORZRES) / (size_x / kMillimetersPerInch) : 0;
287 double dpi_y = (size_y > 0) ?
288 GetDeviceCaps(hdc, VERTRES) / (size_y / kMillimetersPerInch) : 0;
289 screen_info->max_dpi_x = std::max(dpi_x, screen_info->max_dpi_x);
290 screen_info->max_dpi_y = std::max(dpi_y, screen_info->max_dpi_y);
291 return TRUE;
292}
293
294void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) {
295 HDC desktop_dc = GetDC(NULL);
296 if (desktop_dc) {
297 ScreenDPIInformation si = {0,0};
298 if (EnumDisplayMonitors(desktop_dc, NULL, GetMonitorDPICallback,
299 reinterpret_cast<LPARAM>(&si))) {
300 hardware->set_max_dpi_x(si.max_dpi_x);
301 hardware->set_max_dpi_y(si.max_dpi_y);
302 }
303 ReleaseDC(GetDesktopWindow(), desktop_dc);
304 }
305}
306
307#endif // defined(OS_WIN)
308
[email protected]1df44b72012-01-19 05:20:34309} // namespace
310
[email protected]74b299e2013-01-29 01:24:42311class MetricsLog::NetworkObserver
312 : public net::NetworkChangeNotifier::ConnectionTypeObserver {
313 public:
314 NetworkObserver() : connection_type_is_ambiguous_(false) {
315 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
316 Reset();
317 }
318 virtual ~NetworkObserver() {
319 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
320 }
321
322 void Reset() {
323 connection_type_is_ambiguous_ = false;
324 connection_type_ = net::NetworkChangeNotifier::GetConnectionType();
325 }
326
327 // ConnectionTypeObserver:
328 virtual void OnConnectionTypeChanged(
329 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE {
330 if (type == net::NetworkChangeNotifier::CONNECTION_NONE)
331 return;
332 if (type != connection_type_ &&
333 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) {
334 connection_type_is_ambiguous_ = true;
335 }
336 connection_type_ = type;
337 }
338
339 bool connection_type_is_ambiguous() const {
340 return connection_type_is_ambiguous_;
341 }
342
343 SystemProfileProto::Network::ConnectionType connection_type() const {
344 switch (connection_type_) {
345 case net::NetworkChangeNotifier::CONNECTION_NONE:
346 case net::NetworkChangeNotifier::CONNECTION_UNKNOWN:
347 return SystemProfileProto::Network::CONNECTION_UNKNOWN;
348 case net::NetworkChangeNotifier::CONNECTION_ETHERNET:
349 return SystemProfileProto::Network::CONNECTION_ETHERNET;
350 case net::NetworkChangeNotifier::CONNECTION_WIFI:
351 return SystemProfileProto::Network::CONNECTION_WIFI;
352 case net::NetworkChangeNotifier::CONNECTION_2G:
353 return SystemProfileProto::Network::CONNECTION_2G;
354 case net::NetworkChangeNotifier::CONNECTION_3G:
355 return SystemProfileProto::Network::CONNECTION_3G;
356 case net::NetworkChangeNotifier::CONNECTION_4G:
357 return SystemProfileProto::Network::CONNECTION_4G;
358 }
359 NOTREACHED();
360 return SystemProfileProto::Network::CONNECTION_UNKNOWN;
361 }
362
363 private:
364 bool connection_type_is_ambiguous_;
365 net::NetworkChangeNotifier::ConnectionType connection_type_;
366
367 DISALLOW_COPY_AND_ASSIGN(NetworkObserver);
368};
369
[email protected]197c0772012-05-14 23:50:51370GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {}
371
372GoogleUpdateMetrics::~GoogleUpdateMetrics() {}
373
[email protected]67f92bc32012-01-26 01:56:19374static base::LazyInstance<std::string>::Leaky
[email protected]054c8012011-11-16 00:12:42375 g_version_extension = LAZY_INSTANCE_INITIALIZER;
376
[email protected]1226abb2010-06-10 18:01:28377MetricsLog::MetricsLog(const std::string& client_id, int session_id)
[email protected]74b299e2013-01-29 01:24:42378 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()),
379 network_observer_(new NetworkObserver()) {}
[email protected]5ed7d4572009-12-23 17:42:41380
[email protected]1226abb2010-06-10 18:01:28381MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:29382
383// static
[email protected]b1de2c72013-02-06 02:45:47384void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) {
385 registry->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29386}
387
[email protected]1df44b72012-01-19 05:20:34388// static
[email protected]9165f742010-03-10 22:55:01389int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
390 base::TimeTicks now = base::TimeTicks::Now();
391 static base::TimeTicks last_updated_time(now);
392 int64 incremental_time = (now - last_updated_time).InSeconds();
393 last_updated_time = now;
394
395 if (incremental_time > 0) {
396 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
397 metrics_uptime += incremental_time;
398 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
399 }
400
401 return incremental_time;
402}
403
[email protected]1226abb2010-06-10 18:01:28404// static
405std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:42406 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:17407 if (!version_info.is_valid()) {
408 NOTREACHED() << "Unable to retrieve version info.";
409 return std::string();
410 }
411
[email protected]0211f57e2010-08-27 20:28:42412 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:42413 if (!version_extension().empty())
414 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:42415 if (!version_info.IsOfficialBuild())
416 version.append("-devel");
417 return version;
[email protected]1226abb2010-06-10 18:01:28418}
419
[email protected]054c8012011-11-16 00:12:42420// static
421void MetricsLog::set_version_extension(const std::string& extension) {
422 g_version_extension.Get() = extension;
423}
424
425// static
426const std::string& MetricsLog::version_extension() {
427 return g_version_extension.Get();
428}
429
[email protected]fe58acc22012-02-29 01:29:58430void MetricsLog::RecordIncrementalStabilityElements(
431 const std::vector<webkit::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34432 DCHECK(!locked());
[email protected]0b33f80b2008-12-17 21:34:36433
[email protected]767c9d92012-03-02 16:04:34434 PrefService* pref = GetPrefService();
[email protected]0b33f80b2008-12-17 21:34:36435 DCHECK(pref);
436
[email protected]147bbc0b2009-01-06 19:37:40437 OPEN_ELEMENT_FOR_SCOPE("profile");
438 WriteCommonEventAttributes();
439
[email protected]9958a322011-03-08 20:04:17440 WriteInstallElement();
[email protected]147bbc0b2009-01-06 19:37:40441
442 {
443 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
444 WriteRequiredStabilityAttributes(pref);
445 WriteRealtimeStabilityAttributes(pref);
[email protected]fe58acc22012-02-29 01:29:58446 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40447 }
[email protected]0b33f80b2008-12-17 21:34:36448}
449
[email protected]767c9d92012-03-02 16:04:34450PrefService* MetricsLog::GetPrefService() {
451 return g_browser_process->local_state();
452}
453
454gfx::Size MetricsLog::GetScreenSize() const {
[email protected]ffabb1e2012-10-12 19:51:17455 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel();
[email protected]767c9d92012-03-02 16:04:34456}
457
[email protected]aa96417972012-08-22 03:16:44458float MetricsLog::GetScreenDeviceScaleFactor() const {
[email protected]ffabb1e2012-10-12 19:51:17459 return gfx::Screen::GetNativeScreen()->
460 GetPrimaryDisplay().device_scale_factor();
[email protected]aa96417972012-08-22 03:16:44461}
462
[email protected]767c9d92012-03-02 16:04:34463int MetricsLog::GetScreenCount() const {
[email protected]ffabb1e2012-10-12 19:51:17464 // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312
465 return gfx::Screen::GetNativeScreen()->GetNumDisplays();
[email protected]767c9d92012-03-02 16:04:34466}
467
[email protected]767c9d92012-03-02 16:04:34468void MetricsLog::GetFieldTrialIds(
[email protected]0c8b7ad2012-11-06 07:08:14469 std::vector<ActiveGroupId>* field_trial_ids) const {
470 chrome_variations::GetFieldTrialActiveGroupIds(field_trial_ids);
[email protected]767c9d92012-03-02 16:04:34471}
472
[email protected]fe58acc22012-02-29 01:29:58473void MetricsLog::WriteStabilityElement(
474 const std::vector<webkit::WebPluginInfo>& plugin_list,
475 PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:34476 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29477
initial.commit09911bf2008-07-26 23:55:29478 // Get stability attributes out of Local State, zeroing out stored values.
479 // NOTE: This could lead to some data loss if this report isn't successfully
480 // sent, but that's true for all the metrics.
481
[email protected]ffaf78a2008-11-12 17:38:33482 OPEN_ELEMENT_FOR_SCOPE("stability");
[email protected]147bbc0b2009-01-06 19:37:40483 WriteRequiredStabilityAttributes(pref);
484 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29485
[email protected]fe58acc22012-02-29 01:29:58486 int incomplete_shutdown_count =
487 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
[email protected]e324f6b2012-02-28 05:43:37488 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58489 int breakpad_registration_success_count =
490 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
[email protected]e324f6b2012-02-28 05:43:37491 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58492 int breakpad_registration_failure_count =
493 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
[email protected]e324f6b2012-02-28 05:43:37494 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58495 int debugger_present_count =
496 pref->GetInteger(prefs::kStabilityDebuggerPresent);
[email protected]e324f6b2012-02-28 05:43:37497 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58498 int debugger_not_present_count =
499 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
[email protected]e324f6b2012-02-28 05:43:37500 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31501
[email protected]fe58acc22012-02-29 01:29:58502 // TODO(jar): The following are all optional, so we *could* optimize them for
503 // values of zero (and not include them).
504
505 // Write the XML version.
506 WriteIntAttribute("incompleteshutdowncount", incomplete_shutdown_count);
507 WriteIntAttribute("breakpadregistrationok",
508 breakpad_registration_success_count);
509 WriteIntAttribute("breakpadregistrationfail",
510 breakpad_registration_failure_count);
511 WriteIntAttribute("debuggerpresent", debugger_present_count);
512 WriteIntAttribute("debuggernotpresent", debugger_not_present_count);
513
514 // Write the protobuf version.
515 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34516 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58517 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
518 stability->set_breakpad_registration_success_count(
519 breakpad_registration_success_count);
520 stability->set_breakpad_registration_failure_count(
521 breakpad_registration_failure_count);
522 stability->set_debugger_present_count(debugger_present_count);
523 stability->set_debugger_not_present_count(debugger_not_present_count);
524
525 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40526}
527
[email protected]fe58acc22012-02-29 01:29:58528void MetricsLog::WritePluginStabilityElements(
529 const std::vector<webkit::WebPluginInfo>& plugin_list,
530 PrefService* pref) {
[email protected]147bbc0b2009-01-06 19:37:40531 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29532 const ListValue* plugin_stats_list = pref->GetList(
533 prefs::kStabilityPluginStats);
[email protected]1df44b72012-01-19 05:20:34534 if (!plugin_stats_list)
535 return;
initial.commit09911bf2008-07-26 23:55:29536
[email protected]1df44b72012-01-19 05:20:34537 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]ebd71962012-12-20 02:56:55538
539#if defined(ENABLE_PLUGINS)
[email protected]fe58acc22012-02-29 01:29:58540 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34541 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58542 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]1df44b72012-01-19 05:20:34543 for (ListValue::const_iterator iter = plugin_stats_list->begin();
544 iter != plugin_stats_list->end(); ++iter) {
545 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
546 NOTREACHED();
547 continue;
initial.commit09911bf2008-07-26 23:55:29548 }
[email protected]1df44b72012-01-19 05:20:34549 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29550
[email protected]1df44b72012-01-19 05:20:34551 std::string plugin_name;
552 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
553
[email protected]fe58acc22012-02-29 01:29:58554 std::string base64_name_hash;
555 uint64 numeric_name_hash_ignored;
556 CreateHashes(plugin_name, &base64_name_hash, &numeric_name_hash_ignored);
557
558 // Write the XML verison.
[email protected]1df44b72012-01-19 05:20:34559 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
560 // Use "filename" instead of "name", otherwise we need to update the
561 // UMA servers.
[email protected]fe58acc22012-02-29 01:29:58562 WriteAttribute("filename", base64_name_hash);
[email protected]1df44b72012-01-19 05:20:34563
564 int launches = 0;
565 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
566 WriteIntAttribute("launchcount", launches);
567
568 int instances = 0;
569 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
570 WriteIntAttribute("instancecount", instances);
571
572 int crashes = 0;
573 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
574 WriteIntAttribute("crashcount", crashes);
[email protected]fe58acc22012-02-29 01:29:58575
576 // Write the protobuf version.
577 // Note that this search is potentially a quadratic operation, but given the
578 // low number of plugins installed on a "reasonable" setup, this should be
579 // fine.
580 // TODO(isherman): Verify that this does not show up as a hotspot in
581 // profiler runs.
582 const webkit::WebPluginInfo* plugin_info = NULL;
583 const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name);
584 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
585 plugin_list.begin();
586 iter != plugin_list.end(); ++iter) {
587 if (iter->name == plugin_name_utf16) {
588 plugin_info = &(*iter);
589 break;
590 }
591 }
592
593 if (!plugin_info) {
594 NOTREACHED();
595 continue;
596 }
[email protected]cd937072012-07-02 09:00:29597 int loading_errors = 0;
598 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors,
599 &loading_errors);
600 WriteIntAttribute("loadingerrorcount", loading_errors);
[email protected]fe58acc22012-02-29 01:29:58601
[email protected]cd937072012-07-02 09:00:29602 // Write the protobuf version.
[email protected]fe58acc22012-02-29 01:29:58603 SystemProfileProto::Stability::PluginStability* plugin_stability =
604 stability->add_plugin_stability();
605 SetPluginInfo(*plugin_info, plugin_prefs,
606 plugin_stability->mutable_plugin());
607 plugin_stability->set_launch_count(launches);
608 plugin_stability->set_instance_count(instances);
609 plugin_stability->set_crash_count(crashes);
[email protected]cd937072012-07-02 09:00:29610 plugin_stability->set_loading_error_count(loading_errors);
initial.commit09911bf2008-07-26 23:55:29611 }
[email protected]ebd71962012-12-20 02:56:55612#endif // defined(ENABLE_PLUGINS)
[email protected]1df44b72012-01-19 05:20:34613
614 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29615}
616
[email protected]fe58acc22012-02-29 01:29:58617// The server refuses data that doesn't have certain values. crashcount and
618// launchcount are currently "required" in the "stability" group.
619// TODO(isherman): Stop writing these attributes specially once the migration to
620// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40621void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]fe58acc22012-02-29 01:29:58622 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
[email protected]0b33f80b2008-12-17 21:34:36623 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
[email protected]fe58acc22012-02-29 01:29:58624 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
[email protected]0b33f80b2008-12-17 21:34:36625 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58626
627 // Write the XML version.
628 WriteIntAttribute("launchcount", launch_count);
629 WriteIntAttribute("crashcount", crash_count);
630
631 // Write the protobuf version.
632 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34633 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58634 stability->set_launch_count(launch_count);
635 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36636}
637
[email protected]147bbc0b2009-01-06 19:37:40638void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36639 // Update the stats which are critical for real-time stability monitoring.
640 // Since these are "optional," only list ones that are non-zero, as the counts
641 // are aggergated (summed) server side.
642
[email protected]fe58acc22012-02-29 01:29:58643 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34644 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36645 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
646 if (count) {
647 WriteIntAttribute("pageloadcount", count);
[email protected]fe58acc22012-02-29 01:29:58648 stability->set_page_load_count(count);
[email protected]0b33f80b2008-12-17 21:34:36649 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
650 }
651
652 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
653 if (count) {
654 WriteIntAttribute("renderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58655 stability->set_renderer_crash_count(count);
[email protected]0b33f80b2008-12-17 21:34:36656 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
657 }
658
[email protected]1f085622009-12-04 05:33:45659 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
660 if (count) {
661 WriteIntAttribute("extensionrenderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58662 stability->set_extension_renderer_crash_count(count);
[email protected]1f085622009-12-04 05:33:45663 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
664 }
665
[email protected]0b33f80b2008-12-17 21:34:36666 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
667 if (count) {
668 WriteIntAttribute("rendererhangcount", count);
[email protected]fe58acc22012-02-29 01:29:58669 stability->set_renderer_hang_count(count);
[email protected]0b33f80b2008-12-17 21:34:36670 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
671 }
[email protected]1f085622009-12-04 05:33:45672
673 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
674 if (count) {
675 WriteIntAttribute("childprocesscrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58676 stability->set_child_process_crash_count(count);
[email protected]1f085622009-12-04 05:33:45677 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
678 }
[email protected]9165f742010-03-10 22:55:01679
[email protected]c1834a92011-01-21 18:21:03680#if defined(OS_CHROMEOS)
681 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
682 if (count) {
[email protected]fe58acc22012-02-29 01:29:58683 stability->set_other_user_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03684 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
685 }
686
687 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
688 if (count) {
[email protected]fe58acc22012-02-29 01:29:58689 stability->set_kernel_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03690 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
691 }
692
693 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
694 if (count) {
[email protected]fe58acc22012-02-29 01:29:58695 stability->set_unclean_system_shutdown_count(count);
[email protected]c1834a92011-01-21 18:21:03696 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
697 }
698#endif // OS_CHROMEOS
699
[email protected]9165f742010-03-10 22:55:01700 int64 recent_duration = GetIncrementalUptime(pref);
[email protected]fe58acc22012-02-29 01:29:58701 if (recent_duration) {
[email protected]9165f742010-03-10 22:55:01702 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]fe58acc22012-02-29 01:29:58703 stability->set_uptime_sec(recent_duration);
704 }
[email protected]0b33f80b2008-12-17 21:34:36705}
706
initial.commit09911bf2008-07-26 23:55:29707void MetricsLog::WritePluginList(
[email protected]bc66d532012-03-23 01:57:05708 const std::vector<webkit::WebPluginInfo>& plugin_list,
709 bool write_as_xml) {
[email protected]767c9d92012-03-02 16:04:34710 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29711
[email protected]ffaf78a2008-11-12 17:38:33712 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]ebd71962012-12-20 02:56:55713
714#if defined(ENABLE_PLUGINS)
715 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]767c9d92012-03-02 16:04:34716 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]91d9f3d2011-08-14 05:24:44717 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50718 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29719 iter != plugin_list.end(); ++iter) {
[email protected]bc66d532012-03-23 01:57:05720 if (write_as_xml) {
721 std::string base64_name_hash;
722 uint64 numeric_hash_ignored;
723 CreateHashes(UTF16ToUTF8(iter->name), &base64_name_hash,
724 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58725
[email protected]bc66d532012-03-23 01:57:05726 std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe();
727 std::string base64_filename_hash;
728 CreateHashes(filename_bytes, &base64_filename_hash,
729 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58730
[email protected]bc66d532012-03-23 01:57:05731 // Write the XML version.
732 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29733
[email protected]bc66d532012-03-23 01:57:05734 // Plugin name and filename are hashed for the privacy of those
735 // testing unreleased new extensions.
736 WriteAttribute("name", base64_name_hash);
737 WriteAttribute("filename", base64_filename_hash);
738 WriteAttribute("version", UTF16ToUTF8(iter->version));
739 if (plugin_prefs)
740 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
741 } else {
742 // Write the protobuf version.
743 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
744 SetPluginInfo(*iter, plugin_prefs, plugin);
745 }
initial.commit09911bf2008-07-26 23:55:29746 }
[email protected]ebd71962012-12-20 02:56:55747#endif // defined(ENABLE_PLUGINS)
initial.commit09911bf2008-07-26 23:55:29748}
749
[email protected]147bbc0b2009-01-06 19:37:40750void MetricsLog::WriteInstallElement() {
[email protected]fe58acc22012-02-29 01:29:58751 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05752 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]147bbc0b2009-01-06 19:37:40753 OPEN_ELEMENT_FOR_SCOPE("install");
[email protected]cc5d7f42012-10-30 00:30:09754 WriteAttribute("installdate", GetMetricsEnabledDate(GetPrefService()));
[email protected]147bbc0b2009-01-06 19:37:40755 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40756}
757
initial.commit09911bf2008-07-26 23:55:29758void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44759 const std::vector<webkit::WebPluginInfo>& plugin_list,
[email protected]197c0772012-05-14 23:50:51760 const GoogleUpdateMetrics& google_update_metrics,
initial.commit09911bf2008-07-26 23:55:29761 const DictionaryValue* profile_metrics) {
[email protected]767c9d92012-03-02 16:04:34762 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29763
[email protected]767c9d92012-03-02 16:04:34764 PrefService* pref = GetPrefService();
initial.commit09911bf2008-07-26 23:55:29765
[email protected]ffaf78a2008-11-12 17:38:33766 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29767 WriteCommonEventAttributes();
768
[email protected]147bbc0b2009-01-06 19:37:40769 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29770
[email protected]bc66d532012-03-23 01:57:05771 // Write the XML version.
772 // We'll write the protobuf version in RecordEnvironmentProto().
773 bool write_as_xml = true;
774 WritePluginList(plugin_list, write_as_xml);
initial.commit09911bf2008-07-26 23:55:29775
[email protected]fe58acc22012-02-29 01:29:58776 WriteStabilityElement(plugin_list, pref);
initial.commit09911bf2008-07-26 23:55:29777
778 {
[email protected]fe58acc22012-02-29 01:29:58779 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05780 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29781 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]0b6a4fb2012-10-16 01:58:21782 WriteAttribute("arch", base::SysInfo::OperatingSystemArchitecture());
initial.commit09911bf2008-07-26 23:55:29783 }
784
785 {
[email protected]fe58acc22012-02-29 01:29:58786 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05787 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29788 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]bc66d532012-03-23 01:57:05789 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38790#if defined(OS_WIN)
791 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
792#endif
initial.commit09911bf2008-07-26 23:55:29793 }
794
795 {
[email protected]fe58acc22012-02-29 01:29:58796 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05797 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29798 OPEN_ELEMENT_FOR_SCOPE("os");
[email protected]bc66d532012-03-23 01:57:05799 WriteAttribute("name", base::SysInfo::OperatingSystemName());
800 WriteAttribute("version", base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29801 }
802
803 {
[email protected]e8c287c872010-07-20 00:49:42804 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]fe58acc22012-02-29 01:29:58805 const content::GPUInfo& gpu_info =
806 GpuDataManager::GetInstance()->GetGPUInfo();
[email protected]fe58acc22012-02-29 01:29:58807
808 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05809 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]a094e2c2012-05-10 23:02:42810 WriteIntAttribute("vendorid", gpu_info.gpu.vendor_id);
811 WriteIntAttribute("deviceid", gpu_info.gpu.device_id);
[email protected]e8c287c872010-07-20 00:49:42812 }
813
814 {
[email protected]767c9d92012-03-02 16:04:34815 const gfx::Size display_size = GetScreenSize();
[email protected]fe58acc22012-02-29 01:29:58816
817 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05818 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]fe58acc22012-02-29 01:29:58819 OPEN_ELEMENT_FOR_SCOPE("display");
[email protected]bc66d532012-03-23 01:57:05820 WriteIntAttribute("xsize", display_size.width());
821 WriteIntAttribute("ysize", display_size.height());
822 WriteIntAttribute("screens", GetScreenCount());
initial.commit09911bf2008-07-26 23:55:29823 }
824
825 {
826 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
initial.commit09911bf2008-07-26 23:55:29827 {
828 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
829 WriteAttribute("name", "full-tree");
[email protected]8542bcc2013-01-30 00:15:36830 WriteIntAttribute("foldercount", 0);
831 WriteIntAttribute("itemcount", 0);
initial.commit09911bf2008-07-26 23:55:29832 }
833 {
834 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
835 WriteAttribute("name", "toolbar");
[email protected]8542bcc2013-01-30 00:15:36836 WriteIntAttribute("foldercount", 0);
837 WriteIntAttribute("itemcount", 0);
initial.commit09911bf2008-07-26 23:55:29838 }
839 }
840
841 {
842 OPEN_ELEMENT_FOR_SCOPE("keywords");
843 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
844 }
845
846 if (profile_metrics)
847 WriteAllProfilesMetrics(*profile_metrics);
[email protected]767c9d92012-03-02 16:04:34848
[email protected]197c0772012-05-14 23:50:51849 RecordEnvironmentProto(plugin_list, google_update_metrics);
[email protected]bc66d532012-03-23 01:57:05850}
851
852void MetricsLog::RecordEnvironmentProto(
[email protected]197c0772012-05-14 23:50:51853 const std::vector<webkit::WebPluginInfo>& plugin_list,
854 const GoogleUpdateMetrics& google_update_metrics) {
[email protected]bc66d532012-03-23 01:57:05855 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]24b9bb392013-01-29 20:29:29856
857 std::string brand_code;
858 if (google_util::GetBrand(&brand_code))
859 system_profile->set_brand_code(brand_code);
860
[email protected]cc5d7f42012-10-30 00:30:09861 int enabled_date;
862 bool success = base::StringToInt(GetMetricsEnabledDate(GetPrefService()),
863 &enabled_date);
[email protected]bc66d532012-03-23 01:57:05864 DCHECK(success);
[email protected]cc5d7f42012-10-30 00:30:09865 system_profile->set_uma_enabled_date(enabled_date);
[email protected]bc66d532012-03-23 01:57:05866
867 system_profile->set_application_locale(
868 content::GetContentClient()->browser()->GetApplicationLocale());
869
870 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
[email protected]0b6a4fb2012-10-16 01:58:21871 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
[email protected]bc66d532012-03-23 01:57:05872 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
873#if defined(OS_WIN)
874 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
875#endif
876
[email protected]74b299e2013-01-29 01:24:42877 SystemProfileProto::Network* network = system_profile->mutable_network();
878 network->set_connection_type_is_ambiguous(
879 network_observer_->connection_type_is_ambiguous());
880 network->set_connection_type(network_observer_->connection_type());
881 network_observer_->Reset();
882
[email protected]bc66d532012-03-23 01:57:05883 SystemProfileProto::OS* os = system_profile->mutable_os();
[email protected]1bb25e02012-08-03 22:39:39884 std::string os_name = base::SysInfo::OperatingSystemName();
885#if defined(OS_WIN)
886 // TODO(mad): This only checks whether the main process is a Metro process at
887 // upload time; not whether the collected metrics were all gathered from
888 // Metro. This is ok as an approximation for now, since users will rarely be
889 // switching from Metro to Desktop mode; but we should re-evaluate whether we
890 // can distinguish metrics more cleanly in the future: http://crbug.com/140568
891 if (base::win::IsMetroProcess())
892 os_name += " (Metro)";
893#endif
894 os->set_name(os_name);
[email protected]bc66d532012-03-23 01:57:05895 os->set_version(base::SysInfo::OperatingSystemVersion());
[email protected]5106b3a2012-10-03 20:10:44896#if defined(OS_ANDROID)
897 os->set_fingerprint(
898 base::android::BuildInfo::GetInstance()->android_build_fp());
899#endif
[email protected]bc66d532012-03-23 01:57:05900
901 const content::GPUInfo& gpu_info =
902 GpuDataManager::GetInstance()->GetGPUInfo();
903 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
[email protected]a094e2c2012-05-10 23:02:42904 gpu->set_vendor_id(gpu_info.gpu.vendor_id);
905 gpu->set_device_id(gpu_info.gpu.device_id);
[email protected]bc66d532012-03-23 01:57:05906 gpu->set_driver_version(gpu_info.driver_version);
907 gpu->set_driver_date(gpu_info.driver_date);
908 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
909 gpu_performance = gpu->mutable_performance_statistics();
910 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
911 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
912 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
[email protected]d6bdfae2013-01-18 20:23:01913 gpu->set_gl_vendor(gpu_info.gl_vendor);
914 gpu->set_gl_renderer(gpu_info.gl_renderer);
[email protected]bc66d532012-03-23 01:57:05915
916 const gfx::Size display_size = GetScreenSize();
917 hardware->set_primary_screen_width(display_size.width());
918 hardware->set_primary_screen_height(display_size.height());
[email protected]aa96417972012-08-22 03:16:44919 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor());
[email protected]bc66d532012-03-23 01:57:05920 hardware->set_screen_count(GetScreenCount());
921
[email protected]76869ff2013-01-15 16:13:47922#if defined(OS_WIN)
923 WriteScreenDPIInformationProto(hardware);
924#endif
925
[email protected]197c0772012-05-14 23:50:51926 WriteGoogleUpdateProto(google_update_metrics);
927
[email protected]bc66d532012-03-23 01:57:05928 bool write_as_xml = false;
929 WritePluginList(plugin_list, write_as_xml);
930
[email protected]0c8b7ad2012-11-06 07:08:14931 std::vector<ActiveGroupId> field_trial_ids;
[email protected]767c9d92012-03-02 16:04:34932 GetFieldTrialIds(&field_trial_ids);
933 WriteFieldTrials(field_trial_ids, system_profile);
[email protected]f65859e2013-02-04 20:00:25934
935#if defined(OS_CHROMEOS)
936 PerfDataProto perf_data_proto;
937 if (perf_provider_.GetPerfData(&perf_data_proto))
938 uma_proto()->add_perf_data()->Swap(&perf_data_proto);
939#endif
initial.commit09911bf2008-07-26 23:55:29940}
941
[email protected]ed0fd002012-04-25 23:10:34942void MetricsLog::RecordProfilerData(
943 const tracked_objects::ProcessDataSnapshot& process_data,
944 content::ProcessType process_type) {
945 DCHECK(!locked());
946
[email protected]8f829682012-04-27 00:36:49947 if (tracked_objects::GetTimeSourceType() !=
948 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) {
[email protected]ed0fd002012-04-25 23:10:34949 // We currently only support the default time source, wall clock time.
950 return;
951 }
952
953 ProfilerEventProto* profile;
954 if (!uma_proto()->profiler_event_size()) {
955 // For the first process's data, add a new field to the protocol buffer.
956 profile = uma_proto()->add_profiler_event();
957 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
958 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
959 } else {
960 // For the remaining calls, re-use the existing field.
961 profile = uma_proto()->mutable_profiler_event(0);
962 }
963
964 WriteProfilerData(process_data, process_type, profile);
965}
966
initial.commit09911bf2008-07-26 23:55:29967void MetricsLog::WriteAllProfilesMetrics(
968 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51969 const std::string profile_prefix(prefs::kProfilePrefix);
initial.commit09911bf2008-07-26 23:55:29970 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
971 i != all_profiles_metrics.end_keys(); ++i) {
[email protected]e7b418b2010-07-30 19:47:47972 const std::string& key_name = *i;
initial.commit09911bf2008-07-26 23:55:29973 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
[email protected]a61890e2012-07-27 22:27:11974 const DictionaryValue* profile;
[email protected]4dad9ad82009-11-25 20:47:52975 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
976 &profile))
initial.commit09911bf2008-07-26 23:55:29977 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
978 }
979 }
980}
981
[email protected]e7b418b2010-07-30 19:47:47982void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29983 const DictionaryValue& profile_metrics) {
984 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47985 WriteAttribute("profileidhash", profileidhash);
initial.commit09911bf2008-07-26 23:55:29986 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
987 i != profile_metrics.end_keys(); ++i) {
[email protected]a61890e2012-07-27 22:27:11988 const Value* value;
[email protected]4dad9ad82009-11-25 20:47:52989 if (profile_metrics.GetWithoutPathExpansion(*i, &value)) {
[email protected]0b6a4fb2012-10-16 01:58:21990 DCHECK_NE(*i, "id");
initial.commit09911bf2008-07-26 23:55:29991 switch (value->GetType()) {
992 case Value::TYPE_STRING: {
[email protected]5e324b72008-12-18 00:07:59993 std::string string_value;
initial.commit09911bf2008-07-26 23:55:29994 if (value->GetAsString(&string_value)) {
995 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47996 WriteAttribute("name", *i);
[email protected]5e324b72008-12-18 00:07:59997 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29998 }
999 break;
1000 }
1001
1002 case Value::TYPE_BOOLEAN: {
1003 bool bool_value;
1004 if (value->GetAsBoolean(&bool_value)) {
1005 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:471006 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:291007 WriteIntAttribute("value", bool_value ? 1 : 0);
1008 }
1009 break;
1010 }
1011
1012 case Value::TYPE_INTEGER: {
1013 int int_value;
1014 if (value->GetAsInteger(&int_value)) {
1015 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:471016 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:291017 WriteIntAttribute("value", int_value);
1018 }
1019 break;
1020 }
1021
1022 default:
1023 NOTREACHED();
1024 break;
1025 }
1026 }
1027 }
1028}
1029
1030void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
[email protected]767c9d92012-03-02 16:04:341031 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:291032
[email protected]fe58acc22012-02-29 01:29:581033 // Write the XML version.
[email protected]ffaf78a2008-11-12 17:38:331034 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:291035 WriteAttribute("action", "autocomplete");
1036 WriteAttribute("targetidhash", "");
1037 // TODO(kochi): Properly track windows.
1038 WriteIntAttribute("window", 0);
[email protected]6ebc3162011-12-19 13:44:001039 if (log.tab_id != -1) {
1040 // If we know what tab the autocomplete URL was opened in, log it.
1041 WriteIntAttribute("tab", static_cast<int>(log.tab_id));
1042 }
initial.commit09911bf2008-07-26 23:55:291043 WriteCommonEventAttributes();
1044
[email protected]65956312012-04-19 21:28:121045 std::vector<string16> terms;
1046 const int num_terms =
1047 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms));
[email protected]ffaf78a2008-11-12 17:38:331048 {
1049 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:291050
[email protected]ffaf78a2008-11-12 17:38:331051 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
[email protected]65956312012-04-19 21:28:121052 WriteIntAttribute("numterms", num_terms);
[email protected]ffaf78a2008-11-12 17:38:331053 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
1054 WriteIntAttribute("completedlength",
[email protected]62b3ef52013-01-18 00:13:021055 log.completed_length != string16::npos ?
1056 static_cast<int>(log.completed_length) : 0);
[email protected]9e349762012-01-31 03:24:361057 if (log.elapsed_time_since_user_first_modified_omnibox !=
1058 base::TimeDelta::FromMilliseconds(-1)) {
1059 // Only upload the typing duration if it is set/valid.
1060 WriteInt64Attribute("typingduration",
1061 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
1062 }
[email protected]381e2992008-12-16 01:41:001063 const std::string input_type(
1064 AutocompleteInput::TypeToString(log.input_type));
1065 if (!input_type.empty())
1066 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:291067
[email protected]ffaf78a2008-11-12 17:38:331068 for (AutocompleteResult::const_iterator i(log.result.begin());
1069 i != log.result.end(); ++i) {
1070 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
1071 if (i->provider)
[email protected]35f1f4f02012-09-11 13:17:001072 WriteAttribute("provider", i->provider->GetName());
[email protected]381e2992008-12-16 01:41:001073 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
1074 if (!result_type.empty())
1075 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:331076 WriteIntAttribute("relevance", i->relevance);
1077 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
1078 }
initial.commit09911bf2008-07-26 23:55:291079 }
initial.commit09911bf2008-07-26 23:55:291080
[email protected]fe58acc22012-02-29 01:29:581081 // Write the protobuf version.
[email protected]767c9d92012-03-02 16:04:341082 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
[email protected]fe58acc22012-02-29 01:29:581083 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
1084 if (log.tab_id != -1) {
1085 // If we know what tab the autocomplete URL was opened in, log it.
1086 omnibox_event->set_tab_id(log.tab_id);
1087 }
1088 omnibox_event->set_typed_length(log.text.length());
[email protected]660fe8f32012-05-03 20:01:081089 omnibox_event->set_just_deleted_text(log.just_deleted_text);
[email protected]65956312012-04-19 21:28:121090 omnibox_event->set_num_typed_terms(num_terms);
[email protected]fe58acc22012-02-29 01:29:581091 omnibox_event->set_selected_index(log.selected_index);
[email protected]62b3ef52013-01-18 00:13:021092 if (log.completed_length != string16::npos)
1093 omnibox_event->set_completed_length(log.completed_length);
[email protected]65956312012-04-19 21:28:121094 if (log.elapsed_time_since_user_first_modified_omnibox !=
1095 base::TimeDelta::FromMilliseconds(-1)) {
1096 // Only upload the typing duration if it is set/valid.
1097 omnibox_event->set_typing_duration_ms(
1098 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
1099 }
[email protected]35d55602012-11-20 23:49:031100 omnibox_event->set_duration_since_last_default_match_update_ms(
1101 log.elapsed_time_since_last_change_to_default_match.InMilliseconds());
[email protected]ee902532012-05-01 23:54:491102 omnibox_event->set_current_page_classification(
1103 log.current_page_classification);
[email protected]fe58acc22012-02-29 01:29:581104 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
1105 for (AutocompleteResult::const_iterator i(log.result.begin());
1106 i != log.result.end(); ++i) {
1107 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
[email protected]0e9e8782012-05-15 23:01:511108 suggestion->set_provider(i->provider->AsOmniboxEventProviderType());
[email protected]fe58acc22012-02-29 01:29:581109 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
1110 suggestion->set_relevance(i->relevance);
[email protected]cf6256f2012-06-12 23:36:011111 if (i->typed_count != -1)
1112 suggestion->set_typed_count(i->typed_count);
[email protected]fe58acc22012-02-29 01:29:581113 suggestion->set_is_starred(i->starred);
1114 }
[email protected]0e9e8782012-05-15 23:01:511115 for (ProvidersInfo::const_iterator i(log.providers_info.begin());
1116 i != log.providers_info.end(); ++i) {
1117 OmniboxEventProto::ProviderInfo* provider_info =
1118 omnibox_event->add_provider_info();
1119 provider_info->CopyFrom(*i);
1120 }
[email protected]fe58acc22012-02-29 01:29:581121
initial.commit09911bf2008-07-26 23:55:291122 ++num_events_;
1123}
[email protected]197c0772012-05-14 23:50:511124
1125void MetricsLog::WriteGoogleUpdateProto(
1126 const GoogleUpdateMetrics& google_update_metrics) {
1127#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
1128 SystemProfileProto::GoogleUpdate* google_update =
1129 uma_proto()->mutable_system_profile()->mutable_google_update();
1130
1131 google_update->set_is_system_install(google_update_metrics.is_system_install);
1132
1133 if (!google_update_metrics.last_started_au.is_null()) {
1134 google_update->set_last_automatic_start_timestamp(
1135 google_update_metrics.last_started_au.ToTimeT());
1136 }
1137
1138 if (!google_update_metrics.last_checked.is_null()) {
1139 google_update->set_last_update_check_timestamp(
1140 google_update_metrics.last_checked.ToTimeT());
1141 }
1142
1143 if (!google_update_metrics.google_update_data.version.empty()) {
1144 ProductDataToProto(google_update_metrics.google_update_data,
1145 google_update->mutable_google_update_status());
1146 }
1147
1148 if (!google_update_metrics.product_data.version.empty()) {
1149 ProductDataToProto(google_update_metrics.product_data,
1150 google_update->mutable_client_status());
1151 }
1152#endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
1153}