blob: 42ff2af14d02030ac3e525afde1b5126ddc6ac09 [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]ad2461c2012-04-27 21:11:0331#include "chrome/common/metrics/experiments_helper.h"
[email protected]fe58acc22012-02-29 01:29:5832#include "chrome/common/metrics/proto/omnibox_event.pb.h"
[email protected]ed0fd002012-04-25 23:10:3433#include "chrome/common/metrics/proto/profiler_event.pb.h"
[email protected]fe58acc22012-02-29 01:29:5834#include "chrome/common/metrics/proto/system_profile.pb.h"
initial.commit09911bf2008-07-26 23:55:2935#include "chrome/common/pref_names.h"
[email protected]197c0772012-05-14 23:50:5136#include "chrome/installer/util/google_update_settings.h"
[email protected]fe58acc22012-02-29 01:29:5837#include "content/public/browser/content_browser_client.h"
[email protected]79078df2012-02-16 01:22:3238#include "content/public/browser/gpu_data_manager.h"
[email protected]1a838cc2012-04-24 22:06:4939#include "content/public/common/content_client.h"
[email protected]ed0fd002012-04-25 23:10:3440#include "content/public/common/gpu_info.h"
[email protected]46072d42008-07-28 14:49:3541#include "googleurl/src/gurl.h"
[email protected]6b7d954ff2011-10-25 00:39:3542#include "ui/gfx/screen.h"
[email protected]91d9f3d2011-08-14 05:24:4443#include "webkit/plugins/webplugininfo.h"
initial.commit09911bf2008-07-26 23:55:2944
45#define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
46
[email protected]d1be67b2008-11-19 20:28:3847// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
48#if defined(OS_WIN)
49extern "C" IMAGE_DOS_HEADER __ImageBase;
50#endif
51
[email protected]79078df2012-02-16 01:22:3252using content::GpuDataManager;
[email protected]fe58acc22012-02-29 01:29:5853using metrics::OmniboxEventProto;
[email protected]ed0fd002012-04-25 23:10:3454using metrics::ProfilerEventProto;
[email protected]fe58acc22012-02-29 01:29:5855using metrics::SystemProfileProto;
[email protected]ed0fd002012-04-25 23:10:3456using tracked_objects::ProcessDataSnapshot;
[email protected]ad2461c2012-04-27 21:11:0357typedef experiments_helper::SelectedGroupId SelectedGroupId;
[email protected]197c0772012-05-14 23:50:5158typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo;
[email protected]79078df2012-02-16 01:22:3259
[email protected]1df44b72012-01-19 05:20:3460namespace {
61
62// Returns the date at which the current metrics client ID was created as
63// a string containing milliseconds since the epoch, or "0" if none was found.
[email protected]767c9d92012-03-02 16:04:3464std::string GetInstallDate(PrefService* pref) {
65 if (!pref) {
[email protected]1df44b72012-01-19 05:20:3466 NOTREACHED();
67 return "0";
68 }
[email protected]767c9d92012-03-02 16:04:3469
70 return pref->GetString(prefs::kMetricsClientIDTimestamp);
[email protected]1df44b72012-01-19 05:20:3471}
72
[email protected]fe58acc22012-02-29 01:29:5873OmniboxEventProto::InputType AsOmniboxEventInputType(
74 AutocompleteInput::Type type) {
75 switch (type) {
76 case AutocompleteInput::INVALID:
77 return OmniboxEventProto::INVALID;
78 case AutocompleteInput::UNKNOWN:
79 return OmniboxEventProto::UNKNOWN;
80 case AutocompleteInput::REQUESTED_URL:
81 return OmniboxEventProto::REQUESTED_URL;
82 case AutocompleteInput::URL:
83 return OmniboxEventProto::URL;
84 case AutocompleteInput::QUERY:
85 return OmniboxEventProto::QUERY;
86 case AutocompleteInput::FORCED_QUERY:
87 return OmniboxEventProto::FORCED_QUERY;
88 default:
89 NOTREACHED();
90 return OmniboxEventProto::INVALID;
91 }
92}
93
[email protected]fe58acc22012-02-29 01:29:5894OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
95 AutocompleteMatch::Type type) {
96 switch (type) {
97 case AutocompleteMatch::URL_WHAT_YOU_TYPED:
98 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
99 case AutocompleteMatch::HISTORY_URL:
100 return OmniboxEventProto::Suggestion::HISTORY_URL;
101 case AutocompleteMatch::HISTORY_TITLE:
102 return OmniboxEventProto::Suggestion::HISTORY_TITLE;
103 case AutocompleteMatch::HISTORY_BODY:
104 return OmniboxEventProto::Suggestion::HISTORY_BODY;
105 case AutocompleteMatch::HISTORY_KEYWORD:
106 return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
107 case AutocompleteMatch::NAVSUGGEST:
108 return OmniboxEventProto::Suggestion::NAVSUGGEST;
109 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
110 return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
111 case AutocompleteMatch::SEARCH_HISTORY:
112 return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
113 case AutocompleteMatch::SEARCH_SUGGEST:
114 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
115 case AutocompleteMatch::SEARCH_OTHER_ENGINE:
116 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
117 case AutocompleteMatch::EXTENSION_APP:
118 return OmniboxEventProto::Suggestion::EXTENSION_APP;
119 default:
120 NOTREACHED();
121 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
122 }
123}
124
[email protected]ed0fd002012-04-25 23:10:34125ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType(
126 content::ProcessType process_type) {
127 switch (process_type) {
128 case content::PROCESS_TYPE_BROWSER:
129 return ProfilerEventProto::TrackedObject::BROWSER;
130 case content::PROCESS_TYPE_RENDERER:
131 return ProfilerEventProto::TrackedObject::RENDERER;
132 case content::PROCESS_TYPE_PLUGIN:
133 return ProfilerEventProto::TrackedObject::PLUGIN;
134 case content::PROCESS_TYPE_WORKER:
135 return ProfilerEventProto::TrackedObject::WORKER;
136 case content::PROCESS_TYPE_NACL_LOADER:
137 return ProfilerEventProto::TrackedObject::NACL_LOADER;
138 case content::PROCESS_TYPE_UTILITY:
139 return ProfilerEventProto::TrackedObject::UTILITY;
140 case content::PROCESS_TYPE_PROFILE_IMPORT:
141 return ProfilerEventProto::TrackedObject::PROFILE_IMPORT;
142 case content::PROCESS_TYPE_ZYGOTE:
143 return ProfilerEventProto::TrackedObject::ZYGOTE;
144 case content::PROCESS_TYPE_SANDBOX_HELPER:
145 return ProfilerEventProto::TrackedObject::SANDBOX_HELPER;
146 case content::PROCESS_TYPE_NACL_BROKER:
147 return ProfilerEventProto::TrackedObject::NACL_BROKER;
148 case content::PROCESS_TYPE_GPU:
149 return ProfilerEventProto::TrackedObject::GPU;
150 case content::PROCESS_TYPE_PPAPI_PLUGIN:
151 return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN;
152 case content::PROCESS_TYPE_PPAPI_BROKER:
153 return ProfilerEventProto::TrackedObject::PPAPI_BROKER;
154 default:
155 NOTREACHED();
156 return ProfilerEventProto::TrackedObject::UNKNOWN;
157 }
158}
159
[email protected]1df44b72012-01-19 05:20:34160// Returns the plugin preferences corresponding for this user, if available.
161// If multiple user profiles are loaded, returns the preferences corresponding
162// to an arbitrary one of the profiles.
163PluginPrefs* GetPluginPrefs() {
164 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]fe58acc22012-02-29 01:29:58165
166 if (!profile_manager) {
167 // The profile manager can be NULL when testing.
168 return NULL;
169 }
170
[email protected]1df44b72012-01-19 05:20:34171 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
172 if (profiles.empty())
173 return NULL;
174
175 return PluginPrefs::GetForProfile(profiles.front());
176}
177
[email protected]fe58acc22012-02-29 01:29:58178// Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
179void SetPluginInfo(const webkit::WebPluginInfo& plugin_info,
180 const PluginPrefs* plugin_prefs,
181 SystemProfileProto::Plugin* plugin) {
182 plugin->set_name(UTF16ToUTF8(plugin_info.name));
183 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
184 plugin->set_version(UTF16ToUTF8(plugin_info.version));
185 if (plugin_prefs)
186 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
187}
188
[email protected]ad2461c2012-04-27 21:11:03189void WriteFieldTrials(const std::vector<SelectedGroupId>& field_trial_ids,
[email protected]767c9d92012-03-02 16:04:34190 SystemProfileProto* system_profile) {
[email protected]ad2461c2012-04-27 21:11:03191 for (std::vector<SelectedGroupId>::const_iterator it =
192 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
[email protected]767c9d92012-03-02 16:04:34193 SystemProfileProto::FieldTrial* field_trial =
194 system_profile->add_field_trial();
195 field_trial->set_name_id(it->name);
196 field_trial->set_group_id(it->group);
197 }
198}
199
[email protected]ed0fd002012-04-25 23:10:34200void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
201 content::ProcessType process_type,
202 ProfilerEventProto* performance_profile) {
203 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it =
204 profiler_data.tasks.begin();
205 it != profiler_data.tasks.end(); ++it) {
206 std::string ignored;
207 uint64 birth_thread_name_hash;
208 uint64 exec_thread_name_hash;
209 uint64 source_file_name_hash;
210 uint64 source_function_name_hash;
211 MetricsLogBase::CreateHashes(it->birth.thread_name,
212 &ignored, &birth_thread_name_hash);
213 MetricsLogBase::CreateHashes(it->death_thread_name,
214 &ignored, &exec_thread_name_hash);
215 MetricsLogBase::CreateHashes(it->birth.location.function_name,
216 &ignored, &source_file_name_hash);
217 MetricsLogBase::CreateHashes(it->birth.location.file_name,
218 &ignored, &source_function_name_hash);
219
220 const tracked_objects::DeathDataSnapshot& death_data = it->death_data;
221 ProfilerEventProto::TrackedObject* tracked_object =
222 performance_profile->add_tracked_object();
223 tracked_object->set_birth_thread_name_hash(birth_thread_name_hash);
224 tracked_object->set_exec_thread_name_hash(exec_thread_name_hash);
225 tracked_object->set_source_file_name_hash(source_file_name_hash);
226 tracked_object->set_source_function_name_hash(source_function_name_hash);
227 tracked_object->set_source_line_number(it->birth.location.line_number);
228 tracked_object->set_exec_count(death_data.count);
229 tracked_object->set_exec_time_total(death_data.run_duration_sum);
230 tracked_object->set_exec_time_sampled(death_data.run_duration_sample);
231 tracked_object->set_queue_time_total(death_data.queue_duration_sum);
232 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample);
233 tracked_object->set_process_type(AsProtobufProcessType(process_type));
234 tracked_object->set_process_id(profiler_data.process_id);
235 }
236}
237
[email protected]197c0772012-05-14 23:50:51238void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data,
239 ProductInfo* product_info) {
240 product_info->set_version(product_data.version);
241 product_info->set_last_update_success_timestamp(
242 product_data.last_success.ToTimeT());
243 product_info->set_last_error(product_data.last_error_code);
244 product_info->set_last_extra_error(product_data.last_extra_code);
245 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) {
246 product_info->set_last_result(
247 static_cast<ProductInfo::InstallResult>(product_data.last_result));
248 }
249}
250
[email protected]1df44b72012-01-19 05:20:34251} // namespace
252
[email protected]197c0772012-05-14 23:50:51253GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {}
254
255GoogleUpdateMetrics::~GoogleUpdateMetrics() {}
256
[email protected]67f92bc32012-01-26 01:56:19257static base::LazyInstance<std::string>::Leaky
[email protected]054c8012011-11-16 00:12:42258 g_version_extension = LAZY_INSTANCE_INITIALIZER;
259
[email protected]1226abb2010-06-10 18:01:28260MetricsLog::MetricsLog(const std::string& client_id, int session_id)
261 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:41262
[email protected]1226abb2010-06-10 18:01:28263MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:29264
265// static
266void MetricsLog::RegisterPrefs(PrefService* local_state) {
267 local_state->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29268}
269
[email protected]1df44b72012-01-19 05:20:34270// static
[email protected]9165f742010-03-10 22:55:01271int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
272 base::TimeTicks now = base::TimeTicks::Now();
273 static base::TimeTicks last_updated_time(now);
274 int64 incremental_time = (now - last_updated_time).InSeconds();
275 last_updated_time = now;
276
277 if (incremental_time > 0) {
278 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
279 metrics_uptime += incremental_time;
280 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
281 }
282
283 return incremental_time;
284}
285
[email protected]1226abb2010-06-10 18:01:28286// static
287std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:42288 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:17289 if (!version_info.is_valid()) {
290 NOTREACHED() << "Unable to retrieve version info.";
291 return std::string();
292 }
293
[email protected]0211f57e2010-08-27 20:28:42294 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:42295 if (!version_extension().empty())
296 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:42297 if (!version_info.IsOfficialBuild())
298 version.append("-devel");
299 return version;
[email protected]1226abb2010-06-10 18:01:28300}
301
[email protected]054c8012011-11-16 00:12:42302// static
303void MetricsLog::set_version_extension(const std::string& extension) {
304 g_version_extension.Get() = extension;
305}
306
307// static
308const std::string& MetricsLog::version_extension() {
309 return g_version_extension.Get();
310}
311
[email protected]fe58acc22012-02-29 01:29:58312void MetricsLog::RecordIncrementalStabilityElements(
313 const std::vector<webkit::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34314 DCHECK(!locked());
[email protected]0b33f80b2008-12-17 21:34:36315
[email protected]767c9d92012-03-02 16:04:34316 PrefService* pref = GetPrefService();
[email protected]0b33f80b2008-12-17 21:34:36317 DCHECK(pref);
318
[email protected]147bbc0b2009-01-06 19:37:40319 OPEN_ELEMENT_FOR_SCOPE("profile");
320 WriteCommonEventAttributes();
321
[email protected]9958a322011-03-08 20:04:17322 WriteInstallElement();
[email protected]147bbc0b2009-01-06 19:37:40323
324 {
325 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
326 WriteRequiredStabilityAttributes(pref);
327 WriteRealtimeStabilityAttributes(pref);
328
[email protected]fe58acc22012-02-29 01:29:58329 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40330 }
[email protected]0b33f80b2008-12-17 21:34:36331}
332
[email protected]767c9d92012-03-02 16:04:34333PrefService* MetricsLog::GetPrefService() {
334 return g_browser_process->local_state();
335}
336
337gfx::Size MetricsLog::GetScreenSize() const {
[email protected]42c0a0c62012-06-17 03:50:33338 return gfx::Screen::GetPrimaryDisplay().GetSizeInPixel();
[email protected]767c9d92012-03-02 16:04:34339}
340
341int MetricsLog::GetScreenCount() const {
[email protected]42c0a0c62012-06-17 03:50:33342 return gfx::Screen::GetNumDisplays();
[email protected]767c9d92012-03-02 16:04:34343}
344
[email protected]767c9d92012-03-02 16:04:34345void MetricsLog::GetFieldTrialIds(
[email protected]ad2461c2012-04-27 21:11:03346 std::vector<SelectedGroupId>* field_trial_ids) const {
347 experiments_helper::GetFieldTrialSelectedGroupIds(field_trial_ids);
[email protected]767c9d92012-03-02 16:04:34348}
349
[email protected]fe58acc22012-02-29 01:29:58350void MetricsLog::WriteStabilityElement(
351 const std::vector<webkit::WebPluginInfo>& plugin_list,
352 PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:34353 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29354
initial.commit09911bf2008-07-26 23:55:29355 // Get stability attributes out of Local State, zeroing out stored values.
356 // NOTE: This could lead to some data loss if this report isn't successfully
357 // sent, but that's true for all the metrics.
358
[email protected]ffaf78a2008-11-12 17:38:33359 OPEN_ELEMENT_FOR_SCOPE("stability");
[email protected]147bbc0b2009-01-06 19:37:40360 WriteRequiredStabilityAttributes(pref);
361 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29362
[email protected]fe58acc22012-02-29 01:29:58363 int incomplete_shutdown_count =
364 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
[email protected]e324f6b2012-02-28 05:43:37365 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58366 int breakpad_registration_success_count =
367 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
[email protected]e324f6b2012-02-28 05:43:37368 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58369 int breakpad_registration_failure_count =
370 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
[email protected]e324f6b2012-02-28 05:43:37371 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58372 int debugger_present_count =
373 pref->GetInteger(prefs::kStabilityDebuggerPresent);
[email protected]e324f6b2012-02-28 05:43:37374 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58375 int debugger_not_present_count =
376 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
[email protected]e324f6b2012-02-28 05:43:37377 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31378
[email protected]fe58acc22012-02-29 01:29:58379 // TODO(jar): The following are all optional, so we *could* optimize them for
380 // values of zero (and not include them).
381
382 // Write the XML version.
383 WriteIntAttribute("incompleteshutdowncount", incomplete_shutdown_count);
384 WriteIntAttribute("breakpadregistrationok",
385 breakpad_registration_success_count);
386 WriteIntAttribute("breakpadregistrationfail",
387 breakpad_registration_failure_count);
388 WriteIntAttribute("debuggerpresent", debugger_present_count);
389 WriteIntAttribute("debuggernotpresent", debugger_not_present_count);
390
391 // Write the protobuf version.
392 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34393 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58394 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
395 stability->set_breakpad_registration_success_count(
396 breakpad_registration_success_count);
397 stability->set_breakpad_registration_failure_count(
398 breakpad_registration_failure_count);
399 stability->set_debugger_present_count(debugger_present_count);
400 stability->set_debugger_not_present_count(debugger_not_present_count);
401
402 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40403}
404
[email protected]fe58acc22012-02-29 01:29:58405void MetricsLog::WritePluginStabilityElements(
406 const std::vector<webkit::WebPluginInfo>& plugin_list,
407 PrefService* pref) {
[email protected]147bbc0b2009-01-06 19:37:40408 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29409 const ListValue* plugin_stats_list = pref->GetList(
410 prefs::kStabilityPluginStats);
[email protected]1df44b72012-01-19 05:20:34411 if (!plugin_stats_list)
412 return;
initial.commit09911bf2008-07-26 23:55:29413
[email protected]1df44b72012-01-19 05:20:34414 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]fe58acc22012-02-29 01:29:58415 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34416 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58417 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]1df44b72012-01-19 05:20:34418 for (ListValue::const_iterator iter = plugin_stats_list->begin();
419 iter != plugin_stats_list->end(); ++iter) {
420 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
421 NOTREACHED();
422 continue;
initial.commit09911bf2008-07-26 23:55:29423 }
[email protected]1df44b72012-01-19 05:20:34424 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29425
[email protected]1df44b72012-01-19 05:20:34426 std::string plugin_name;
427 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
428
[email protected]fe58acc22012-02-29 01:29:58429 std::string base64_name_hash;
430 uint64 numeric_name_hash_ignored;
431 CreateHashes(plugin_name, &base64_name_hash, &numeric_name_hash_ignored);
432
433 // Write the XML verison.
[email protected]1df44b72012-01-19 05:20:34434 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
435 // Use "filename" instead of "name", otherwise we need to update the
436 // UMA servers.
[email protected]fe58acc22012-02-29 01:29:58437 WriteAttribute("filename", base64_name_hash);
[email protected]1df44b72012-01-19 05:20:34438
439 int launches = 0;
440 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
441 WriteIntAttribute("launchcount", launches);
442
443 int instances = 0;
444 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
445 WriteIntAttribute("instancecount", instances);
446
447 int crashes = 0;
448 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
449 WriteIntAttribute("crashcount", crashes);
[email protected]fe58acc22012-02-29 01:29:58450
451 // Write the protobuf version.
452 // Note that this search is potentially a quadratic operation, but given the
453 // low number of plugins installed on a "reasonable" setup, this should be
454 // fine.
455 // TODO(isherman): Verify that this does not show up as a hotspot in
456 // profiler runs.
457 const webkit::WebPluginInfo* plugin_info = NULL;
458 const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name);
459 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
460 plugin_list.begin();
461 iter != plugin_list.end(); ++iter) {
462 if (iter->name == plugin_name_utf16) {
463 plugin_info = &(*iter);
464 break;
465 }
466 }
467
468 if (!plugin_info) {
469 NOTREACHED();
470 continue;
471 }
472
473 SystemProfileProto::Stability::PluginStability* plugin_stability =
474 stability->add_plugin_stability();
475 SetPluginInfo(*plugin_info, plugin_prefs,
476 plugin_stability->mutable_plugin());
477 plugin_stability->set_launch_count(launches);
478 plugin_stability->set_instance_count(instances);
479 plugin_stability->set_crash_count(crashes);
initial.commit09911bf2008-07-26 23:55:29480 }
[email protected]1df44b72012-01-19 05:20:34481
482 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29483}
484
[email protected]fe58acc22012-02-29 01:29:58485// The server refuses data that doesn't have certain values. crashcount and
486// launchcount are currently "required" in the "stability" group.
487// TODO(isherman): Stop writing these attributes specially once the migration to
488// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40489void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]fe58acc22012-02-29 01:29:58490 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
[email protected]0b33f80b2008-12-17 21:34:36491 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
[email protected]fe58acc22012-02-29 01:29:58492 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
[email protected]0b33f80b2008-12-17 21:34:36493 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58494
495 // Write the XML version.
496 WriteIntAttribute("launchcount", launch_count);
497 WriteIntAttribute("crashcount", crash_count);
498
499 // Write the protobuf version.
500 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34501 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58502 stability->set_launch_count(launch_count);
503 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36504}
505
[email protected]147bbc0b2009-01-06 19:37:40506void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36507 // Update the stats which are critical for real-time stability monitoring.
508 // Since these are "optional," only list ones that are non-zero, as the counts
509 // are aggergated (summed) server side.
510
[email protected]fe58acc22012-02-29 01:29:58511 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34512 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36513 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
514 if (count) {
515 WriteIntAttribute("pageloadcount", count);
[email protected]fe58acc22012-02-29 01:29:58516 stability->set_page_load_count(count);
[email protected]0b33f80b2008-12-17 21:34:36517 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
518 }
519
520 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
521 if (count) {
522 WriteIntAttribute("renderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58523 stability->set_renderer_crash_count(count);
[email protected]0b33f80b2008-12-17 21:34:36524 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
525 }
526
[email protected]1f085622009-12-04 05:33:45527 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
528 if (count) {
529 WriteIntAttribute("extensionrenderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58530 stability->set_extension_renderer_crash_count(count);
[email protected]1f085622009-12-04 05:33:45531 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
532 }
533
[email protected]0b33f80b2008-12-17 21:34:36534 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
535 if (count) {
536 WriteIntAttribute("rendererhangcount", count);
[email protected]fe58acc22012-02-29 01:29:58537 stability->set_renderer_hang_count(count);
[email protected]0b33f80b2008-12-17 21:34:36538 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
539 }
[email protected]1f085622009-12-04 05:33:45540
541 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
542 if (count) {
543 WriteIntAttribute("childprocesscrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58544 stability->set_child_process_crash_count(count);
[email protected]1f085622009-12-04 05:33:45545 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
546 }
[email protected]9165f742010-03-10 22:55:01547
[email protected]c1834a92011-01-21 18:21:03548#if defined(OS_CHROMEOS)
549 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
550 if (count) {
[email protected]fe58acc22012-02-29 01:29:58551 stability->set_other_user_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03552 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
553 }
554
555 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
556 if (count) {
[email protected]fe58acc22012-02-29 01:29:58557 stability->set_kernel_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03558 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
559 }
560
561 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
562 if (count) {
[email protected]fe58acc22012-02-29 01:29:58563 stability->set_unclean_system_shutdown_count(count);
[email protected]c1834a92011-01-21 18:21:03564 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
565 }
566#endif // OS_CHROMEOS
567
[email protected]9165f742010-03-10 22:55:01568 int64 recent_duration = GetIncrementalUptime(pref);
[email protected]fe58acc22012-02-29 01:29:58569 if (recent_duration) {
[email protected]9165f742010-03-10 22:55:01570 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]fe58acc22012-02-29 01:29:58571 stability->set_uptime_sec(recent_duration);
572 }
[email protected]0b33f80b2008-12-17 21:34:36573}
574
initial.commit09911bf2008-07-26 23:55:29575void MetricsLog::WritePluginList(
[email protected]bc66d532012-03-23 01:57:05576 const std::vector<webkit::WebPluginInfo>& plugin_list,
577 bool write_as_xml) {
[email protected]767c9d92012-03-02 16:04:34578 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29579
[email protected]1df44b72012-01-19 05:20:34580 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]10084982011-08-19 17:56:56581
[email protected]ffaf78a2008-11-12 17:38:33582 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]767c9d92012-03-02 16:04:34583 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]91d9f3d2011-08-14 05:24:44584 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50585 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29586 iter != plugin_list.end(); ++iter) {
[email protected]bc66d532012-03-23 01:57:05587 if (write_as_xml) {
588 std::string base64_name_hash;
589 uint64 numeric_hash_ignored;
590 CreateHashes(UTF16ToUTF8(iter->name), &base64_name_hash,
591 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58592
[email protected]bc66d532012-03-23 01:57:05593 std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe();
594 std::string base64_filename_hash;
595 CreateHashes(filename_bytes, &base64_filename_hash,
596 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58597
[email protected]bc66d532012-03-23 01:57:05598 // Write the XML version.
599 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29600
[email protected]bc66d532012-03-23 01:57:05601 // Plugin name and filename are hashed for the privacy of those
602 // testing unreleased new extensions.
603 WriteAttribute("name", base64_name_hash);
604 WriteAttribute("filename", base64_filename_hash);
605 WriteAttribute("version", UTF16ToUTF8(iter->version));
606 if (plugin_prefs)
607 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
608 } else {
609 // Write the protobuf version.
610 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
611 SetPluginInfo(*iter, plugin_prefs, plugin);
612 }
initial.commit09911bf2008-07-26 23:55:29613 }
initial.commit09911bf2008-07-26 23:55:29614}
615
[email protected]147bbc0b2009-01-06 19:37:40616void MetricsLog::WriteInstallElement() {
[email protected]fe58acc22012-02-29 01:29:58617 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05618 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]147bbc0b2009-01-06 19:37:40619 OPEN_ELEMENT_FOR_SCOPE("install");
[email protected]bc66d532012-03-23 01:57:05620 WriteAttribute("installdate", GetInstallDate(GetPrefService()));
[email protected]147bbc0b2009-01-06 19:37:40621 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40622}
623
initial.commit09911bf2008-07-26 23:55:29624void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44625 const std::vector<webkit::WebPluginInfo>& plugin_list,
[email protected]197c0772012-05-14 23:50:51626 const GoogleUpdateMetrics& google_update_metrics,
initial.commit09911bf2008-07-26 23:55:29627 const DictionaryValue* profile_metrics) {
[email protected]767c9d92012-03-02 16:04:34628 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29629
[email protected]767c9d92012-03-02 16:04:34630 PrefService* pref = GetPrefService();
initial.commit09911bf2008-07-26 23:55:29631
[email protected]ffaf78a2008-11-12 17:38:33632 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29633 WriteCommonEventAttributes();
634
[email protected]147bbc0b2009-01-06 19:37:40635 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29636
[email protected]bc66d532012-03-23 01:57:05637 // Write the XML version.
638 // We'll write the protobuf version in RecordEnvironmentProto().
639 bool write_as_xml = true;
640 WritePluginList(plugin_list, write_as_xml);
initial.commit09911bf2008-07-26 23:55:29641
[email protected]fe58acc22012-02-29 01:29:58642 WriteStabilityElement(plugin_list, pref);
initial.commit09911bf2008-07-26 23:55:29643
644 {
[email protected]fe58acc22012-02-29 01:29:58645 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05646 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29647 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]bc66d532012-03-23 01:57:05648 WriteAttribute("arch", base::SysInfo::CPUArchitecture());
initial.commit09911bf2008-07-26 23:55:29649 }
650
651 {
[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("memory");
[email protected]bc66d532012-03-23 01:57:05655 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38656#if defined(OS_WIN)
657 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
658#endif
initial.commit09911bf2008-07-26 23:55:29659 }
660
661 {
[email protected]fe58acc22012-02-29 01:29:58662 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05663 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29664 OPEN_ELEMENT_FOR_SCOPE("os");
[email protected]bc66d532012-03-23 01:57:05665 WriteAttribute("name", base::SysInfo::OperatingSystemName());
666 WriteAttribute("version", base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29667 }
668
669 {
[email protected]e8c287c872010-07-20 00:49:42670 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]fe58acc22012-02-29 01:29:58671 const content::GPUInfo& gpu_info =
672 GpuDataManager::GetInstance()->GetGPUInfo();
[email protected]fe58acc22012-02-29 01:29:58673
674 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05675 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]a094e2c2012-05-10 23:02:42676 WriteIntAttribute("vendorid", gpu_info.gpu.vendor_id);
677 WriteIntAttribute("deviceid", gpu_info.gpu.device_id);
[email protected]e8c287c872010-07-20 00:49:42678 }
679
680 {
[email protected]767c9d92012-03-02 16:04:34681 const gfx::Size display_size = GetScreenSize();
[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]fe58acc22012-02-29 01:29:58685 OPEN_ELEMENT_FOR_SCOPE("display");
[email protected]bc66d532012-03-23 01:57:05686 WriteIntAttribute("xsize", display_size.width());
687 WriteIntAttribute("ysize", display_size.height());
688 WriteIntAttribute("screens", GetScreenCount());
initial.commit09911bf2008-07-26 23:55:29689 }
690
691 {
692 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
693 int num_bookmarks_on_bookmark_bar =
694 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
695 int num_folders_on_bookmark_bar =
696 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
697 int num_bookmarks_in_other_bookmarks_folder =
698 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
699 int num_folders_in_other_bookmarks_folder =
700 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
701 {
702 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
703 WriteAttribute("name", "full-tree");
704 WriteIntAttribute("foldercount",
705 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
706 WriteIntAttribute("itemcount",
707 num_bookmarks_on_bookmark_bar +
708 num_bookmarks_in_other_bookmarks_folder);
709 }
710 {
711 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
712 WriteAttribute("name", "toolbar");
713 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
714 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
715 }
716 }
717
718 {
719 OPEN_ELEMENT_FOR_SCOPE("keywords");
720 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
721 }
722
723 if (profile_metrics)
724 WriteAllProfilesMetrics(*profile_metrics);
[email protected]767c9d92012-03-02 16:04:34725
[email protected]197c0772012-05-14 23:50:51726 RecordEnvironmentProto(plugin_list, google_update_metrics);
[email protected]bc66d532012-03-23 01:57:05727}
728
729void MetricsLog::RecordEnvironmentProto(
[email protected]197c0772012-05-14 23:50:51730 const std::vector<webkit::WebPluginInfo>& plugin_list,
731 const GoogleUpdateMetrics& google_update_metrics) {
[email protected]bc66d532012-03-23 01:57:05732 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
733 int install_date;
734 bool success = base::StringToInt(GetInstallDate(GetPrefService()),
735 &install_date);
736 DCHECK(success);
737 system_profile->set_install_date(install_date);
738
739 system_profile->set_application_locale(
740 content::GetContentClient()->browser()->GetApplicationLocale());
741
742 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
743 hardware->set_cpu_architecture(base::SysInfo::CPUArchitecture());
744 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
745#if defined(OS_WIN)
746 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
747#endif
748
749 SystemProfileProto::OS* os = system_profile->mutable_os();
750 os->set_name(base::SysInfo::OperatingSystemName());
751 os->set_version(base::SysInfo::OperatingSystemVersion());
752
753 const content::GPUInfo& gpu_info =
754 GpuDataManager::GetInstance()->GetGPUInfo();
755 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
[email protected]a094e2c2012-05-10 23:02:42756 gpu->set_vendor_id(gpu_info.gpu.vendor_id);
757 gpu->set_device_id(gpu_info.gpu.device_id);
[email protected]bc66d532012-03-23 01:57:05758 gpu->set_driver_version(gpu_info.driver_version);
759 gpu->set_driver_date(gpu_info.driver_date);
760 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
761 gpu_performance = gpu->mutable_performance_statistics();
762 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
763 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
764 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
765
766 const gfx::Size display_size = GetScreenSize();
767 hardware->set_primary_screen_width(display_size.width());
768 hardware->set_primary_screen_height(display_size.height());
769 hardware->set_screen_count(GetScreenCount());
770
[email protected]197c0772012-05-14 23:50:51771 WriteGoogleUpdateProto(google_update_metrics);
772
[email protected]bc66d532012-03-23 01:57:05773 bool write_as_xml = false;
774 WritePluginList(plugin_list, write_as_xml);
775
[email protected]ad2461c2012-04-27 21:11:03776 std::vector<SelectedGroupId> field_trial_ids;
[email protected]767c9d92012-03-02 16:04:34777 GetFieldTrialIds(&field_trial_ids);
778 WriteFieldTrials(field_trial_ids, system_profile);
initial.commit09911bf2008-07-26 23:55:29779}
780
[email protected]ed0fd002012-04-25 23:10:34781void MetricsLog::RecordProfilerData(
782 const tracked_objects::ProcessDataSnapshot& process_data,
783 content::ProcessType process_type) {
784 DCHECK(!locked());
785
[email protected]8f829682012-04-27 00:36:49786 if (tracked_objects::GetTimeSourceType() !=
787 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) {
[email protected]ed0fd002012-04-25 23:10:34788 // We currently only support the default time source, wall clock time.
789 return;
790 }
791
792 ProfilerEventProto* profile;
793 if (!uma_proto()->profiler_event_size()) {
794 // For the first process's data, add a new field to the protocol buffer.
795 profile = uma_proto()->add_profiler_event();
796 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
797 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
798 } else {
799 // For the remaining calls, re-use the existing field.
800 profile = uma_proto()->mutable_profiler_event(0);
801 }
802
803 WriteProfilerData(process_data, process_type, profile);
804}
805
initial.commit09911bf2008-07-26 23:55:29806void MetricsLog::WriteAllProfilesMetrics(
807 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51808 const std::string profile_prefix(prefs::kProfilePrefix);
initial.commit09911bf2008-07-26 23:55:29809 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
810 i != all_profiles_metrics.end_keys(); ++i) {
[email protected]e7b418b2010-07-30 19:47:47811 const std::string& key_name = *i;
initial.commit09911bf2008-07-26 23:55:29812 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
813 DictionaryValue* profile;
[email protected]4dad9ad82009-11-25 20:47:52814 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
815 &profile))
initial.commit09911bf2008-07-26 23:55:29816 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
817 }
818 }
819}
820
[email protected]e7b418b2010-07-30 19:47:47821void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29822 const DictionaryValue& profile_metrics) {
823 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47824 WriteAttribute("profileidhash", profileidhash);
initial.commit09911bf2008-07-26 23:55:29825 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
826 i != profile_metrics.end_keys(); ++i) {
827 Value* value;
[email protected]4dad9ad82009-11-25 20:47:52828 if (profile_metrics.GetWithoutPathExpansion(*i, &value)) {
[email protected]e7b418b2010-07-30 19:47:47829 DCHECK(*i != "id");
initial.commit09911bf2008-07-26 23:55:29830 switch (value->GetType()) {
831 case Value::TYPE_STRING: {
[email protected]5e324b72008-12-18 00:07:59832 std::string string_value;
initial.commit09911bf2008-07-26 23:55:29833 if (value->GetAsString(&string_value)) {
834 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47835 WriteAttribute("name", *i);
[email protected]5e324b72008-12-18 00:07:59836 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29837 }
838 break;
839 }
840
841 case Value::TYPE_BOOLEAN: {
842 bool bool_value;
843 if (value->GetAsBoolean(&bool_value)) {
844 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47845 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29846 WriteIntAttribute("value", bool_value ? 1 : 0);
847 }
848 break;
849 }
850
851 case Value::TYPE_INTEGER: {
852 int int_value;
853 if (value->GetAsInteger(&int_value)) {
854 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47855 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29856 WriteIntAttribute("value", int_value);
857 }
858 break;
859 }
860
861 default:
862 NOTREACHED();
863 break;
864 }
865 }
866 }
867}
868
869void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
[email protected]767c9d92012-03-02 16:04:34870 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29871
[email protected]fe58acc22012-02-29 01:29:58872 // Write the XML version.
[email protected]ffaf78a2008-11-12 17:38:33873 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29874 WriteAttribute("action", "autocomplete");
875 WriteAttribute("targetidhash", "");
876 // TODO(kochi): Properly track windows.
877 WriteIntAttribute("window", 0);
[email protected]6ebc3162011-12-19 13:44:00878 if (log.tab_id != -1) {
879 // If we know what tab the autocomplete URL was opened in, log it.
880 WriteIntAttribute("tab", static_cast<int>(log.tab_id));
881 }
initial.commit09911bf2008-07-26 23:55:29882 WriteCommonEventAttributes();
883
[email protected]65956312012-04-19 21:28:12884 std::vector<string16> terms;
885 const int num_terms =
886 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms));
[email protected]ffaf78a2008-11-12 17:38:33887 {
888 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29889
[email protected]ffaf78a2008-11-12 17:38:33890 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
[email protected]65956312012-04-19 21:28:12891 WriteIntAttribute("numterms", num_terms);
[email protected]ffaf78a2008-11-12 17:38:33892 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
893 WriteIntAttribute("completedlength",
894 static_cast<int>(log.inline_autocompleted_length));
[email protected]9e349762012-01-31 03:24:36895 if (log.elapsed_time_since_user_first_modified_omnibox !=
896 base::TimeDelta::FromMilliseconds(-1)) {
897 // Only upload the typing duration if it is set/valid.
898 WriteInt64Attribute("typingduration",
899 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
900 }
[email protected]381e2992008-12-16 01:41:00901 const std::string input_type(
902 AutocompleteInput::TypeToString(log.input_type));
903 if (!input_type.empty())
904 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:29905
[email protected]ffaf78a2008-11-12 17:38:33906 for (AutocompleteResult::const_iterator i(log.result.begin());
907 i != log.result.end(); ++i) {
908 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
909 if (i->provider)
910 WriteAttribute("provider", i->provider->name());
[email protected]381e2992008-12-16 01:41:00911 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
912 if (!result_type.empty())
913 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:33914 WriteIntAttribute("relevance", i->relevance);
915 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
916 }
initial.commit09911bf2008-07-26 23:55:29917 }
initial.commit09911bf2008-07-26 23:55:29918
[email protected]fe58acc22012-02-29 01:29:58919 // Write the protobuf version.
[email protected]767c9d92012-03-02 16:04:34920 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
[email protected]fe58acc22012-02-29 01:29:58921 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
922 if (log.tab_id != -1) {
923 // If we know what tab the autocomplete URL was opened in, log it.
924 omnibox_event->set_tab_id(log.tab_id);
925 }
926 omnibox_event->set_typed_length(log.text.length());
[email protected]660fe8f32012-05-03 20:01:08927 omnibox_event->set_just_deleted_text(log.just_deleted_text);
[email protected]65956312012-04-19 21:28:12928 omnibox_event->set_num_typed_terms(num_terms);
[email protected]fe58acc22012-02-29 01:29:58929 omnibox_event->set_selected_index(log.selected_index);
930 omnibox_event->set_completed_length(log.inline_autocompleted_length);
[email protected]65956312012-04-19 21:28:12931 if (log.elapsed_time_since_user_first_modified_omnibox !=
932 base::TimeDelta::FromMilliseconds(-1)) {
933 // Only upload the typing duration if it is set/valid.
934 omnibox_event->set_typing_duration_ms(
935 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
936 }
[email protected]ee902532012-05-01 23:54:49937 omnibox_event->set_current_page_classification(
938 log.current_page_classification);
[email protected]fe58acc22012-02-29 01:29:58939 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
940 for (AutocompleteResult::const_iterator i(log.result.begin());
941 i != log.result.end(); ++i) {
942 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
[email protected]0e9e8782012-05-15 23:01:51943 suggestion->set_provider(i->provider->AsOmniboxEventProviderType());
[email protected]fe58acc22012-02-29 01:29:58944 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
945 suggestion->set_relevance(i->relevance);
[email protected]cf6256f2012-06-12 23:36:01946 if (i->typed_count != -1)
947 suggestion->set_typed_count(i->typed_count);
[email protected]fe58acc22012-02-29 01:29:58948 suggestion->set_is_starred(i->starred);
949 }
[email protected]0e9e8782012-05-15 23:01:51950 for (ProvidersInfo::const_iterator i(log.providers_info.begin());
951 i != log.providers_info.end(); ++i) {
952 OmniboxEventProto::ProviderInfo* provider_info =
953 omnibox_event->add_provider_info();
954 provider_info->CopyFrom(*i);
955 }
[email protected]fe58acc22012-02-29 01:29:58956
initial.commit09911bf2008-07-26 23:55:29957 ++num_events_;
958}
[email protected]197c0772012-05-14 23:50:51959
960void MetricsLog::WriteGoogleUpdateProto(
961 const GoogleUpdateMetrics& google_update_metrics) {
962#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
963 SystemProfileProto::GoogleUpdate* google_update =
964 uma_proto()->mutable_system_profile()->mutable_google_update();
965
966 google_update->set_is_system_install(google_update_metrics.is_system_install);
967
968 if (!google_update_metrics.last_started_au.is_null()) {
969 google_update->set_last_automatic_start_timestamp(
970 google_update_metrics.last_started_au.ToTimeT());
971 }
972
973 if (!google_update_metrics.last_checked.is_null()) {
974 google_update->set_last_update_check_timestamp(
975 google_update_metrics.last_checked.ToTimeT());
976 }
977
978 if (!google_update_metrics.google_update_data.version.empty()) {
979 ProductDataToProto(google_update_metrics.google_update_data,
980 google_update->mutable_google_update_status());
981 }
982
983 if (!google_update_metrics.product_data.version.empty()) {
984 ProductDataToProto(google_update_metrics.product_data,
985 google_update->mutable_client_status());
986 }
987#endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
988}