blob: b79ecef1f50da42a7ca28c5e9b10e7e08af07e53 [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]9ac40092010-10-27 23:05:2624#include "chrome/browser/autocomplete/autocomplete_match.h"
initial.commit09911bf2008-07-26 23:55:2925#include "chrome/browser/browser_process.h"
[email protected]10084982011-08-19 17:56:5626#include "chrome/browser/plugin_prefs.h"
[email protected]37858e52010-08-26 00:22:0227#include "chrome/browser/prefs/pref_service.h"
[email protected]10084982011-08-19 17:56:5628#include "chrome/browser/profiles/profile_manager.h"
[email protected]1eeb5e02010-07-20 23:02:1129#include "chrome/common/chrome_version_info.h"
initial.commit09911bf2008-07-26 23:55:2930#include "chrome/common/logging_chrome.h"
[email protected]fe58acc22012-02-29 01:29:5831#include "chrome/common/metrics/proto/omnibox_event.pb.h"
[email protected]ed0fd002012-04-25 23:10:3432#include "chrome/common/metrics/proto/profiler_event.pb.h"
[email protected]fe58acc22012-02-29 01:29:5833#include "chrome/common/metrics/proto/system_profile.pb.h"
initial.commit09911bf2008-07-26 23:55:2934#include "chrome/common/pref_names.h"
[email protected]fe58acc22012-02-29 01:29:5835#include "content/public/browser/content_browser_client.h"
[email protected]79078df2012-02-16 01:22:3236#include "content/public/browser/gpu_data_manager.h"
[email protected]1a838cc2012-04-24 22:06:4937#include "content/public/common/content_client.h"
[email protected]ed0fd002012-04-25 23:10:3438#include "content/public/common/gpu_info.h"
[email protected]46072d42008-07-28 14:49:3539#include "googleurl/src/gurl.h"
[email protected]6b7d954ff2011-10-25 00:39:3540#include "ui/gfx/screen.h"
[email protected]91d9f3d2011-08-14 05:24:4441#include "webkit/plugins/webplugininfo.h"
initial.commit09911bf2008-07-26 23:55:2942
43#define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
44
[email protected]d1be67b2008-11-19 20:28:3845// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
46#if defined(OS_WIN)
47extern "C" IMAGE_DOS_HEADER __ImageBase;
48#endif
49
[email protected]79078df2012-02-16 01:22:3250using content::GpuDataManager;
[email protected]fe58acc22012-02-29 01:29:5851using metrics::OmniboxEventProto;
[email protected]ed0fd002012-04-25 23:10:3452using metrics::ProfilerEventProto;
[email protected]fe58acc22012-02-29 01:29:5853using metrics::SystemProfileProto;
[email protected]ed0fd002012-04-25 23:10:3454using tracked_objects::ProcessDataSnapshot;
[email protected]767c9d92012-03-02 16:04:3455typedef base::FieldTrial::NameGroupId NameGroupId;
[email protected]79078df2012-02-16 01:22:3256
[email protected]1df44b72012-01-19 05:20:3457namespace {
58
59// Returns the date at which the current metrics client ID was created as
60// a string containing milliseconds since the epoch, or "0" if none was found.
[email protected]767c9d92012-03-02 16:04:3461std::string GetInstallDate(PrefService* pref) {
62 if (!pref) {
[email protected]1df44b72012-01-19 05:20:3463 NOTREACHED();
64 return "0";
65 }
[email protected]767c9d92012-03-02 16:04:3466
67 return pref->GetString(prefs::kMetricsClientIDTimestamp);
[email protected]1df44b72012-01-19 05:20:3468}
69
[email protected]fe58acc22012-02-29 01:29:5870OmniboxEventProto::InputType AsOmniboxEventInputType(
71 AutocompleteInput::Type type) {
72 switch (type) {
73 case AutocompleteInput::INVALID:
74 return OmniboxEventProto::INVALID;
75 case AutocompleteInput::UNKNOWN:
76 return OmniboxEventProto::UNKNOWN;
77 case AutocompleteInput::REQUESTED_URL:
78 return OmniboxEventProto::REQUESTED_URL;
79 case AutocompleteInput::URL:
80 return OmniboxEventProto::URL;
81 case AutocompleteInput::QUERY:
82 return OmniboxEventProto::QUERY;
83 case AutocompleteInput::FORCED_QUERY:
84 return OmniboxEventProto::FORCED_QUERY;
85 default:
86 NOTREACHED();
87 return OmniboxEventProto::INVALID;
88 }
89}
90
91OmniboxEventProto::Suggestion::ProviderType AsOmniboxEventProviderType(
92 const AutocompleteProvider* provider) {
93 if (!provider)
94 return OmniboxEventProto::Suggestion::UNKNOWN_PROVIDER;
95
96 const std::string& name = provider->name();
97 if (name == "HistoryURL")
98 return OmniboxEventProto::Suggestion::URL;
99 if (name == "HistoryContents")
100 return OmniboxEventProto::Suggestion::HISTORY_CONTENTS;
101 if (name == "HistoryQuickProvider")
102 return OmniboxEventProto::Suggestion::HISTORY_QUICK;
103 if (name == "Search")
104 return OmniboxEventProto::Suggestion::SEARCH;
105 if (name == "Keyword")
106 return OmniboxEventProto::Suggestion::KEYWORD;
107 if (name == "Builtin")
108 return OmniboxEventProto::Suggestion::BUILTIN;
109 if (name == "ShortcutsProvider")
110 return OmniboxEventProto::Suggestion::SHORTCUTS;
111 if (name == "ExtensionApps")
112 return OmniboxEventProto::Suggestion::EXTENSION_APPS;
113
114 NOTREACHED();
115 return OmniboxEventProto::Suggestion::UNKNOWN_PROVIDER;
116}
117
118OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
119 AutocompleteMatch::Type type) {
120 switch (type) {
121 case AutocompleteMatch::URL_WHAT_YOU_TYPED:
122 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
123 case AutocompleteMatch::HISTORY_URL:
124 return OmniboxEventProto::Suggestion::HISTORY_URL;
125 case AutocompleteMatch::HISTORY_TITLE:
126 return OmniboxEventProto::Suggestion::HISTORY_TITLE;
127 case AutocompleteMatch::HISTORY_BODY:
128 return OmniboxEventProto::Suggestion::HISTORY_BODY;
129 case AutocompleteMatch::HISTORY_KEYWORD:
130 return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
131 case AutocompleteMatch::NAVSUGGEST:
132 return OmniboxEventProto::Suggestion::NAVSUGGEST;
133 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
134 return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
135 case AutocompleteMatch::SEARCH_HISTORY:
136 return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
137 case AutocompleteMatch::SEARCH_SUGGEST:
138 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
139 case AutocompleteMatch::SEARCH_OTHER_ENGINE:
140 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
141 case AutocompleteMatch::EXTENSION_APP:
142 return OmniboxEventProto::Suggestion::EXTENSION_APP;
143 default:
144 NOTREACHED();
145 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
146 }
147}
148
[email protected]ed0fd002012-04-25 23:10:34149ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType(
150 content::ProcessType process_type) {
151 switch (process_type) {
152 case content::PROCESS_TYPE_BROWSER:
153 return ProfilerEventProto::TrackedObject::BROWSER;
154 case content::PROCESS_TYPE_RENDERER:
155 return ProfilerEventProto::TrackedObject::RENDERER;
156 case content::PROCESS_TYPE_PLUGIN:
157 return ProfilerEventProto::TrackedObject::PLUGIN;
158 case content::PROCESS_TYPE_WORKER:
159 return ProfilerEventProto::TrackedObject::WORKER;
160 case content::PROCESS_TYPE_NACL_LOADER:
161 return ProfilerEventProto::TrackedObject::NACL_LOADER;
162 case content::PROCESS_TYPE_UTILITY:
163 return ProfilerEventProto::TrackedObject::UTILITY;
164 case content::PROCESS_TYPE_PROFILE_IMPORT:
165 return ProfilerEventProto::TrackedObject::PROFILE_IMPORT;
166 case content::PROCESS_TYPE_ZYGOTE:
167 return ProfilerEventProto::TrackedObject::ZYGOTE;
168 case content::PROCESS_TYPE_SANDBOX_HELPER:
169 return ProfilerEventProto::TrackedObject::SANDBOX_HELPER;
170 case content::PROCESS_TYPE_NACL_BROKER:
171 return ProfilerEventProto::TrackedObject::NACL_BROKER;
172 case content::PROCESS_TYPE_GPU:
173 return ProfilerEventProto::TrackedObject::GPU;
174 case content::PROCESS_TYPE_PPAPI_PLUGIN:
175 return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN;
176 case content::PROCESS_TYPE_PPAPI_BROKER:
177 return ProfilerEventProto::TrackedObject::PPAPI_BROKER;
178 default:
179 NOTREACHED();
180 return ProfilerEventProto::TrackedObject::UNKNOWN;
181 }
182}
183
[email protected]1df44b72012-01-19 05:20:34184// Returns the plugin preferences corresponding for this user, if available.
185// If multiple user profiles are loaded, returns the preferences corresponding
186// to an arbitrary one of the profiles.
187PluginPrefs* GetPluginPrefs() {
188 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]fe58acc22012-02-29 01:29:58189
190 if (!profile_manager) {
191 // The profile manager can be NULL when testing.
192 return NULL;
193 }
194
[email protected]1df44b72012-01-19 05:20:34195 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
196 if (profiles.empty())
197 return NULL;
198
199 return PluginPrefs::GetForProfile(profiles.front());
200}
201
[email protected]fe58acc22012-02-29 01:29:58202// Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
203void SetPluginInfo(const webkit::WebPluginInfo& plugin_info,
204 const PluginPrefs* plugin_prefs,
205 SystemProfileProto::Plugin* plugin) {
206 plugin->set_name(UTF16ToUTF8(plugin_info.name));
207 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
208 plugin->set_version(UTF16ToUTF8(plugin_info.version));
209 if (plugin_prefs)
210 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
211}
212
[email protected]767c9d92012-03-02 16:04:34213void WriteFieldTrials(const std::vector<NameGroupId>& field_trial_ids,
214 SystemProfileProto* system_profile) {
215 for (std::vector<NameGroupId>::const_iterator it = field_trial_ids.begin();
216 it != field_trial_ids.end(); ++it) {
217 SystemProfileProto::FieldTrial* field_trial =
218 system_profile->add_field_trial();
219 field_trial->set_name_id(it->name);
220 field_trial->set_group_id(it->group);
221 }
222}
223
[email protected]ed0fd002012-04-25 23:10:34224void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
225 content::ProcessType process_type,
226 ProfilerEventProto* performance_profile) {
227 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it =
228 profiler_data.tasks.begin();
229 it != profiler_data.tasks.end(); ++it) {
230 std::string ignored;
231 uint64 birth_thread_name_hash;
232 uint64 exec_thread_name_hash;
233 uint64 source_file_name_hash;
234 uint64 source_function_name_hash;
235 MetricsLogBase::CreateHashes(it->birth.thread_name,
236 &ignored, &birth_thread_name_hash);
237 MetricsLogBase::CreateHashes(it->death_thread_name,
238 &ignored, &exec_thread_name_hash);
239 MetricsLogBase::CreateHashes(it->birth.location.function_name,
240 &ignored, &source_file_name_hash);
241 MetricsLogBase::CreateHashes(it->birth.location.file_name,
242 &ignored, &source_function_name_hash);
243
244 const tracked_objects::DeathDataSnapshot& death_data = it->death_data;
245 ProfilerEventProto::TrackedObject* tracked_object =
246 performance_profile->add_tracked_object();
247 tracked_object->set_birth_thread_name_hash(birth_thread_name_hash);
248 tracked_object->set_exec_thread_name_hash(exec_thread_name_hash);
249 tracked_object->set_source_file_name_hash(source_file_name_hash);
250 tracked_object->set_source_function_name_hash(source_function_name_hash);
251 tracked_object->set_source_line_number(it->birth.location.line_number);
252 tracked_object->set_exec_count(death_data.count);
253 tracked_object->set_exec_time_total(death_data.run_duration_sum);
254 tracked_object->set_exec_time_sampled(death_data.run_duration_sample);
255 tracked_object->set_queue_time_total(death_data.queue_duration_sum);
256 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample);
257 tracked_object->set_process_type(AsProtobufProcessType(process_type));
258 tracked_object->set_process_id(profiler_data.process_id);
259 }
260}
261
[email protected]1df44b72012-01-19 05:20:34262} // namespace
263
[email protected]67f92bc32012-01-26 01:56:19264static base::LazyInstance<std::string>::Leaky
[email protected]054c8012011-11-16 00:12:42265 g_version_extension = LAZY_INSTANCE_INITIALIZER;
266
[email protected]1226abb2010-06-10 18:01:28267MetricsLog::MetricsLog(const std::string& client_id, int session_id)
268 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:41269
[email protected]1226abb2010-06-10 18:01:28270MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:29271
272// static
273void MetricsLog::RegisterPrefs(PrefService* local_state) {
274 local_state->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29275}
276
[email protected]1df44b72012-01-19 05:20:34277// static
[email protected]9165f742010-03-10 22:55:01278int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
279 base::TimeTicks now = base::TimeTicks::Now();
280 static base::TimeTicks last_updated_time(now);
281 int64 incremental_time = (now - last_updated_time).InSeconds();
282 last_updated_time = now;
283
284 if (incremental_time > 0) {
285 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
286 metrics_uptime += incremental_time;
287 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
288 }
289
290 return incremental_time;
291}
292
[email protected]1226abb2010-06-10 18:01:28293// static
294std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:42295 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:17296 if (!version_info.is_valid()) {
297 NOTREACHED() << "Unable to retrieve version info.";
298 return std::string();
299 }
300
[email protected]0211f57e2010-08-27 20:28:42301 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:42302 if (!version_extension().empty())
303 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:42304 if (!version_info.IsOfficialBuild())
305 version.append("-devel");
306 return version;
[email protected]1226abb2010-06-10 18:01:28307}
308
[email protected]054c8012011-11-16 00:12:42309// static
310void MetricsLog::set_version_extension(const std::string& extension) {
311 g_version_extension.Get() = extension;
312}
313
314// static
315const std::string& MetricsLog::version_extension() {
316 return g_version_extension.Get();
317}
318
[email protected]fe58acc22012-02-29 01:29:58319void MetricsLog::RecordIncrementalStabilityElements(
320 const std::vector<webkit::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34321 DCHECK(!locked());
[email protected]0b33f80b2008-12-17 21:34:36322
[email protected]767c9d92012-03-02 16:04:34323 PrefService* pref = GetPrefService();
[email protected]0b33f80b2008-12-17 21:34:36324 DCHECK(pref);
325
[email protected]147bbc0b2009-01-06 19:37:40326 OPEN_ELEMENT_FOR_SCOPE("profile");
327 WriteCommonEventAttributes();
328
[email protected]9958a322011-03-08 20:04:17329 WriteInstallElement();
[email protected]147bbc0b2009-01-06 19:37:40330
331 {
332 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
333 WriteRequiredStabilityAttributes(pref);
334 WriteRealtimeStabilityAttributes(pref);
335
[email protected]fe58acc22012-02-29 01:29:58336 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40337 }
[email protected]0b33f80b2008-12-17 21:34:36338}
339
[email protected]767c9d92012-03-02 16:04:34340PrefService* MetricsLog::GetPrefService() {
341 return g_browser_process->local_state();
342}
343
344gfx::Size MetricsLog::GetScreenSize() const {
[email protected]b82c42c42012-04-25 20:03:41345 return gfx::Screen::GetPrimaryMonitor().size();
[email protected]767c9d92012-03-02 16:04:34346}
347
348int MetricsLog::GetScreenCount() const {
349 return gfx::Screen::GetNumMonitors();
350}
351
352
353void MetricsLog::GetFieldTrialIds(
354 std::vector<NameGroupId>* field_trial_ids) const {
355 base::FieldTrialList::GetFieldTrialNameGroupIds(field_trial_ids);
356}
357
[email protected]fe58acc22012-02-29 01:29:58358void MetricsLog::WriteStabilityElement(
359 const std::vector<webkit::WebPluginInfo>& plugin_list,
360 PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:34361 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29362
initial.commit09911bf2008-07-26 23:55:29363 // Get stability attributes out of Local State, zeroing out stored values.
364 // NOTE: This could lead to some data loss if this report isn't successfully
365 // sent, but that's true for all the metrics.
366
[email protected]ffaf78a2008-11-12 17:38:33367 OPEN_ELEMENT_FOR_SCOPE("stability");
[email protected]147bbc0b2009-01-06 19:37:40368 WriteRequiredStabilityAttributes(pref);
369 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29370
[email protected]fe58acc22012-02-29 01:29:58371 int incomplete_shutdown_count =
372 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
[email protected]e324f6b2012-02-28 05:43:37373 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58374 int breakpad_registration_success_count =
375 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
[email protected]e324f6b2012-02-28 05:43:37376 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58377 int breakpad_registration_failure_count =
378 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
[email protected]e324f6b2012-02-28 05:43:37379 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58380 int debugger_present_count =
381 pref->GetInteger(prefs::kStabilityDebuggerPresent);
[email protected]e324f6b2012-02-28 05:43:37382 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58383 int debugger_not_present_count =
384 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
[email protected]e324f6b2012-02-28 05:43:37385 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31386
[email protected]fe58acc22012-02-29 01:29:58387 // TODO(jar): The following are all optional, so we *could* optimize them for
388 // values of zero (and not include them).
389
390 // Write the XML version.
391 WriteIntAttribute("incompleteshutdowncount", incomplete_shutdown_count);
392 WriteIntAttribute("breakpadregistrationok",
393 breakpad_registration_success_count);
394 WriteIntAttribute("breakpadregistrationfail",
395 breakpad_registration_failure_count);
396 WriteIntAttribute("debuggerpresent", debugger_present_count);
397 WriteIntAttribute("debuggernotpresent", debugger_not_present_count);
398
399 // Write the protobuf version.
400 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34401 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58402 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
403 stability->set_breakpad_registration_success_count(
404 breakpad_registration_success_count);
405 stability->set_breakpad_registration_failure_count(
406 breakpad_registration_failure_count);
407 stability->set_debugger_present_count(debugger_present_count);
408 stability->set_debugger_not_present_count(debugger_not_present_count);
409
410 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40411}
412
[email protected]fe58acc22012-02-29 01:29:58413void MetricsLog::WritePluginStabilityElements(
414 const std::vector<webkit::WebPluginInfo>& plugin_list,
415 PrefService* pref) {
[email protected]147bbc0b2009-01-06 19:37:40416 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29417 const ListValue* plugin_stats_list = pref->GetList(
418 prefs::kStabilityPluginStats);
[email protected]1df44b72012-01-19 05:20:34419 if (!plugin_stats_list)
420 return;
initial.commit09911bf2008-07-26 23:55:29421
[email protected]1df44b72012-01-19 05:20:34422 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]fe58acc22012-02-29 01:29:58423 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34424 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58425 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]1df44b72012-01-19 05:20:34426 for (ListValue::const_iterator iter = plugin_stats_list->begin();
427 iter != plugin_stats_list->end(); ++iter) {
428 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
429 NOTREACHED();
430 continue;
initial.commit09911bf2008-07-26 23:55:29431 }
[email protected]1df44b72012-01-19 05:20:34432 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29433
[email protected]1df44b72012-01-19 05:20:34434 std::string plugin_name;
435 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
436
[email protected]fe58acc22012-02-29 01:29:58437 std::string base64_name_hash;
438 uint64 numeric_name_hash_ignored;
439 CreateHashes(plugin_name, &base64_name_hash, &numeric_name_hash_ignored);
440
441 // Write the XML verison.
[email protected]1df44b72012-01-19 05:20:34442 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
443 // Use "filename" instead of "name", otherwise we need to update the
444 // UMA servers.
[email protected]fe58acc22012-02-29 01:29:58445 WriteAttribute("filename", base64_name_hash);
[email protected]1df44b72012-01-19 05:20:34446
447 int launches = 0;
448 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
449 WriteIntAttribute("launchcount", launches);
450
451 int instances = 0;
452 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
453 WriteIntAttribute("instancecount", instances);
454
455 int crashes = 0;
456 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
457 WriteIntAttribute("crashcount", crashes);
[email protected]fe58acc22012-02-29 01:29:58458
459 // Write the protobuf version.
460 // Note that this search is potentially a quadratic operation, but given the
461 // low number of plugins installed on a "reasonable" setup, this should be
462 // fine.
463 // TODO(isherman): Verify that this does not show up as a hotspot in
464 // profiler runs.
465 const webkit::WebPluginInfo* plugin_info = NULL;
466 const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name);
467 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
468 plugin_list.begin();
469 iter != plugin_list.end(); ++iter) {
470 if (iter->name == plugin_name_utf16) {
471 plugin_info = &(*iter);
472 break;
473 }
474 }
475
476 if (!plugin_info) {
477 NOTREACHED();
478 continue;
479 }
480
481 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);
initial.commit09911bf2008-07-26 23:55:29488 }
[email protected]1df44b72012-01-19 05:20:34489
490 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29491}
492
[email protected]fe58acc22012-02-29 01:29:58493// The server refuses data that doesn't have certain values. crashcount and
494// launchcount are currently "required" in the "stability" group.
495// TODO(isherman): Stop writing these attributes specially once the migration to
496// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40497void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]fe58acc22012-02-29 01:29:58498 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
[email protected]0b33f80b2008-12-17 21:34:36499 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
[email protected]fe58acc22012-02-29 01:29:58500 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
[email protected]0b33f80b2008-12-17 21:34:36501 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58502
503 // Write the XML version.
504 WriteIntAttribute("launchcount", launch_count);
505 WriteIntAttribute("crashcount", crash_count);
506
507 // Write the protobuf version.
508 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34509 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58510 stability->set_launch_count(launch_count);
511 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36512}
513
[email protected]147bbc0b2009-01-06 19:37:40514void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36515 // Update the stats which are critical for real-time stability monitoring.
516 // Since these are "optional," only list ones that are non-zero, as the counts
517 // are aggergated (summed) server side.
518
[email protected]fe58acc22012-02-29 01:29:58519 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34520 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36521 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
522 if (count) {
523 WriteIntAttribute("pageloadcount", count);
[email protected]fe58acc22012-02-29 01:29:58524 stability->set_page_load_count(count);
[email protected]0b33f80b2008-12-17 21:34:36525 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
526 }
527
528 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
529 if (count) {
530 WriteIntAttribute("renderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58531 stability->set_renderer_crash_count(count);
[email protected]0b33f80b2008-12-17 21:34:36532 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
533 }
534
[email protected]1f085622009-12-04 05:33:45535 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
536 if (count) {
537 WriteIntAttribute("extensionrenderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58538 stability->set_extension_renderer_crash_count(count);
[email protected]1f085622009-12-04 05:33:45539 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
540 }
541
[email protected]0b33f80b2008-12-17 21:34:36542 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
543 if (count) {
544 WriteIntAttribute("rendererhangcount", count);
[email protected]fe58acc22012-02-29 01:29:58545 stability->set_renderer_hang_count(count);
[email protected]0b33f80b2008-12-17 21:34:36546 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
547 }
[email protected]1f085622009-12-04 05:33:45548
549 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
550 if (count) {
551 WriteIntAttribute("childprocesscrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58552 stability->set_child_process_crash_count(count);
[email protected]1f085622009-12-04 05:33:45553 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
554 }
[email protected]9165f742010-03-10 22:55:01555
[email protected]c1834a92011-01-21 18:21:03556#if defined(OS_CHROMEOS)
557 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
558 if (count) {
[email protected]fe58acc22012-02-29 01:29:58559 stability->set_other_user_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03560 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
561 }
562
563 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
564 if (count) {
[email protected]fe58acc22012-02-29 01:29:58565 stability->set_kernel_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03566 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
567 }
568
569 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
570 if (count) {
[email protected]fe58acc22012-02-29 01:29:58571 stability->set_unclean_system_shutdown_count(count);
[email protected]c1834a92011-01-21 18:21:03572 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
573 }
574#endif // OS_CHROMEOS
575
[email protected]9165f742010-03-10 22:55:01576 int64 recent_duration = GetIncrementalUptime(pref);
[email protected]fe58acc22012-02-29 01:29:58577 if (recent_duration) {
[email protected]9165f742010-03-10 22:55:01578 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]fe58acc22012-02-29 01:29:58579 stability->set_uptime_sec(recent_duration);
580 }
[email protected]0b33f80b2008-12-17 21:34:36581}
582
initial.commit09911bf2008-07-26 23:55:29583void MetricsLog::WritePluginList(
[email protected]bc66d532012-03-23 01:57:05584 const std::vector<webkit::WebPluginInfo>& plugin_list,
585 bool write_as_xml) {
[email protected]767c9d92012-03-02 16:04:34586 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29587
[email protected]1df44b72012-01-19 05:20:34588 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]10084982011-08-19 17:56:56589
[email protected]ffaf78a2008-11-12 17:38:33590 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]767c9d92012-03-02 16:04:34591 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]91d9f3d2011-08-14 05:24:44592 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50593 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29594 iter != plugin_list.end(); ++iter) {
[email protected]bc66d532012-03-23 01:57:05595 if (write_as_xml) {
596 std::string base64_name_hash;
597 uint64 numeric_hash_ignored;
598 CreateHashes(UTF16ToUTF8(iter->name), &base64_name_hash,
599 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58600
[email protected]bc66d532012-03-23 01:57:05601 std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe();
602 std::string base64_filename_hash;
603 CreateHashes(filename_bytes, &base64_filename_hash,
604 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58605
[email protected]bc66d532012-03-23 01:57:05606 // Write the XML version.
607 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29608
[email protected]bc66d532012-03-23 01:57:05609 // Plugin name and filename are hashed for the privacy of those
610 // testing unreleased new extensions.
611 WriteAttribute("name", base64_name_hash);
612 WriteAttribute("filename", base64_filename_hash);
613 WriteAttribute("version", UTF16ToUTF8(iter->version));
614 if (plugin_prefs)
615 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
616 } else {
617 // Write the protobuf version.
618 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
619 SetPluginInfo(*iter, plugin_prefs, plugin);
620 }
initial.commit09911bf2008-07-26 23:55:29621 }
initial.commit09911bf2008-07-26 23:55:29622}
623
[email protected]147bbc0b2009-01-06 19:37:40624void MetricsLog::WriteInstallElement() {
[email protected]fe58acc22012-02-29 01:29:58625 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05626 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]147bbc0b2009-01-06 19:37:40627 OPEN_ELEMENT_FOR_SCOPE("install");
[email protected]bc66d532012-03-23 01:57:05628 WriteAttribute("installdate", GetInstallDate(GetPrefService()));
[email protected]147bbc0b2009-01-06 19:37:40629 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40630}
631
initial.commit09911bf2008-07-26 23:55:29632void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44633 const std::vector<webkit::WebPluginInfo>& plugin_list,
initial.commit09911bf2008-07-26 23:55:29634 const DictionaryValue* profile_metrics) {
[email protected]767c9d92012-03-02 16:04:34635 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29636
[email protected]767c9d92012-03-02 16:04:34637 PrefService* pref = GetPrefService();
initial.commit09911bf2008-07-26 23:55:29638
[email protected]ffaf78a2008-11-12 17:38:33639 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29640 WriteCommonEventAttributes();
641
[email protected]147bbc0b2009-01-06 19:37:40642 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29643
[email protected]bc66d532012-03-23 01:57:05644 // Write the XML version.
645 // We'll write the protobuf version in RecordEnvironmentProto().
646 bool write_as_xml = true;
647 WritePluginList(plugin_list, write_as_xml);
initial.commit09911bf2008-07-26 23:55:29648
[email protected]fe58acc22012-02-29 01:29:58649 WriteStabilityElement(plugin_list, pref);
initial.commit09911bf2008-07-26 23:55:29650
initial.commit09911bf2008-07-26 23:55:29651 {
[email protected]fe58acc22012-02-29 01:29:58652 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05653 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29654 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]bc66d532012-03-23 01:57:05655 WriteAttribute("arch", base::SysInfo::CPUArchitecture());
initial.commit09911bf2008-07-26 23:55:29656 }
657
658 {
[email protected]fe58acc22012-02-29 01:29:58659 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05660 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29661 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]bc66d532012-03-23 01:57:05662 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38663#if defined(OS_WIN)
664 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
665#endif
initial.commit09911bf2008-07-26 23:55:29666 }
667
668 {
[email protected]fe58acc22012-02-29 01:29:58669 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05670 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29671 OPEN_ELEMENT_FOR_SCOPE("os");
[email protected]bc66d532012-03-23 01:57:05672 WriteAttribute("name", base::SysInfo::OperatingSystemName());
673 WriteAttribute("version", base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29674 }
675
676 {
[email protected]e8c287c872010-07-20 00:49:42677 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]fe58acc22012-02-29 01:29:58678 const content::GPUInfo& gpu_info =
679 GpuDataManager::GetInstance()->GetGPUInfo();
[email protected]fe58acc22012-02-29 01:29:58680
681 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05682 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]79078df2012-02-16 01:22:32683 WriteIntAttribute("vendorid", gpu_info.vendor_id);
684 WriteIntAttribute("deviceid", gpu_info.device_id);
[email protected]e8c287c872010-07-20 00:49:42685 }
686
687 {
[email protected]767c9d92012-03-02 16:04:34688 const gfx::Size display_size = GetScreenSize();
[email protected]fe58acc22012-02-29 01:29:58689
690 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05691 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]fe58acc22012-02-29 01:29:58692 OPEN_ELEMENT_FOR_SCOPE("display");
[email protected]bc66d532012-03-23 01:57:05693 WriteIntAttribute("xsize", display_size.width());
694 WriteIntAttribute("ysize", display_size.height());
695 WriteIntAttribute("screens", GetScreenCount());
initial.commit09911bf2008-07-26 23:55:29696 }
697
698 {
699 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
700 int num_bookmarks_on_bookmark_bar =
701 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
702 int num_folders_on_bookmark_bar =
703 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
704 int num_bookmarks_in_other_bookmarks_folder =
705 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
706 int num_folders_in_other_bookmarks_folder =
707 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
708 {
709 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
710 WriteAttribute("name", "full-tree");
711 WriteIntAttribute("foldercount",
712 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
713 WriteIntAttribute("itemcount",
714 num_bookmarks_on_bookmark_bar +
715 num_bookmarks_in_other_bookmarks_folder);
716 }
717 {
718 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
719 WriteAttribute("name", "toolbar");
720 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
721 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
722 }
723 }
724
725 {
726 OPEN_ELEMENT_FOR_SCOPE("keywords");
727 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
728 }
729
730 if (profile_metrics)
731 WriteAllProfilesMetrics(*profile_metrics);
[email protected]767c9d92012-03-02 16:04:34732
[email protected]bc66d532012-03-23 01:57:05733 RecordEnvironmentProto(plugin_list);
734}
735
736void MetricsLog::RecordEnvironmentProto(
737 const std::vector<webkit::WebPluginInfo>& plugin_list) {
738 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
739 int install_date;
740 bool success = base::StringToInt(GetInstallDate(GetPrefService()),
741 &install_date);
742 DCHECK(success);
743 system_profile->set_install_date(install_date);
744
745 system_profile->set_application_locale(
746 content::GetContentClient()->browser()->GetApplicationLocale());
747
748 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
749 hardware->set_cpu_architecture(base::SysInfo::CPUArchitecture());
750 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
751#if defined(OS_WIN)
752 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
753#endif
754
755 SystemProfileProto::OS* os = system_profile->mutable_os();
756 os->set_name(base::SysInfo::OperatingSystemName());
757 os->set_version(base::SysInfo::OperatingSystemVersion());
758
759 const content::GPUInfo& gpu_info =
760 GpuDataManager::GetInstance()->GetGPUInfo();
761 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
762 gpu->set_vendor_id(gpu_info.vendor_id);
763 gpu->set_device_id(gpu_info.device_id);
764 gpu->set_driver_version(gpu_info.driver_version);
765 gpu->set_driver_date(gpu_info.driver_date);
766 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
767 gpu_performance = gpu->mutable_performance_statistics();
768 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
769 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
770 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
771
772 const gfx::Size display_size = GetScreenSize();
773 hardware->set_primary_screen_width(display_size.width());
774 hardware->set_primary_screen_height(display_size.height());
775 hardware->set_screen_count(GetScreenCount());
776
777 bool write_as_xml = false;
778 WritePluginList(plugin_list, write_as_xml);
779
[email protected]767c9d92012-03-02 16:04:34780 std::vector<NameGroupId> field_trial_ids;
781 GetFieldTrialIds(&field_trial_ids);
782 WriteFieldTrials(field_trial_ids, system_profile);
initial.commit09911bf2008-07-26 23:55:29783}
784
[email protected]ed0fd002012-04-25 23:10:34785void MetricsLog::RecordProfilerData(
786 const tracked_objects::ProcessDataSnapshot& process_data,
787 content::ProcessType process_type) {
788 DCHECK(!locked());
789
[email protected]8f829682012-04-27 00:36:49790 if (tracked_objects::GetTimeSourceType() !=
791 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) {
[email protected]ed0fd002012-04-25 23:10:34792 // We currently only support the default time source, wall clock time.
793 return;
794 }
795
796 ProfilerEventProto* profile;
797 if (!uma_proto()->profiler_event_size()) {
798 // For the first process's data, add a new field to the protocol buffer.
799 profile = uma_proto()->add_profiler_event();
800 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
801 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
802 } else {
803 // For the remaining calls, re-use the existing field.
804 profile = uma_proto()->mutable_profiler_event(0);
805 }
806
807 WriteProfilerData(process_data, process_type, profile);
808}
809
initial.commit09911bf2008-07-26 23:55:29810void MetricsLog::WriteAllProfilesMetrics(
811 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51812 const std::string profile_prefix(prefs::kProfilePrefix);
initial.commit09911bf2008-07-26 23:55:29813 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
814 i != all_profiles_metrics.end_keys(); ++i) {
[email protected]e7b418b2010-07-30 19:47:47815 const std::string& key_name = *i;
initial.commit09911bf2008-07-26 23:55:29816 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
817 DictionaryValue* profile;
[email protected]4dad9ad82009-11-25 20:47:52818 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
819 &profile))
initial.commit09911bf2008-07-26 23:55:29820 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
821 }
822 }
823}
824
[email protected]e7b418b2010-07-30 19:47:47825void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29826 const DictionaryValue& profile_metrics) {
827 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47828 WriteAttribute("profileidhash", profileidhash);
initial.commit09911bf2008-07-26 23:55:29829 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
830 i != profile_metrics.end_keys(); ++i) {
831 Value* value;
[email protected]4dad9ad82009-11-25 20:47:52832 if (profile_metrics.GetWithoutPathExpansion(*i, &value)) {
[email protected]e7b418b2010-07-30 19:47:47833 DCHECK(*i != "id");
initial.commit09911bf2008-07-26 23:55:29834 switch (value->GetType()) {
835 case Value::TYPE_STRING: {
[email protected]5e324b72008-12-18 00:07:59836 std::string string_value;
initial.commit09911bf2008-07-26 23:55:29837 if (value->GetAsString(&string_value)) {
838 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47839 WriteAttribute("name", *i);
[email protected]5e324b72008-12-18 00:07:59840 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29841 }
842 break;
843 }
844
845 case Value::TYPE_BOOLEAN: {
846 bool bool_value;
847 if (value->GetAsBoolean(&bool_value)) {
848 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47849 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29850 WriteIntAttribute("value", bool_value ? 1 : 0);
851 }
852 break;
853 }
854
855 case Value::TYPE_INTEGER: {
856 int int_value;
857 if (value->GetAsInteger(&int_value)) {
858 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47859 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29860 WriteIntAttribute("value", int_value);
861 }
862 break;
863 }
864
865 default:
866 NOTREACHED();
867 break;
868 }
869 }
870 }
871}
872
873void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
[email protected]767c9d92012-03-02 16:04:34874 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29875
[email protected]fe58acc22012-02-29 01:29:58876 // Write the XML version.
[email protected]ffaf78a2008-11-12 17:38:33877 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29878 WriteAttribute("action", "autocomplete");
879 WriteAttribute("targetidhash", "");
880 // TODO(kochi): Properly track windows.
881 WriteIntAttribute("window", 0);
[email protected]6ebc3162011-12-19 13:44:00882 if (log.tab_id != -1) {
883 // If we know what tab the autocomplete URL was opened in, log it.
884 WriteIntAttribute("tab", static_cast<int>(log.tab_id));
885 }
initial.commit09911bf2008-07-26 23:55:29886 WriteCommonEventAttributes();
887
[email protected]65956312012-04-19 21:28:12888 std::vector<string16> terms;
889 const int num_terms =
890 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms));
[email protected]ffaf78a2008-11-12 17:38:33891 {
892 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29893
[email protected]ffaf78a2008-11-12 17:38:33894 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
[email protected]65956312012-04-19 21:28:12895 WriteIntAttribute("numterms", num_terms);
[email protected]ffaf78a2008-11-12 17:38:33896 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
897 WriteIntAttribute("completedlength",
898 static_cast<int>(log.inline_autocompleted_length));
[email protected]9e349762012-01-31 03:24:36899 if (log.elapsed_time_since_user_first_modified_omnibox !=
900 base::TimeDelta::FromMilliseconds(-1)) {
901 // Only upload the typing duration if it is set/valid.
902 WriteInt64Attribute("typingduration",
903 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
904 }
[email protected]381e2992008-12-16 01:41:00905 const std::string input_type(
906 AutocompleteInput::TypeToString(log.input_type));
907 if (!input_type.empty())
908 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:29909
[email protected]ffaf78a2008-11-12 17:38:33910 for (AutocompleteResult::const_iterator i(log.result.begin());
911 i != log.result.end(); ++i) {
912 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
913 if (i->provider)
914 WriteAttribute("provider", i->provider->name());
[email protected]381e2992008-12-16 01:41:00915 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
916 if (!result_type.empty())
917 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:33918 WriteIntAttribute("relevance", i->relevance);
919 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
920 }
initial.commit09911bf2008-07-26 23:55:29921 }
initial.commit09911bf2008-07-26 23:55:29922
[email protected]fe58acc22012-02-29 01:29:58923 // Write the protobuf version.
[email protected]767c9d92012-03-02 16:04:34924 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
[email protected]fe58acc22012-02-29 01:29:58925 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
926 if (log.tab_id != -1) {
927 // If we know what tab the autocomplete URL was opened in, log it.
928 omnibox_event->set_tab_id(log.tab_id);
929 }
930 omnibox_event->set_typed_length(log.text.length());
[email protected]65956312012-04-19 21:28:12931 omnibox_event->set_num_typed_terms(num_terms);
[email protected]fe58acc22012-02-29 01:29:58932 omnibox_event->set_selected_index(log.selected_index);
933 omnibox_event->set_completed_length(log.inline_autocompleted_length);
[email protected]65956312012-04-19 21:28:12934 if (log.elapsed_time_since_user_first_modified_omnibox !=
935 base::TimeDelta::FromMilliseconds(-1)) {
936 // Only upload the typing duration if it is set/valid.
937 omnibox_event->set_typing_duration_ms(
938 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
939 }
[email protected]fe58acc22012-02-29 01:29:58940 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
941 for (AutocompleteResult::const_iterator i(log.result.begin());
942 i != log.result.end(); ++i) {
943 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
944 suggestion->set_provider(AsOmniboxEventProviderType(i->provider));
945 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
946 suggestion->set_relevance(i->relevance);
947 suggestion->set_is_starred(i->starred);
948 }
949
initial.commit09911bf2008-07-26 23:55:29950 ++num_events_;
951}