blob: 87a92d8ba4634eb93f6d3d6b3ef8e6d82a324069 [file] [log] [blame]
[email protected]1df44b72012-01-19 05:20:341// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]cd1adc22009-01-16 01:29:225#include "chrome/browser/metrics/metrics_log.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]1eeb5e02010-07-20 23:02:117#include <string>
8#include <vector>
9
[email protected]d1be67b2008-11-19 20:28:3810#include "base/basictypes.h"
initial.commit09911bf2008-07-26 23:55:2911#include "base/file_util.h"
[email protected]054c8012011-11-16 00:12:4212#include "base/lazy_instance.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/scoped_ptr.h"
[email protected]85ed9d42010-06-08 22:37:4414#include "base/perftimer.h"
[email protected]ed0fd002012-04-25 23:10:3415#include "base/profiler/alternate_timer.h"
[email protected]fe58acc22012-02-29 01:29:5816#include "base/string_number_conversions.h"
initial.commit09911bf2008-07-26 23:55:2917#include "base/string_util.h"
[email protected]fadf97f2008-09-18 12:18:1418#include "base/sys_info.h"
[email protected]37f39e42010-01-06 17:35:1719#include "base/third_party/nspr/prtime.h"
[email protected]1eeb5e02010-07-20 23:02:1120#include "base/time.h"
[email protected]ed0fd002012-04-25 23:10:3421#include "base/tracked_objects.h"
[email protected]1eeb5e02010-07-20 23:02:1122#include "base/utf_string_conversions.h"
initial.commit09911bf2008-07-26 23:55:2923#include "chrome/browser/autocomplete/autocomplete.h"
[email protected]19871a92012-06-27 19:50:3224#include "chrome/browser/autocomplete/autocomplete_log.h"
[email protected]9ac40092010-10-27 23:05:2625#include "chrome/browser/autocomplete/autocomplete_match.h"
[email protected]30f5bc92012-06-26 04:14:5526#include "chrome/browser/autocomplete/autocomplete_provider.h"
[email protected]73c2b1632012-07-02 22:51:3827#include "chrome/browser/autocomplete/autocomplete_result.h"
initial.commit09911bf2008-07-26 23:55:2928#include "chrome/browser/browser_process.h"
[email protected]10084982011-08-19 17:56:5629#include "chrome/browser/plugin_prefs.h"
[email protected]37858e52010-08-26 00:22:0230#include "chrome/browser/prefs/pref_service.h"
[email protected]10084982011-08-19 17:56:5631#include "chrome/browser/profiles/profile_manager.h"
[email protected]1eeb5e02010-07-20 23:02:1132#include "chrome/common/chrome_version_info.h"
initial.commit09911bf2008-07-26 23:55:2933#include "chrome/common/logging_chrome.h"
[email protected]ad2461c2012-04-27 21:11:0334#include "chrome/common/metrics/experiments_helper.h"
[email protected]fe58acc22012-02-29 01:29:5835#include "chrome/common/metrics/proto/omnibox_event.pb.h"
[email protected]ed0fd002012-04-25 23:10:3436#include "chrome/common/metrics/proto/profiler_event.pb.h"
[email protected]fe58acc22012-02-29 01:29:5837#include "chrome/common/metrics/proto/system_profile.pb.h"
initial.commit09911bf2008-07-26 23:55:2938#include "chrome/common/pref_names.h"
[email protected]197c0772012-05-14 23:50:5139#include "chrome/installer/util/google_update_settings.h"
[email protected]fe58acc22012-02-29 01:29:5840#include "content/public/browser/content_browser_client.h"
[email protected]79078df2012-02-16 01:22:3241#include "content/public/browser/gpu_data_manager.h"
[email protected]1a838cc2012-04-24 22:06:4942#include "content/public/common/content_client.h"
[email protected]ed0fd002012-04-25 23:10:3443#include "content/public/common/gpu_info.h"
[email protected]46072d42008-07-28 14:49:3544#include "googleurl/src/gurl.h"
[email protected]6b7d954ff2011-10-25 00:39:3545#include "ui/gfx/screen.h"
[email protected]91d9f3d2011-08-14 05:24:4446#include "webkit/plugins/webplugininfo.h"
initial.commit09911bf2008-07-26 23:55:2947
48#define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
49
[email protected]d1be67b2008-11-19 20:28:3850// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
51#if defined(OS_WIN)
52extern "C" IMAGE_DOS_HEADER __ImageBase;
53#endif
54
[email protected]79078df2012-02-16 01:22:3255using content::GpuDataManager;
[email protected]fe58acc22012-02-29 01:29:5856using metrics::OmniboxEventProto;
[email protected]ed0fd002012-04-25 23:10:3457using metrics::ProfilerEventProto;
[email protected]fe58acc22012-02-29 01:29:5858using metrics::SystemProfileProto;
[email protected]ed0fd002012-04-25 23:10:3459using tracked_objects::ProcessDataSnapshot;
[email protected]ad2461c2012-04-27 21:11:0360typedef experiments_helper::SelectedGroupId SelectedGroupId;
[email protected]197c0772012-05-14 23:50:5161typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo;
[email protected]79078df2012-02-16 01:22:3262
[email protected]1df44b72012-01-19 05:20:3463namespace {
64
65// Returns the date at which the current metrics client ID was created as
66// a string containing milliseconds since the epoch, or "0" if none was found.
[email protected]767c9d92012-03-02 16:04:3467std::string GetInstallDate(PrefService* pref) {
68 if (!pref) {
[email protected]1df44b72012-01-19 05:20:3469 NOTREACHED();
70 return "0";
71 }
[email protected]767c9d92012-03-02 16:04:3472
73 return pref->GetString(prefs::kMetricsClientIDTimestamp);
[email protected]1df44b72012-01-19 05:20:3474}
75
[email protected]fe58acc22012-02-29 01:29:5876OmniboxEventProto::InputType AsOmniboxEventInputType(
77 AutocompleteInput::Type type) {
78 switch (type) {
79 case AutocompleteInput::INVALID:
80 return OmniboxEventProto::INVALID;
81 case AutocompleteInput::UNKNOWN:
82 return OmniboxEventProto::UNKNOWN;
83 case AutocompleteInput::REQUESTED_URL:
84 return OmniboxEventProto::REQUESTED_URL;
85 case AutocompleteInput::URL:
86 return OmniboxEventProto::URL;
87 case AutocompleteInput::QUERY:
88 return OmniboxEventProto::QUERY;
89 case AutocompleteInput::FORCED_QUERY:
90 return OmniboxEventProto::FORCED_QUERY;
91 default:
92 NOTREACHED();
93 return OmniboxEventProto::INVALID;
94 }
95}
96
[email protected]fe58acc22012-02-29 01:29:5897OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
98 AutocompleteMatch::Type type) {
99 switch (type) {
100 case AutocompleteMatch::URL_WHAT_YOU_TYPED:
101 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
102 case AutocompleteMatch::HISTORY_URL:
103 return OmniboxEventProto::Suggestion::HISTORY_URL;
104 case AutocompleteMatch::HISTORY_TITLE:
105 return OmniboxEventProto::Suggestion::HISTORY_TITLE;
106 case AutocompleteMatch::HISTORY_BODY:
107 return OmniboxEventProto::Suggestion::HISTORY_BODY;
108 case AutocompleteMatch::HISTORY_KEYWORD:
109 return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
110 case AutocompleteMatch::NAVSUGGEST:
111 return OmniboxEventProto::Suggestion::NAVSUGGEST;
112 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
113 return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
114 case AutocompleteMatch::SEARCH_HISTORY:
115 return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
116 case AutocompleteMatch::SEARCH_SUGGEST:
117 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
118 case AutocompleteMatch::SEARCH_OTHER_ENGINE:
119 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
120 case AutocompleteMatch::EXTENSION_APP:
121 return OmniboxEventProto::Suggestion::EXTENSION_APP;
122 default:
123 NOTREACHED();
124 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
125 }
126}
127
[email protected]ed0fd002012-04-25 23:10:34128ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType(
129 content::ProcessType process_type) {
130 switch (process_type) {
131 case content::PROCESS_TYPE_BROWSER:
132 return ProfilerEventProto::TrackedObject::BROWSER;
133 case content::PROCESS_TYPE_RENDERER:
134 return ProfilerEventProto::TrackedObject::RENDERER;
135 case content::PROCESS_TYPE_PLUGIN:
136 return ProfilerEventProto::TrackedObject::PLUGIN;
137 case content::PROCESS_TYPE_WORKER:
138 return ProfilerEventProto::TrackedObject::WORKER;
139 case content::PROCESS_TYPE_NACL_LOADER:
140 return ProfilerEventProto::TrackedObject::NACL_LOADER;
141 case content::PROCESS_TYPE_UTILITY:
142 return ProfilerEventProto::TrackedObject::UTILITY;
143 case content::PROCESS_TYPE_PROFILE_IMPORT:
144 return ProfilerEventProto::TrackedObject::PROFILE_IMPORT;
145 case content::PROCESS_TYPE_ZYGOTE:
146 return ProfilerEventProto::TrackedObject::ZYGOTE;
147 case content::PROCESS_TYPE_SANDBOX_HELPER:
148 return ProfilerEventProto::TrackedObject::SANDBOX_HELPER;
149 case content::PROCESS_TYPE_NACL_BROKER:
150 return ProfilerEventProto::TrackedObject::NACL_BROKER;
151 case content::PROCESS_TYPE_GPU:
152 return ProfilerEventProto::TrackedObject::GPU;
153 case content::PROCESS_TYPE_PPAPI_PLUGIN:
154 return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN;
155 case content::PROCESS_TYPE_PPAPI_BROKER:
156 return ProfilerEventProto::TrackedObject::PPAPI_BROKER;
157 default:
158 NOTREACHED();
159 return ProfilerEventProto::TrackedObject::UNKNOWN;
160 }
161}
162
[email protected]1df44b72012-01-19 05:20:34163// Returns the plugin preferences corresponding for this user, if available.
164// If multiple user profiles are loaded, returns the preferences corresponding
165// to an arbitrary one of the profiles.
166PluginPrefs* GetPluginPrefs() {
167 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]fe58acc22012-02-29 01:29:58168
169 if (!profile_manager) {
170 // The profile manager can be NULL when testing.
171 return NULL;
172 }
173
[email protected]1df44b72012-01-19 05:20:34174 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
175 if (profiles.empty())
176 return NULL;
177
178 return PluginPrefs::GetForProfile(profiles.front());
179}
180
[email protected]fe58acc22012-02-29 01:29:58181// Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
182void SetPluginInfo(const webkit::WebPluginInfo& plugin_info,
183 const PluginPrefs* plugin_prefs,
184 SystemProfileProto::Plugin* plugin) {
185 plugin->set_name(UTF16ToUTF8(plugin_info.name));
186 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
187 plugin->set_version(UTF16ToUTF8(plugin_info.version));
188 if (plugin_prefs)
189 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
190}
191
[email protected]ad2461c2012-04-27 21:11:03192void WriteFieldTrials(const std::vector<SelectedGroupId>& field_trial_ids,
[email protected]767c9d92012-03-02 16:04:34193 SystemProfileProto* system_profile) {
[email protected]ad2461c2012-04-27 21:11:03194 for (std::vector<SelectedGroupId>::const_iterator it =
195 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
[email protected]767c9d92012-03-02 16:04:34196 SystemProfileProto::FieldTrial* field_trial =
197 system_profile->add_field_trial();
198 field_trial->set_name_id(it->name);
199 field_trial->set_group_id(it->group);
200 }
201}
202
[email protected]ed0fd002012-04-25 23:10:34203void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
204 content::ProcessType process_type,
205 ProfilerEventProto* performance_profile) {
206 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it =
207 profiler_data.tasks.begin();
208 it != profiler_data.tasks.end(); ++it) {
209 std::string ignored;
210 uint64 birth_thread_name_hash;
211 uint64 exec_thread_name_hash;
212 uint64 source_file_name_hash;
213 uint64 source_function_name_hash;
214 MetricsLogBase::CreateHashes(it->birth.thread_name,
215 &ignored, &birth_thread_name_hash);
216 MetricsLogBase::CreateHashes(it->death_thread_name,
217 &ignored, &exec_thread_name_hash);
218 MetricsLogBase::CreateHashes(it->birth.location.function_name,
219 &ignored, &source_file_name_hash);
220 MetricsLogBase::CreateHashes(it->birth.location.file_name,
221 &ignored, &source_function_name_hash);
222
223 const tracked_objects::DeathDataSnapshot& death_data = it->death_data;
224 ProfilerEventProto::TrackedObject* tracked_object =
225 performance_profile->add_tracked_object();
226 tracked_object->set_birth_thread_name_hash(birth_thread_name_hash);
227 tracked_object->set_exec_thread_name_hash(exec_thread_name_hash);
228 tracked_object->set_source_file_name_hash(source_file_name_hash);
229 tracked_object->set_source_function_name_hash(source_function_name_hash);
230 tracked_object->set_source_line_number(it->birth.location.line_number);
231 tracked_object->set_exec_count(death_data.count);
232 tracked_object->set_exec_time_total(death_data.run_duration_sum);
233 tracked_object->set_exec_time_sampled(death_data.run_duration_sample);
234 tracked_object->set_queue_time_total(death_data.queue_duration_sum);
235 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample);
236 tracked_object->set_process_type(AsProtobufProcessType(process_type));
237 tracked_object->set_process_id(profiler_data.process_id);
238 }
239}
240
[email protected]197c0772012-05-14 23:50:51241void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data,
242 ProductInfo* product_info) {
243 product_info->set_version(product_data.version);
244 product_info->set_last_update_success_timestamp(
245 product_data.last_success.ToTimeT());
246 product_info->set_last_error(product_data.last_error_code);
247 product_info->set_last_extra_error(product_data.last_extra_code);
248 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) {
249 product_info->set_last_result(
250 static_cast<ProductInfo::InstallResult>(product_data.last_result));
251 }
252}
253
[email protected]1df44b72012-01-19 05:20:34254} // namespace
255
[email protected]197c0772012-05-14 23:50:51256GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {}
257
258GoogleUpdateMetrics::~GoogleUpdateMetrics() {}
259
[email protected]67f92bc32012-01-26 01:56:19260static base::LazyInstance<std::string>::Leaky
[email protected]054c8012011-11-16 00:12:42261 g_version_extension = LAZY_INSTANCE_INITIALIZER;
262
[email protected]1226abb2010-06-10 18:01:28263MetricsLog::MetricsLog(const std::string& client_id, int session_id)
264 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:41265
[email protected]1226abb2010-06-10 18:01:28266MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:29267
268// static
269void MetricsLog::RegisterPrefs(PrefService* local_state) {
270 local_state->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29271}
272
[email protected]1df44b72012-01-19 05:20:34273// static
[email protected]9165f742010-03-10 22:55:01274int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
275 base::TimeTicks now = base::TimeTicks::Now();
276 static base::TimeTicks last_updated_time(now);
277 int64 incremental_time = (now - last_updated_time).InSeconds();
278 last_updated_time = now;
279
280 if (incremental_time > 0) {
281 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
282 metrics_uptime += incremental_time;
283 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
284 }
285
286 return incremental_time;
287}
288
[email protected]1226abb2010-06-10 18:01:28289// static
290std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:42291 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:17292 if (!version_info.is_valid()) {
293 NOTREACHED() << "Unable to retrieve version info.";
294 return std::string();
295 }
296
[email protected]0211f57e2010-08-27 20:28:42297 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:42298 if (!version_extension().empty())
299 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:42300 if (!version_info.IsOfficialBuild())
301 version.append("-devel");
302 return version;
[email protected]1226abb2010-06-10 18:01:28303}
304
[email protected]054c8012011-11-16 00:12:42305// static
306void MetricsLog::set_version_extension(const std::string& extension) {
307 g_version_extension.Get() = extension;
308}
309
310// static
311const std::string& MetricsLog::version_extension() {
312 return g_version_extension.Get();
313}
314
[email protected]fe58acc22012-02-29 01:29:58315void MetricsLog::RecordIncrementalStabilityElements(
316 const std::vector<webkit::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34317 DCHECK(!locked());
[email protected]0b33f80b2008-12-17 21:34:36318
[email protected]767c9d92012-03-02 16:04:34319 PrefService* pref = GetPrefService();
[email protected]0b33f80b2008-12-17 21:34:36320 DCHECK(pref);
321
[email protected]147bbc0b2009-01-06 19:37:40322 OPEN_ELEMENT_FOR_SCOPE("profile");
323 WriteCommonEventAttributes();
324
[email protected]9958a322011-03-08 20:04:17325 WriteInstallElement();
[email protected]147bbc0b2009-01-06 19:37:40326
327 {
328 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
329 WriteRequiredStabilityAttributes(pref);
330 WriteRealtimeStabilityAttributes(pref);
331
[email protected]fe58acc22012-02-29 01:29:58332 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40333 }
[email protected]0b33f80b2008-12-17 21:34:36334}
335
[email protected]767c9d92012-03-02 16:04:34336PrefService* MetricsLog::GetPrefService() {
337 return g_browser_process->local_state();
338}
339
340gfx::Size MetricsLog::GetScreenSize() const {
[email protected]42c0a0c62012-06-17 03:50:33341 return gfx::Screen::GetPrimaryDisplay().GetSizeInPixel();
[email protected]767c9d92012-03-02 16:04:34342}
343
344int MetricsLog::GetScreenCount() const {
[email protected]42c0a0c62012-06-17 03:50:33345 return gfx::Screen::GetNumDisplays();
[email protected]767c9d92012-03-02 16:04:34346}
347
[email protected]767c9d92012-03-02 16:04:34348void MetricsLog::GetFieldTrialIds(
[email protected]ad2461c2012-04-27 21:11:03349 std::vector<SelectedGroupId>* field_trial_ids) const {
350 experiments_helper::GetFieldTrialSelectedGroupIds(field_trial_ids);
[email protected]767c9d92012-03-02 16:04:34351}
352
[email protected]fe58acc22012-02-29 01:29:58353void MetricsLog::WriteStabilityElement(
354 const std::vector<webkit::WebPluginInfo>& plugin_list,
355 PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:34356 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29357
initial.commit09911bf2008-07-26 23:55:29358 // Get stability attributes out of Local State, zeroing out stored values.
359 // NOTE: This could lead to some data loss if this report isn't successfully
360 // sent, but that's true for all the metrics.
361
[email protected]ffaf78a2008-11-12 17:38:33362 OPEN_ELEMENT_FOR_SCOPE("stability");
[email protected]147bbc0b2009-01-06 19:37:40363 WriteRequiredStabilityAttributes(pref);
364 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29365
[email protected]fe58acc22012-02-29 01:29:58366 int incomplete_shutdown_count =
367 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
[email protected]e324f6b2012-02-28 05:43:37368 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58369 int breakpad_registration_success_count =
370 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
[email protected]e324f6b2012-02-28 05:43:37371 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58372 int breakpad_registration_failure_count =
373 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
[email protected]e324f6b2012-02-28 05:43:37374 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58375 int debugger_present_count =
376 pref->GetInteger(prefs::kStabilityDebuggerPresent);
[email protected]e324f6b2012-02-28 05:43:37377 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58378 int debugger_not_present_count =
379 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
[email protected]e324f6b2012-02-28 05:43:37380 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31381
[email protected]fe58acc22012-02-29 01:29:58382 // TODO(jar): The following are all optional, so we *could* optimize them for
383 // values of zero (and not include them).
384
385 // Write the XML version.
386 WriteIntAttribute("incompleteshutdowncount", incomplete_shutdown_count);
387 WriteIntAttribute("breakpadregistrationok",
388 breakpad_registration_success_count);
389 WriteIntAttribute("breakpadregistrationfail",
390 breakpad_registration_failure_count);
391 WriteIntAttribute("debuggerpresent", debugger_present_count);
392 WriteIntAttribute("debuggernotpresent", debugger_not_present_count);
393
394 // Write the protobuf version.
395 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34396 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58397 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
398 stability->set_breakpad_registration_success_count(
399 breakpad_registration_success_count);
400 stability->set_breakpad_registration_failure_count(
401 breakpad_registration_failure_count);
402 stability->set_debugger_present_count(debugger_present_count);
403 stability->set_debugger_not_present_count(debugger_not_present_count);
404
405 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40406}
407
[email protected]fe58acc22012-02-29 01:29:58408void MetricsLog::WritePluginStabilityElements(
409 const std::vector<webkit::WebPluginInfo>& plugin_list,
410 PrefService* pref) {
[email protected]147bbc0b2009-01-06 19:37:40411 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29412 const ListValue* plugin_stats_list = pref->GetList(
413 prefs::kStabilityPluginStats);
[email protected]1df44b72012-01-19 05:20:34414 if (!plugin_stats_list)
415 return;
initial.commit09911bf2008-07-26 23:55:29416
[email protected]1df44b72012-01-19 05:20:34417 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]fe58acc22012-02-29 01:29:58418 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34419 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58420 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]1df44b72012-01-19 05:20:34421 for (ListValue::const_iterator iter = plugin_stats_list->begin();
422 iter != plugin_stats_list->end(); ++iter) {
423 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
424 NOTREACHED();
425 continue;
initial.commit09911bf2008-07-26 23:55:29426 }
[email protected]1df44b72012-01-19 05:20:34427 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29428
[email protected]1df44b72012-01-19 05:20:34429 std::string plugin_name;
430 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
431
[email protected]fe58acc22012-02-29 01:29:58432 std::string base64_name_hash;
433 uint64 numeric_name_hash_ignored;
434 CreateHashes(plugin_name, &base64_name_hash, &numeric_name_hash_ignored);
435
436 // Write the XML verison.
[email protected]1df44b72012-01-19 05:20:34437 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
438 // Use "filename" instead of "name", otherwise we need to update the
439 // UMA servers.
[email protected]fe58acc22012-02-29 01:29:58440 WriteAttribute("filename", base64_name_hash);
[email protected]1df44b72012-01-19 05:20:34441
442 int launches = 0;
443 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
444 WriteIntAttribute("launchcount", launches);
445
446 int instances = 0;
447 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
448 WriteIntAttribute("instancecount", instances);
449
450 int crashes = 0;
451 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
452 WriteIntAttribute("crashcount", crashes);
[email protected]fe58acc22012-02-29 01:29:58453
454 // Write the protobuf version.
455 // Note that this search is potentially a quadratic operation, but given the
456 // low number of plugins installed on a "reasonable" setup, this should be
457 // fine.
458 // TODO(isherman): Verify that this does not show up as a hotspot in
459 // profiler runs.
460 const webkit::WebPluginInfo* plugin_info = NULL;
461 const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name);
462 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
463 plugin_list.begin();
464 iter != plugin_list.end(); ++iter) {
465 if (iter->name == plugin_name_utf16) {
466 plugin_info = &(*iter);
467 break;
468 }
469 }
470
471 if (!plugin_info) {
472 NOTREACHED();
473 continue;
474 }
[email protected]cd937072012-07-02 09:00:29475 int loading_errors = 0;
476 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors,
477 &loading_errors);
478 WriteIntAttribute("loadingerrorcount", loading_errors);
[email protected]fe58acc22012-02-29 01:29:58479
[email protected]cd937072012-07-02 09:00:29480 // Write the protobuf version.
[email protected]fe58acc22012-02-29 01:29:58481 SystemProfileProto::Stability::PluginStability* plugin_stability =
482 stability->add_plugin_stability();
483 SetPluginInfo(*plugin_info, plugin_prefs,
484 plugin_stability->mutable_plugin());
485 plugin_stability->set_launch_count(launches);
486 plugin_stability->set_instance_count(instances);
487 plugin_stability->set_crash_count(crashes);
[email protected]cd937072012-07-02 09:00:29488 plugin_stability->set_loading_error_count(loading_errors);
initial.commit09911bf2008-07-26 23:55:29489 }
[email protected]1df44b72012-01-19 05:20:34490
491 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29492}
493
[email protected]fe58acc22012-02-29 01:29:58494// The server refuses data that doesn't have certain values. crashcount and
495// launchcount are currently "required" in the "stability" group.
496// TODO(isherman): Stop writing these attributes specially once the migration to
497// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40498void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]fe58acc22012-02-29 01:29:58499 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
[email protected]0b33f80b2008-12-17 21:34:36500 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
[email protected]fe58acc22012-02-29 01:29:58501 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
[email protected]0b33f80b2008-12-17 21:34:36502 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58503
504 // Write the XML version.
505 WriteIntAttribute("launchcount", launch_count);
506 WriteIntAttribute("crashcount", crash_count);
507
508 // Write the protobuf version.
509 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34510 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58511 stability->set_launch_count(launch_count);
512 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36513}
514
[email protected]147bbc0b2009-01-06 19:37:40515void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36516 // Update the stats which are critical for real-time stability monitoring.
517 // Since these are "optional," only list ones that are non-zero, as the counts
518 // are aggergated (summed) server side.
519
[email protected]fe58acc22012-02-29 01:29:58520 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34521 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36522 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
523 if (count) {
524 WriteIntAttribute("pageloadcount", count);
[email protected]fe58acc22012-02-29 01:29:58525 stability->set_page_load_count(count);
[email protected]0b33f80b2008-12-17 21:34:36526 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
527 }
528
529 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
530 if (count) {
531 WriteIntAttribute("renderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58532 stability->set_renderer_crash_count(count);
[email protected]0b33f80b2008-12-17 21:34:36533 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
534 }
535
[email protected]1f085622009-12-04 05:33:45536 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
537 if (count) {
538 WriteIntAttribute("extensionrenderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58539 stability->set_extension_renderer_crash_count(count);
[email protected]1f085622009-12-04 05:33:45540 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
541 }
542
[email protected]0b33f80b2008-12-17 21:34:36543 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
544 if (count) {
545 WriteIntAttribute("rendererhangcount", count);
[email protected]fe58acc22012-02-29 01:29:58546 stability->set_renderer_hang_count(count);
[email protected]0b33f80b2008-12-17 21:34:36547 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
548 }
[email protected]1f085622009-12-04 05:33:45549
550 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
551 if (count) {
552 WriteIntAttribute("childprocesscrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58553 stability->set_child_process_crash_count(count);
[email protected]1f085622009-12-04 05:33:45554 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
555 }
[email protected]9165f742010-03-10 22:55:01556
[email protected]c1834a92011-01-21 18:21:03557#if defined(OS_CHROMEOS)
558 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
559 if (count) {
[email protected]fe58acc22012-02-29 01:29:58560 stability->set_other_user_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03561 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
562 }
563
564 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
565 if (count) {
[email protected]fe58acc22012-02-29 01:29:58566 stability->set_kernel_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03567 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
568 }
569
570 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
571 if (count) {
[email protected]fe58acc22012-02-29 01:29:58572 stability->set_unclean_system_shutdown_count(count);
[email protected]c1834a92011-01-21 18:21:03573 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
574 }
575#endif // OS_CHROMEOS
576
[email protected]9165f742010-03-10 22:55:01577 int64 recent_duration = GetIncrementalUptime(pref);
[email protected]fe58acc22012-02-29 01:29:58578 if (recent_duration) {
[email protected]9165f742010-03-10 22:55:01579 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]fe58acc22012-02-29 01:29:58580 stability->set_uptime_sec(recent_duration);
581 }
[email protected]0b33f80b2008-12-17 21:34:36582}
583
initial.commit09911bf2008-07-26 23:55:29584void MetricsLog::WritePluginList(
[email protected]bc66d532012-03-23 01:57:05585 const std::vector<webkit::WebPluginInfo>& plugin_list,
586 bool write_as_xml) {
[email protected]767c9d92012-03-02 16:04:34587 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29588
[email protected]1df44b72012-01-19 05:20:34589 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]10084982011-08-19 17:56:56590
[email protected]ffaf78a2008-11-12 17:38:33591 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]767c9d92012-03-02 16:04:34592 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]91d9f3d2011-08-14 05:24:44593 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50594 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29595 iter != plugin_list.end(); ++iter) {
[email protected]bc66d532012-03-23 01:57:05596 if (write_as_xml) {
597 std::string base64_name_hash;
598 uint64 numeric_hash_ignored;
599 CreateHashes(UTF16ToUTF8(iter->name), &base64_name_hash,
600 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58601
[email protected]bc66d532012-03-23 01:57:05602 std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe();
603 std::string base64_filename_hash;
604 CreateHashes(filename_bytes, &base64_filename_hash,
605 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58606
[email protected]bc66d532012-03-23 01:57:05607 // Write the XML version.
608 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29609
[email protected]bc66d532012-03-23 01:57:05610 // Plugin name and filename are hashed for the privacy of those
611 // testing unreleased new extensions.
612 WriteAttribute("name", base64_name_hash);
613 WriteAttribute("filename", base64_filename_hash);
614 WriteAttribute("version", UTF16ToUTF8(iter->version));
615 if (plugin_prefs)
616 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
617 } else {
618 // Write the protobuf version.
619 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
620 SetPluginInfo(*iter, plugin_prefs, plugin);
621 }
initial.commit09911bf2008-07-26 23:55:29622 }
initial.commit09911bf2008-07-26 23:55:29623}
624
[email protected]147bbc0b2009-01-06 19:37:40625void MetricsLog::WriteInstallElement() {
[email protected]fe58acc22012-02-29 01:29:58626 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05627 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]147bbc0b2009-01-06 19:37:40628 OPEN_ELEMENT_FOR_SCOPE("install");
[email protected]bc66d532012-03-23 01:57:05629 WriteAttribute("installdate", GetInstallDate(GetPrefService()));
[email protected]147bbc0b2009-01-06 19:37:40630 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40631}
632
initial.commit09911bf2008-07-26 23:55:29633void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44634 const std::vector<webkit::WebPluginInfo>& plugin_list,
[email protected]197c0772012-05-14 23:50:51635 const GoogleUpdateMetrics& google_update_metrics,
initial.commit09911bf2008-07-26 23:55:29636 const DictionaryValue* profile_metrics) {
[email protected]767c9d92012-03-02 16:04:34637 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29638
[email protected]767c9d92012-03-02 16:04:34639 PrefService* pref = GetPrefService();
initial.commit09911bf2008-07-26 23:55:29640
[email protected]ffaf78a2008-11-12 17:38:33641 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29642 WriteCommonEventAttributes();
643
[email protected]147bbc0b2009-01-06 19:37:40644 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29645
[email protected]bc66d532012-03-23 01:57:05646 // Write the XML version.
647 // We'll write the protobuf version in RecordEnvironmentProto().
648 bool write_as_xml = true;
649 WritePluginList(plugin_list, write_as_xml);
initial.commit09911bf2008-07-26 23:55:29650
[email protected]fe58acc22012-02-29 01:29:58651 WriteStabilityElement(plugin_list, pref);
initial.commit09911bf2008-07-26 23:55:29652
653 {
[email protected]fe58acc22012-02-29 01:29:58654 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05655 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29656 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]bc66d532012-03-23 01:57:05657 WriteAttribute("arch", base::SysInfo::CPUArchitecture());
initial.commit09911bf2008-07-26 23:55:29658 }
659
660 {
[email protected]fe58acc22012-02-29 01:29:58661 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05662 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29663 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]bc66d532012-03-23 01:57:05664 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38665#if defined(OS_WIN)
666 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
667#endif
initial.commit09911bf2008-07-26 23:55:29668 }
669
670 {
[email protected]fe58acc22012-02-29 01:29:58671 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05672 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29673 OPEN_ELEMENT_FOR_SCOPE("os");
[email protected]bc66d532012-03-23 01:57:05674 WriteAttribute("name", base::SysInfo::OperatingSystemName());
675 WriteAttribute("version", base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29676 }
677
678 {
[email protected]e8c287c872010-07-20 00:49:42679 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]fe58acc22012-02-29 01:29:58680 const content::GPUInfo& gpu_info =
681 GpuDataManager::GetInstance()->GetGPUInfo();
[email protected]fe58acc22012-02-29 01:29:58682
683 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05684 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]a094e2c2012-05-10 23:02:42685 WriteIntAttribute("vendorid", gpu_info.gpu.vendor_id);
686 WriteIntAttribute("deviceid", gpu_info.gpu.device_id);
[email protected]e8c287c872010-07-20 00:49:42687 }
688
689 {
[email protected]767c9d92012-03-02 16:04:34690 const gfx::Size display_size = GetScreenSize();
[email protected]fe58acc22012-02-29 01:29:58691
692 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05693 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]fe58acc22012-02-29 01:29:58694 OPEN_ELEMENT_FOR_SCOPE("display");
[email protected]bc66d532012-03-23 01:57:05695 WriteIntAttribute("xsize", display_size.width());
696 WriteIntAttribute("ysize", display_size.height());
697 WriteIntAttribute("screens", GetScreenCount());
initial.commit09911bf2008-07-26 23:55:29698 }
699
700 {
701 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
702 int num_bookmarks_on_bookmark_bar =
703 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
704 int num_folders_on_bookmark_bar =
705 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
706 int num_bookmarks_in_other_bookmarks_folder =
707 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
708 int num_folders_in_other_bookmarks_folder =
709 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
710 {
711 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
712 WriteAttribute("name", "full-tree");
713 WriteIntAttribute("foldercount",
714 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
715 WriteIntAttribute("itemcount",
716 num_bookmarks_on_bookmark_bar +
717 num_bookmarks_in_other_bookmarks_folder);
718 }
719 {
720 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
721 WriteAttribute("name", "toolbar");
722 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
723 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
724 }
725 }
726
727 {
728 OPEN_ELEMENT_FOR_SCOPE("keywords");
729 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
730 }
731
732 if (profile_metrics)
733 WriteAllProfilesMetrics(*profile_metrics);
[email protected]767c9d92012-03-02 16:04:34734
[email protected]197c0772012-05-14 23:50:51735 RecordEnvironmentProto(plugin_list, google_update_metrics);
[email protected]bc66d532012-03-23 01:57:05736}
737
738void MetricsLog::RecordEnvironmentProto(
[email protected]197c0772012-05-14 23:50:51739 const std::vector<webkit::WebPluginInfo>& plugin_list,
740 const GoogleUpdateMetrics& google_update_metrics) {
[email protected]bc66d532012-03-23 01:57:05741 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
742 int install_date;
743 bool success = base::StringToInt(GetInstallDate(GetPrefService()),
744 &install_date);
745 DCHECK(success);
746 system_profile->set_install_date(install_date);
747
748 system_profile->set_application_locale(
749 content::GetContentClient()->browser()->GetApplicationLocale());
750
751 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
752 hardware->set_cpu_architecture(base::SysInfo::CPUArchitecture());
753 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
754#if defined(OS_WIN)
755 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
756#endif
757
758 SystemProfileProto::OS* os = system_profile->mutable_os();
759 os->set_name(base::SysInfo::OperatingSystemName());
760 os->set_version(base::SysInfo::OperatingSystemVersion());
761
762 const content::GPUInfo& gpu_info =
763 GpuDataManager::GetInstance()->GetGPUInfo();
764 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
[email protected]a094e2c2012-05-10 23:02:42765 gpu->set_vendor_id(gpu_info.gpu.vendor_id);
766 gpu->set_device_id(gpu_info.gpu.device_id);
[email protected]bc66d532012-03-23 01:57:05767 gpu->set_driver_version(gpu_info.driver_version);
768 gpu->set_driver_date(gpu_info.driver_date);
769 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
770 gpu_performance = gpu->mutable_performance_statistics();
771 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
772 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
773 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
774
775 const gfx::Size display_size = GetScreenSize();
776 hardware->set_primary_screen_width(display_size.width());
777 hardware->set_primary_screen_height(display_size.height());
778 hardware->set_screen_count(GetScreenCount());
779
[email protected]197c0772012-05-14 23:50:51780 WriteGoogleUpdateProto(google_update_metrics);
781
[email protected]bc66d532012-03-23 01:57:05782 bool write_as_xml = false;
783 WritePluginList(plugin_list, write_as_xml);
784
[email protected]ad2461c2012-04-27 21:11:03785 std::vector<SelectedGroupId> field_trial_ids;
[email protected]767c9d92012-03-02 16:04:34786 GetFieldTrialIds(&field_trial_ids);
787 WriteFieldTrials(field_trial_ids, system_profile);
initial.commit09911bf2008-07-26 23:55:29788}
789
[email protected]ed0fd002012-04-25 23:10:34790void MetricsLog::RecordProfilerData(
791 const tracked_objects::ProcessDataSnapshot& process_data,
792 content::ProcessType process_type) {
793 DCHECK(!locked());
794
[email protected]8f829682012-04-27 00:36:49795 if (tracked_objects::GetTimeSourceType() !=
796 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) {
[email protected]ed0fd002012-04-25 23:10:34797 // We currently only support the default time source, wall clock time.
798 return;
799 }
800
801 ProfilerEventProto* profile;
802 if (!uma_proto()->profiler_event_size()) {
803 // For the first process's data, add a new field to the protocol buffer.
804 profile = uma_proto()->add_profiler_event();
805 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
806 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
807 } else {
808 // For the remaining calls, re-use the existing field.
809 profile = uma_proto()->mutable_profiler_event(0);
810 }
811
812 WriteProfilerData(process_data, process_type, profile);
813}
814
initial.commit09911bf2008-07-26 23:55:29815void MetricsLog::WriteAllProfilesMetrics(
816 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51817 const std::string profile_prefix(prefs::kProfilePrefix);
initial.commit09911bf2008-07-26 23:55:29818 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
819 i != all_profiles_metrics.end_keys(); ++i) {
[email protected]e7b418b2010-07-30 19:47:47820 const std::string& key_name = *i;
initial.commit09911bf2008-07-26 23:55:29821 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
822 DictionaryValue* profile;
[email protected]4dad9ad82009-11-25 20:47:52823 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
824 &profile))
initial.commit09911bf2008-07-26 23:55:29825 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
826 }
827 }
828}
829
[email protected]e7b418b2010-07-30 19:47:47830void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29831 const DictionaryValue& profile_metrics) {
832 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47833 WriteAttribute("profileidhash", profileidhash);
initial.commit09911bf2008-07-26 23:55:29834 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
835 i != profile_metrics.end_keys(); ++i) {
836 Value* value;
[email protected]4dad9ad82009-11-25 20:47:52837 if (profile_metrics.GetWithoutPathExpansion(*i, &value)) {
[email protected]e7b418b2010-07-30 19:47:47838 DCHECK(*i != "id");
initial.commit09911bf2008-07-26 23:55:29839 switch (value->GetType()) {
840 case Value::TYPE_STRING: {
[email protected]5e324b72008-12-18 00:07:59841 std::string string_value;
initial.commit09911bf2008-07-26 23:55:29842 if (value->GetAsString(&string_value)) {
843 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47844 WriteAttribute("name", *i);
[email protected]5e324b72008-12-18 00:07:59845 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29846 }
847 break;
848 }
849
850 case Value::TYPE_BOOLEAN: {
851 bool bool_value;
852 if (value->GetAsBoolean(&bool_value)) {
853 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47854 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29855 WriteIntAttribute("value", bool_value ? 1 : 0);
856 }
857 break;
858 }
859
860 case Value::TYPE_INTEGER: {
861 int int_value;
862 if (value->GetAsInteger(&int_value)) {
863 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47864 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29865 WriteIntAttribute("value", int_value);
866 }
867 break;
868 }
869
870 default:
871 NOTREACHED();
872 break;
873 }
874 }
875 }
876}
877
878void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
[email protected]767c9d92012-03-02 16:04:34879 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29880
[email protected]fe58acc22012-02-29 01:29:58881 // Write the XML version.
[email protected]ffaf78a2008-11-12 17:38:33882 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29883 WriteAttribute("action", "autocomplete");
884 WriteAttribute("targetidhash", "");
885 // TODO(kochi): Properly track windows.
886 WriteIntAttribute("window", 0);
[email protected]6ebc3162011-12-19 13:44:00887 if (log.tab_id != -1) {
888 // If we know what tab the autocomplete URL was opened in, log it.
889 WriteIntAttribute("tab", static_cast<int>(log.tab_id));
890 }
initial.commit09911bf2008-07-26 23:55:29891 WriteCommonEventAttributes();
892
[email protected]65956312012-04-19 21:28:12893 std::vector<string16> terms;
894 const int num_terms =
895 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms));
[email protected]ffaf78a2008-11-12 17:38:33896 {
897 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29898
[email protected]ffaf78a2008-11-12 17:38:33899 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
[email protected]65956312012-04-19 21:28:12900 WriteIntAttribute("numterms", num_terms);
[email protected]ffaf78a2008-11-12 17:38:33901 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
902 WriteIntAttribute("completedlength",
903 static_cast<int>(log.inline_autocompleted_length));
[email protected]9e349762012-01-31 03:24:36904 if (log.elapsed_time_since_user_first_modified_omnibox !=
905 base::TimeDelta::FromMilliseconds(-1)) {
906 // Only upload the typing duration if it is set/valid.
907 WriteInt64Attribute("typingduration",
908 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
909 }
[email protected]381e2992008-12-16 01:41:00910 const std::string input_type(
911 AutocompleteInput::TypeToString(log.input_type));
912 if (!input_type.empty())
913 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:29914
[email protected]ffaf78a2008-11-12 17:38:33915 for (AutocompleteResult::const_iterator i(log.result.begin());
916 i != log.result.end(); ++i) {
917 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
918 if (i->provider)
919 WriteAttribute("provider", i->provider->name());
[email protected]381e2992008-12-16 01:41:00920 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
921 if (!result_type.empty())
922 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:33923 WriteIntAttribute("relevance", i->relevance);
924 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
925 }
initial.commit09911bf2008-07-26 23:55:29926 }
initial.commit09911bf2008-07-26 23:55:29927
[email protected]fe58acc22012-02-29 01:29:58928 // Write the protobuf version.
[email protected]767c9d92012-03-02 16:04:34929 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
[email protected]fe58acc22012-02-29 01:29:58930 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
931 if (log.tab_id != -1) {
932 // If we know what tab the autocomplete URL was opened in, log it.
933 omnibox_event->set_tab_id(log.tab_id);
934 }
935 omnibox_event->set_typed_length(log.text.length());
[email protected]660fe8f32012-05-03 20:01:08936 omnibox_event->set_just_deleted_text(log.just_deleted_text);
[email protected]65956312012-04-19 21:28:12937 omnibox_event->set_num_typed_terms(num_terms);
[email protected]fe58acc22012-02-29 01:29:58938 omnibox_event->set_selected_index(log.selected_index);
939 omnibox_event->set_completed_length(log.inline_autocompleted_length);
[email protected]65956312012-04-19 21:28:12940 if (log.elapsed_time_since_user_first_modified_omnibox !=
941 base::TimeDelta::FromMilliseconds(-1)) {
942 // Only upload the typing duration if it is set/valid.
943 omnibox_event->set_typing_duration_ms(
944 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
945 }
[email protected]ee902532012-05-01 23:54:49946 omnibox_event->set_current_page_classification(
947 log.current_page_classification);
[email protected]fe58acc22012-02-29 01:29:58948 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
949 for (AutocompleteResult::const_iterator i(log.result.begin());
950 i != log.result.end(); ++i) {
951 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
[email protected]0e9e8782012-05-15 23:01:51952 suggestion->set_provider(i->provider->AsOmniboxEventProviderType());
[email protected]fe58acc22012-02-29 01:29:58953 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
954 suggestion->set_relevance(i->relevance);
[email protected]cf6256f2012-06-12 23:36:01955 if (i->typed_count != -1)
956 suggestion->set_typed_count(i->typed_count);
[email protected]fe58acc22012-02-29 01:29:58957 suggestion->set_is_starred(i->starred);
958 }
[email protected]0e9e8782012-05-15 23:01:51959 for (ProvidersInfo::const_iterator i(log.providers_info.begin());
960 i != log.providers_info.end(); ++i) {
961 OmniboxEventProto::ProviderInfo* provider_info =
962 omnibox_event->add_provider_info();
963 provider_info->CopyFrom(*i);
964 }
[email protected]fe58acc22012-02-29 01:29:58965
initial.commit09911bf2008-07-26 23:55:29966 ++num_events_;
967}
[email protected]197c0772012-05-14 23:50:51968
969void MetricsLog::WriteGoogleUpdateProto(
970 const GoogleUpdateMetrics& google_update_metrics) {
971#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
972 SystemProfileProto::GoogleUpdate* google_update =
973 uma_proto()->mutable_system_profile()->mutable_google_update();
974
975 google_update->set_is_system_install(google_update_metrics.is_system_install);
976
977 if (!google_update_metrics.last_started_au.is_null()) {
978 google_update->set_last_automatic_start_timestamp(
979 google_update_metrics.last_started_au.ToTimeT());
980 }
981
982 if (!google_update_metrics.last_checked.is_null()) {
983 google_update->set_last_update_check_timestamp(
984 google_update_metrics.last_checked.ToTimeT());
985 }
986
987 if (!google_update_metrics.google_update_data.version.empty()) {
988 ProductDataToProto(google_update_metrics.google_update_data,
989 google_update->mutable_google_update_status());
990 }
991
992 if (!google_update_metrics.product_data.version.empty()) {
993 ProductDataToProto(google_update_metrics.product_data,
994 google_update->mutable_client_status());
995 }
996#endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
997}