blob: 1469674aaf68dfa8a393f8c60f3b43c8114f53ce [file] [log] [blame]
[email protected]1df44b72012-01-19 05:20:341// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]cd1adc22009-01-16 01:29:225#include "chrome/browser/metrics/metrics_log.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]1eeb5e02010-07-20 23:02:117#include <string>
8#include <vector>
9
[email protected]d1be67b2008-11-19 20:28:3810#include "base/basictypes.h"
initial.commit09911bf2008-07-26 23:55:2911#include "base/file_util.h"
[email protected]054c8012011-11-16 00:12:4212#include "base/lazy_instance.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/scoped_ptr.h"
[email protected]85ed9d42010-06-08 22:37:4414#include "base/perftimer.h"
[email protected]ed0fd002012-04-25 23:10:3415#include "base/profiler/alternate_timer.h"
[email protected]fe58acc22012-02-29 01:29:5816#include "base/string_number_conversions.h"
initial.commit09911bf2008-07-26 23:55:2917#include "base/string_util.h"
[email protected]fadf97f2008-09-18 12:18:1418#include "base/sys_info.h"
[email protected]37f39e42010-01-06 17:35:1719#include "base/third_party/nspr/prtime.h"
[email protected]1eeb5e02010-07-20 23:02:1120#include "base/time.h"
[email protected]ed0fd002012-04-25 23:10:3421#include "base/tracked_objects.h"
[email protected]1eeb5e02010-07-20 23:02:1122#include "base/utf_string_conversions.h"
initial.commit09911bf2008-07-26 23:55:2923#include "chrome/browser/autocomplete/autocomplete.h"
[email protected]19871a92012-06-27 19:50:3224#include "chrome/browser/autocomplete/autocomplete_log.h"
[email protected]9ac40092010-10-27 23:05:2625#include "chrome/browser/autocomplete/autocomplete_match.h"
[email protected]30f5bc92012-06-26 04:14:5526#include "chrome/browser/autocomplete/autocomplete_provider.h"
initial.commit09911bf2008-07-26 23:55:2927#include "chrome/browser/browser_process.h"
[email protected]10084982011-08-19 17:56:5628#include "chrome/browser/plugin_prefs.h"
[email protected]37858e52010-08-26 00:22:0229#include "chrome/browser/prefs/pref_service.h"
[email protected]10084982011-08-19 17:56:5630#include "chrome/browser/profiles/profile_manager.h"
[email protected]1eeb5e02010-07-20 23:02:1131#include "chrome/common/chrome_version_info.h"
initial.commit09911bf2008-07-26 23:55:2932#include "chrome/common/logging_chrome.h"
[email protected]ad2461c2012-04-27 21:11:0333#include "chrome/common/metrics/experiments_helper.h"
[email protected]fe58acc22012-02-29 01:29:5834#include "chrome/common/metrics/proto/omnibox_event.pb.h"
[email protected]ed0fd002012-04-25 23:10:3435#include "chrome/common/metrics/proto/profiler_event.pb.h"
[email protected]fe58acc22012-02-29 01:29:5836#include "chrome/common/metrics/proto/system_profile.pb.h"
initial.commit09911bf2008-07-26 23:55:2937#include "chrome/common/pref_names.h"
[email protected]197c0772012-05-14 23:50:5138#include "chrome/installer/util/google_update_settings.h"
[email protected]fe58acc22012-02-29 01:29:5839#include "content/public/browser/content_browser_client.h"
[email protected]79078df2012-02-16 01:22:3240#include "content/public/browser/gpu_data_manager.h"
[email protected]1a838cc2012-04-24 22:06:4941#include "content/public/common/content_client.h"
[email protected]ed0fd002012-04-25 23:10:3442#include "content/public/common/gpu_info.h"
[email protected]46072d42008-07-28 14:49:3543#include "googleurl/src/gurl.h"
[email protected]6b7d954ff2011-10-25 00:39:3544#include "ui/gfx/screen.h"
[email protected]91d9f3d2011-08-14 05:24:4445#include "webkit/plugins/webplugininfo.h"
initial.commit09911bf2008-07-26 23:55:2946
47#define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
48
[email protected]d1be67b2008-11-19 20:28:3849// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
50#if defined(OS_WIN)
51extern "C" IMAGE_DOS_HEADER __ImageBase;
52#endif
53
[email protected]79078df2012-02-16 01:22:3254using content::GpuDataManager;
[email protected]fe58acc22012-02-29 01:29:5855using metrics::OmniboxEventProto;
[email protected]ed0fd002012-04-25 23:10:3456using metrics::ProfilerEventProto;
[email protected]fe58acc22012-02-29 01:29:5857using metrics::SystemProfileProto;
[email protected]ed0fd002012-04-25 23:10:3458using tracked_objects::ProcessDataSnapshot;
[email protected]ad2461c2012-04-27 21:11:0359typedef experiments_helper::SelectedGroupId SelectedGroupId;
[email protected]197c0772012-05-14 23:50:5160typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo;
[email protected]79078df2012-02-16 01:22:3261
[email protected]1df44b72012-01-19 05:20:3462namespace {
63
64// Returns the date at which the current metrics client ID was created as
65// a string containing milliseconds since the epoch, or "0" if none was found.
[email protected]767c9d92012-03-02 16:04:3466std::string GetInstallDate(PrefService* pref) {
67 if (!pref) {
[email protected]1df44b72012-01-19 05:20:3468 NOTREACHED();
69 return "0";
70 }
[email protected]767c9d92012-03-02 16:04:3471
72 return pref->GetString(prefs::kMetricsClientIDTimestamp);
[email protected]1df44b72012-01-19 05:20:3473}
74
[email protected]fe58acc22012-02-29 01:29:5875OmniboxEventProto::InputType AsOmniboxEventInputType(
76 AutocompleteInput::Type type) {
77 switch (type) {
78 case AutocompleteInput::INVALID:
79 return OmniboxEventProto::INVALID;
80 case AutocompleteInput::UNKNOWN:
81 return OmniboxEventProto::UNKNOWN;
82 case AutocompleteInput::REQUESTED_URL:
83 return OmniboxEventProto::REQUESTED_URL;
84 case AutocompleteInput::URL:
85 return OmniboxEventProto::URL;
86 case AutocompleteInput::QUERY:
87 return OmniboxEventProto::QUERY;
88 case AutocompleteInput::FORCED_QUERY:
89 return OmniboxEventProto::FORCED_QUERY;
90 default:
91 NOTREACHED();
92 return OmniboxEventProto::INVALID;
93 }
94}
95
[email protected]fe58acc22012-02-29 01:29:5896OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
97 AutocompleteMatch::Type type) {
98 switch (type) {
99 case AutocompleteMatch::URL_WHAT_YOU_TYPED:
100 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
101 case AutocompleteMatch::HISTORY_URL:
102 return OmniboxEventProto::Suggestion::HISTORY_URL;
103 case AutocompleteMatch::HISTORY_TITLE:
104 return OmniboxEventProto::Suggestion::HISTORY_TITLE;
105 case AutocompleteMatch::HISTORY_BODY:
106 return OmniboxEventProto::Suggestion::HISTORY_BODY;
107 case AutocompleteMatch::HISTORY_KEYWORD:
108 return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
109 case AutocompleteMatch::NAVSUGGEST:
110 return OmniboxEventProto::Suggestion::NAVSUGGEST;
111 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
112 return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
113 case AutocompleteMatch::SEARCH_HISTORY:
114 return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
115 case AutocompleteMatch::SEARCH_SUGGEST:
116 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
117 case AutocompleteMatch::SEARCH_OTHER_ENGINE:
118 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
119 case AutocompleteMatch::EXTENSION_APP:
120 return OmniboxEventProto::Suggestion::EXTENSION_APP;
121 default:
122 NOTREACHED();
123 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
124 }
125}
126
[email protected]ed0fd002012-04-25 23:10:34127ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType(
128 content::ProcessType process_type) {
129 switch (process_type) {
130 case content::PROCESS_TYPE_BROWSER:
131 return ProfilerEventProto::TrackedObject::BROWSER;
132 case content::PROCESS_TYPE_RENDERER:
133 return ProfilerEventProto::TrackedObject::RENDERER;
134 case content::PROCESS_TYPE_PLUGIN:
135 return ProfilerEventProto::TrackedObject::PLUGIN;
136 case content::PROCESS_TYPE_WORKER:
137 return ProfilerEventProto::TrackedObject::WORKER;
138 case content::PROCESS_TYPE_NACL_LOADER:
139 return ProfilerEventProto::TrackedObject::NACL_LOADER;
140 case content::PROCESS_TYPE_UTILITY:
141 return ProfilerEventProto::TrackedObject::UTILITY;
142 case content::PROCESS_TYPE_PROFILE_IMPORT:
143 return ProfilerEventProto::TrackedObject::PROFILE_IMPORT;
144 case content::PROCESS_TYPE_ZYGOTE:
145 return ProfilerEventProto::TrackedObject::ZYGOTE;
146 case content::PROCESS_TYPE_SANDBOX_HELPER:
147 return ProfilerEventProto::TrackedObject::SANDBOX_HELPER;
148 case content::PROCESS_TYPE_NACL_BROKER:
149 return ProfilerEventProto::TrackedObject::NACL_BROKER;
150 case content::PROCESS_TYPE_GPU:
151 return ProfilerEventProto::TrackedObject::GPU;
152 case content::PROCESS_TYPE_PPAPI_PLUGIN:
153 return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN;
154 case content::PROCESS_TYPE_PPAPI_BROKER:
155 return ProfilerEventProto::TrackedObject::PPAPI_BROKER;
156 default:
157 NOTREACHED();
158 return ProfilerEventProto::TrackedObject::UNKNOWN;
159 }
160}
161
[email protected]1df44b72012-01-19 05:20:34162// Returns the plugin preferences corresponding for this user, if available.
163// If multiple user profiles are loaded, returns the preferences corresponding
164// to an arbitrary one of the profiles.
165PluginPrefs* GetPluginPrefs() {
166 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]fe58acc22012-02-29 01:29:58167
168 if (!profile_manager) {
169 // The profile manager can be NULL when testing.
170 return NULL;
171 }
172
[email protected]1df44b72012-01-19 05:20:34173 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
174 if (profiles.empty())
175 return NULL;
176
177 return PluginPrefs::GetForProfile(profiles.front());
178}
179
[email protected]fe58acc22012-02-29 01:29:58180// Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
181void SetPluginInfo(const webkit::WebPluginInfo& plugin_info,
182 const PluginPrefs* plugin_prefs,
183 SystemProfileProto::Plugin* plugin) {
184 plugin->set_name(UTF16ToUTF8(plugin_info.name));
185 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
186 plugin->set_version(UTF16ToUTF8(plugin_info.version));
187 if (plugin_prefs)
188 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
189}
190
[email protected]ad2461c2012-04-27 21:11:03191void WriteFieldTrials(const std::vector<SelectedGroupId>& field_trial_ids,
[email protected]767c9d92012-03-02 16:04:34192 SystemProfileProto* system_profile) {
[email protected]ad2461c2012-04-27 21:11:03193 for (std::vector<SelectedGroupId>::const_iterator it =
194 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
[email protected]767c9d92012-03-02 16:04:34195 SystemProfileProto::FieldTrial* field_trial =
196 system_profile->add_field_trial();
197 field_trial->set_name_id(it->name);
198 field_trial->set_group_id(it->group);
199 }
200}
201
[email protected]ed0fd002012-04-25 23:10:34202void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
203 content::ProcessType process_type,
204 ProfilerEventProto* performance_profile) {
205 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it =
206 profiler_data.tasks.begin();
207 it != profiler_data.tasks.end(); ++it) {
208 std::string ignored;
209 uint64 birth_thread_name_hash;
210 uint64 exec_thread_name_hash;
211 uint64 source_file_name_hash;
212 uint64 source_function_name_hash;
213 MetricsLogBase::CreateHashes(it->birth.thread_name,
214 &ignored, &birth_thread_name_hash);
215 MetricsLogBase::CreateHashes(it->death_thread_name,
216 &ignored, &exec_thread_name_hash);
217 MetricsLogBase::CreateHashes(it->birth.location.function_name,
218 &ignored, &source_file_name_hash);
219 MetricsLogBase::CreateHashes(it->birth.location.file_name,
220 &ignored, &source_function_name_hash);
221
222 const tracked_objects::DeathDataSnapshot& death_data = it->death_data;
223 ProfilerEventProto::TrackedObject* tracked_object =
224 performance_profile->add_tracked_object();
225 tracked_object->set_birth_thread_name_hash(birth_thread_name_hash);
226 tracked_object->set_exec_thread_name_hash(exec_thread_name_hash);
227 tracked_object->set_source_file_name_hash(source_file_name_hash);
228 tracked_object->set_source_function_name_hash(source_function_name_hash);
229 tracked_object->set_source_line_number(it->birth.location.line_number);
230 tracked_object->set_exec_count(death_data.count);
231 tracked_object->set_exec_time_total(death_data.run_duration_sum);
232 tracked_object->set_exec_time_sampled(death_data.run_duration_sample);
233 tracked_object->set_queue_time_total(death_data.queue_duration_sum);
234 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample);
235 tracked_object->set_process_type(AsProtobufProcessType(process_type));
236 tracked_object->set_process_id(profiler_data.process_id);
237 }
238}
239
[email protected]197c0772012-05-14 23:50:51240void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data,
241 ProductInfo* product_info) {
242 product_info->set_version(product_data.version);
243 product_info->set_last_update_success_timestamp(
244 product_data.last_success.ToTimeT());
245 product_info->set_last_error(product_data.last_error_code);
246 product_info->set_last_extra_error(product_data.last_extra_code);
247 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) {
248 product_info->set_last_result(
249 static_cast<ProductInfo::InstallResult>(product_data.last_result));
250 }
251}
252
[email protected]1df44b72012-01-19 05:20:34253} // namespace
254
[email protected]197c0772012-05-14 23:50:51255GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {}
256
257GoogleUpdateMetrics::~GoogleUpdateMetrics() {}
258
[email protected]67f92bc32012-01-26 01:56:19259static base::LazyInstance<std::string>::Leaky
[email protected]054c8012011-11-16 00:12:42260 g_version_extension = LAZY_INSTANCE_INITIALIZER;
261
[email protected]1226abb2010-06-10 18:01:28262MetricsLog::MetricsLog(const std::string& client_id, int session_id)
263 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:41264
[email protected]1226abb2010-06-10 18:01:28265MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:29266
267// static
268void MetricsLog::RegisterPrefs(PrefService* local_state) {
269 local_state->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29270}
271
[email protected]1df44b72012-01-19 05:20:34272// static
[email protected]9165f742010-03-10 22:55:01273int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
274 base::TimeTicks now = base::TimeTicks::Now();
275 static base::TimeTicks last_updated_time(now);
276 int64 incremental_time = (now - last_updated_time).InSeconds();
277 last_updated_time = now;
278
279 if (incremental_time > 0) {
280 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
281 metrics_uptime += incremental_time;
282 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
283 }
284
285 return incremental_time;
286}
287
[email protected]1226abb2010-06-10 18:01:28288// static
289std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:42290 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:17291 if (!version_info.is_valid()) {
292 NOTREACHED() << "Unable to retrieve version info.";
293 return std::string();
294 }
295
[email protected]0211f57e2010-08-27 20:28:42296 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:42297 if (!version_extension().empty())
298 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:42299 if (!version_info.IsOfficialBuild())
300 version.append("-devel");
301 return version;
[email protected]1226abb2010-06-10 18:01:28302}
303
[email protected]054c8012011-11-16 00:12:42304// static
305void MetricsLog::set_version_extension(const std::string& extension) {
306 g_version_extension.Get() = extension;
307}
308
309// static
310const std::string& MetricsLog::version_extension() {
311 return g_version_extension.Get();
312}
313
[email protected]fe58acc22012-02-29 01:29:58314void MetricsLog::RecordIncrementalStabilityElements(
315 const std::vector<webkit::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34316 DCHECK(!locked());
[email protected]0b33f80b2008-12-17 21:34:36317
[email protected]767c9d92012-03-02 16:04:34318 PrefService* pref = GetPrefService();
[email protected]0b33f80b2008-12-17 21:34:36319 DCHECK(pref);
320
[email protected]147bbc0b2009-01-06 19:37:40321 OPEN_ELEMENT_FOR_SCOPE("profile");
322 WriteCommonEventAttributes();
323
[email protected]9958a322011-03-08 20:04:17324 WriteInstallElement();
[email protected]147bbc0b2009-01-06 19:37:40325
326 {
327 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
328 WriteRequiredStabilityAttributes(pref);
329 WriteRealtimeStabilityAttributes(pref);
330
[email protected]fe58acc22012-02-29 01:29:58331 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40332 }
[email protected]0b33f80b2008-12-17 21:34:36333}
334
[email protected]767c9d92012-03-02 16:04:34335PrefService* MetricsLog::GetPrefService() {
336 return g_browser_process->local_state();
337}
338
339gfx::Size MetricsLog::GetScreenSize() const {
[email protected]42c0a0c62012-06-17 03:50:33340 return gfx::Screen::GetPrimaryDisplay().GetSizeInPixel();
[email protected]767c9d92012-03-02 16:04:34341}
342
343int MetricsLog::GetScreenCount() const {
[email protected]42c0a0c62012-06-17 03:50:33344 return gfx::Screen::GetNumDisplays();
[email protected]767c9d92012-03-02 16:04:34345}
346
[email protected]767c9d92012-03-02 16:04:34347void MetricsLog::GetFieldTrialIds(
[email protected]ad2461c2012-04-27 21:11:03348 std::vector<SelectedGroupId>* field_trial_ids) const {
349 experiments_helper::GetFieldTrialSelectedGroupIds(field_trial_ids);
[email protected]767c9d92012-03-02 16:04:34350}
351
[email protected]fe58acc22012-02-29 01:29:58352void MetricsLog::WriteStabilityElement(
353 const std::vector<webkit::WebPluginInfo>& plugin_list,
354 PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:34355 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29356
initial.commit09911bf2008-07-26 23:55:29357 // Get stability attributes out of Local State, zeroing out stored values.
358 // NOTE: This could lead to some data loss if this report isn't successfully
359 // sent, but that's true for all the metrics.
360
[email protected]ffaf78a2008-11-12 17:38:33361 OPEN_ELEMENT_FOR_SCOPE("stability");
[email protected]147bbc0b2009-01-06 19:37:40362 WriteRequiredStabilityAttributes(pref);
363 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29364
[email protected]fe58acc22012-02-29 01:29:58365 int incomplete_shutdown_count =
366 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
[email protected]e324f6b2012-02-28 05:43:37367 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58368 int breakpad_registration_success_count =
369 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
[email protected]e324f6b2012-02-28 05:43:37370 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58371 int breakpad_registration_failure_count =
372 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
[email protected]e324f6b2012-02-28 05:43:37373 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58374 int debugger_present_count =
375 pref->GetInteger(prefs::kStabilityDebuggerPresent);
[email protected]e324f6b2012-02-28 05:43:37376 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58377 int debugger_not_present_count =
378 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
[email protected]e324f6b2012-02-28 05:43:37379 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31380
[email protected]fe58acc22012-02-29 01:29:58381 // TODO(jar): The following are all optional, so we *could* optimize them for
382 // values of zero (and not include them).
383
384 // Write the XML version.
385 WriteIntAttribute("incompleteshutdowncount", incomplete_shutdown_count);
386 WriteIntAttribute("breakpadregistrationok",
387 breakpad_registration_success_count);
388 WriteIntAttribute("breakpadregistrationfail",
389 breakpad_registration_failure_count);
390 WriteIntAttribute("debuggerpresent", debugger_present_count);
391 WriteIntAttribute("debuggernotpresent", debugger_not_present_count);
392
393 // Write the protobuf version.
394 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34395 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58396 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
397 stability->set_breakpad_registration_success_count(
398 breakpad_registration_success_count);
399 stability->set_breakpad_registration_failure_count(
400 breakpad_registration_failure_count);
401 stability->set_debugger_present_count(debugger_present_count);
402 stability->set_debugger_not_present_count(debugger_not_present_count);
403
404 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40405}
406
[email protected]fe58acc22012-02-29 01:29:58407void MetricsLog::WritePluginStabilityElements(
408 const std::vector<webkit::WebPluginInfo>& plugin_list,
409 PrefService* pref) {
[email protected]147bbc0b2009-01-06 19:37:40410 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29411 const ListValue* plugin_stats_list = pref->GetList(
412 prefs::kStabilityPluginStats);
[email protected]1df44b72012-01-19 05:20:34413 if (!plugin_stats_list)
414 return;
initial.commit09911bf2008-07-26 23:55:29415
[email protected]1df44b72012-01-19 05:20:34416 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]fe58acc22012-02-29 01:29:58417 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34418 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58419 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]1df44b72012-01-19 05:20:34420 for (ListValue::const_iterator iter = plugin_stats_list->begin();
421 iter != plugin_stats_list->end(); ++iter) {
422 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
423 NOTREACHED();
424 continue;
initial.commit09911bf2008-07-26 23:55:29425 }
[email protected]1df44b72012-01-19 05:20:34426 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29427
[email protected]1df44b72012-01-19 05:20:34428 std::string plugin_name;
429 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
430
[email protected]fe58acc22012-02-29 01:29:58431 std::string base64_name_hash;
432 uint64 numeric_name_hash_ignored;
433 CreateHashes(plugin_name, &base64_name_hash, &numeric_name_hash_ignored);
434
435 // Write the XML verison.
[email protected]1df44b72012-01-19 05:20:34436 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
437 // Use "filename" instead of "name", otherwise we need to update the
438 // UMA servers.
[email protected]fe58acc22012-02-29 01:29:58439 WriteAttribute("filename", base64_name_hash);
[email protected]1df44b72012-01-19 05:20:34440
441 int launches = 0;
442 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
443 WriteIntAttribute("launchcount", launches);
444
445 int instances = 0;
446 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
447 WriteIntAttribute("instancecount", instances);
448
449 int crashes = 0;
450 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
451 WriteIntAttribute("crashcount", crashes);
[email protected]fe58acc22012-02-29 01:29:58452
453 // Write the protobuf version.
454 // Note that this search is potentially a quadratic operation, but given the
455 // low number of plugins installed on a "reasonable" setup, this should be
456 // fine.
457 // TODO(isherman): Verify that this does not show up as a hotspot in
458 // profiler runs.
459 const webkit::WebPluginInfo* plugin_info = NULL;
460 const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name);
461 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
462 plugin_list.begin();
463 iter != plugin_list.end(); ++iter) {
464 if (iter->name == plugin_name_utf16) {
465 plugin_info = &(*iter);
466 break;
467 }
468 }
469
470 if (!plugin_info) {
471 NOTREACHED();
472 continue;
473 }
474
475 SystemProfileProto::Stability::PluginStability* plugin_stability =
476 stability->add_plugin_stability();
477 SetPluginInfo(*plugin_info, plugin_prefs,
478 plugin_stability->mutable_plugin());
479 plugin_stability->set_launch_count(launches);
480 plugin_stability->set_instance_count(instances);
481 plugin_stability->set_crash_count(crashes);
initial.commit09911bf2008-07-26 23:55:29482 }
[email protected]1df44b72012-01-19 05:20:34483
484 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29485}
486
[email protected]fe58acc22012-02-29 01:29:58487// The server refuses data that doesn't have certain values. crashcount and
488// launchcount are currently "required" in the "stability" group.
489// TODO(isherman): Stop writing these attributes specially once the migration to
490// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40491void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]fe58acc22012-02-29 01:29:58492 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
[email protected]0b33f80b2008-12-17 21:34:36493 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
[email protected]fe58acc22012-02-29 01:29:58494 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
[email protected]0b33f80b2008-12-17 21:34:36495 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58496
497 // Write the XML version.
498 WriteIntAttribute("launchcount", launch_count);
499 WriteIntAttribute("crashcount", crash_count);
500
501 // Write the protobuf version.
502 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34503 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58504 stability->set_launch_count(launch_count);
505 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36506}
507
[email protected]147bbc0b2009-01-06 19:37:40508void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36509 // Update the stats which are critical for real-time stability monitoring.
510 // Since these are "optional," only list ones that are non-zero, as the counts
511 // are aggergated (summed) server side.
512
[email protected]fe58acc22012-02-29 01:29:58513 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34514 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36515 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
516 if (count) {
517 WriteIntAttribute("pageloadcount", count);
[email protected]fe58acc22012-02-29 01:29:58518 stability->set_page_load_count(count);
[email protected]0b33f80b2008-12-17 21:34:36519 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
520 }
521
522 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
523 if (count) {
524 WriteIntAttribute("renderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58525 stability->set_renderer_crash_count(count);
[email protected]0b33f80b2008-12-17 21:34:36526 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
527 }
528
[email protected]1f085622009-12-04 05:33:45529 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
530 if (count) {
531 WriteIntAttribute("extensionrenderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58532 stability->set_extension_renderer_crash_count(count);
[email protected]1f085622009-12-04 05:33:45533 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
534 }
535
[email protected]0b33f80b2008-12-17 21:34:36536 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
537 if (count) {
538 WriteIntAttribute("rendererhangcount", count);
[email protected]fe58acc22012-02-29 01:29:58539 stability->set_renderer_hang_count(count);
[email protected]0b33f80b2008-12-17 21:34:36540 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
541 }
[email protected]1f085622009-12-04 05:33:45542
543 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
544 if (count) {
545 WriteIntAttribute("childprocesscrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58546 stability->set_child_process_crash_count(count);
[email protected]1f085622009-12-04 05:33:45547 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
548 }
[email protected]9165f742010-03-10 22:55:01549
[email protected]c1834a92011-01-21 18:21:03550#if defined(OS_CHROMEOS)
551 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
552 if (count) {
[email protected]fe58acc22012-02-29 01:29:58553 stability->set_other_user_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03554 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
555 }
556
557 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
558 if (count) {
[email protected]fe58acc22012-02-29 01:29:58559 stability->set_kernel_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03560 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
561 }
562
563 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
564 if (count) {
[email protected]fe58acc22012-02-29 01:29:58565 stability->set_unclean_system_shutdown_count(count);
[email protected]c1834a92011-01-21 18:21:03566 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
567 }
568#endif // OS_CHROMEOS
569
[email protected]9165f742010-03-10 22:55:01570 int64 recent_duration = GetIncrementalUptime(pref);
[email protected]fe58acc22012-02-29 01:29:58571 if (recent_duration) {
[email protected]9165f742010-03-10 22:55:01572 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]fe58acc22012-02-29 01:29:58573 stability->set_uptime_sec(recent_duration);
574 }
[email protected]0b33f80b2008-12-17 21:34:36575}
576
initial.commit09911bf2008-07-26 23:55:29577void MetricsLog::WritePluginList(
[email protected]bc66d532012-03-23 01:57:05578 const std::vector<webkit::WebPluginInfo>& plugin_list,
579 bool write_as_xml) {
[email protected]767c9d92012-03-02 16:04:34580 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29581
[email protected]1df44b72012-01-19 05:20:34582 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]10084982011-08-19 17:56:56583
[email protected]ffaf78a2008-11-12 17:38:33584 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]767c9d92012-03-02 16:04:34585 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]91d9f3d2011-08-14 05:24:44586 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50587 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29588 iter != plugin_list.end(); ++iter) {
[email protected]bc66d532012-03-23 01:57:05589 if (write_as_xml) {
590 std::string base64_name_hash;
591 uint64 numeric_hash_ignored;
592 CreateHashes(UTF16ToUTF8(iter->name), &base64_name_hash,
593 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58594
[email protected]bc66d532012-03-23 01:57:05595 std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe();
596 std::string base64_filename_hash;
597 CreateHashes(filename_bytes, &base64_filename_hash,
598 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58599
[email protected]bc66d532012-03-23 01:57:05600 // Write the XML version.
601 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29602
[email protected]bc66d532012-03-23 01:57:05603 // Plugin name and filename are hashed for the privacy of those
604 // testing unreleased new extensions.
605 WriteAttribute("name", base64_name_hash);
606 WriteAttribute("filename", base64_filename_hash);
607 WriteAttribute("version", UTF16ToUTF8(iter->version));
608 if (plugin_prefs)
609 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
610 } else {
611 // Write the protobuf version.
612 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
613 SetPluginInfo(*iter, plugin_prefs, plugin);
614 }
initial.commit09911bf2008-07-26 23:55:29615 }
initial.commit09911bf2008-07-26 23:55:29616}
617
[email protected]147bbc0b2009-01-06 19:37:40618void MetricsLog::WriteInstallElement() {
[email protected]fe58acc22012-02-29 01:29:58619 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05620 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]147bbc0b2009-01-06 19:37:40621 OPEN_ELEMENT_FOR_SCOPE("install");
[email protected]bc66d532012-03-23 01:57:05622 WriteAttribute("installdate", GetInstallDate(GetPrefService()));
[email protected]147bbc0b2009-01-06 19:37:40623 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40624}
625
initial.commit09911bf2008-07-26 23:55:29626void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44627 const std::vector<webkit::WebPluginInfo>& plugin_list,
[email protected]197c0772012-05-14 23:50:51628 const GoogleUpdateMetrics& google_update_metrics,
initial.commit09911bf2008-07-26 23:55:29629 const DictionaryValue* profile_metrics) {
[email protected]767c9d92012-03-02 16:04:34630 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29631
[email protected]767c9d92012-03-02 16:04:34632 PrefService* pref = GetPrefService();
initial.commit09911bf2008-07-26 23:55:29633
[email protected]ffaf78a2008-11-12 17:38:33634 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29635 WriteCommonEventAttributes();
636
[email protected]147bbc0b2009-01-06 19:37:40637 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29638
[email protected]bc66d532012-03-23 01:57:05639 // Write the XML version.
640 // We'll write the protobuf version in RecordEnvironmentProto().
641 bool write_as_xml = true;
642 WritePluginList(plugin_list, write_as_xml);
initial.commit09911bf2008-07-26 23:55:29643
[email protected]fe58acc22012-02-29 01:29:58644 WriteStabilityElement(plugin_list, pref);
initial.commit09911bf2008-07-26 23:55:29645
646 {
[email protected]fe58acc22012-02-29 01:29:58647 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05648 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29649 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]bc66d532012-03-23 01:57:05650 WriteAttribute("arch", base::SysInfo::CPUArchitecture());
initial.commit09911bf2008-07-26 23:55:29651 }
652
653 {
[email protected]fe58acc22012-02-29 01:29:58654 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05655 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29656 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]bc66d532012-03-23 01:57:05657 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38658#if defined(OS_WIN)
659 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
660#endif
initial.commit09911bf2008-07-26 23:55:29661 }
662
663 {
[email protected]fe58acc22012-02-29 01:29:58664 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05665 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29666 OPEN_ELEMENT_FOR_SCOPE("os");
[email protected]bc66d532012-03-23 01:57:05667 WriteAttribute("name", base::SysInfo::OperatingSystemName());
668 WriteAttribute("version", base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29669 }
670
671 {
[email protected]e8c287c872010-07-20 00:49:42672 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]fe58acc22012-02-29 01:29:58673 const content::GPUInfo& gpu_info =
674 GpuDataManager::GetInstance()->GetGPUInfo();
[email protected]fe58acc22012-02-29 01:29:58675
676 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05677 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]a094e2c2012-05-10 23:02:42678 WriteIntAttribute("vendorid", gpu_info.gpu.vendor_id);
679 WriteIntAttribute("deviceid", gpu_info.gpu.device_id);
[email protected]e8c287c872010-07-20 00:49:42680 }
681
682 {
[email protected]767c9d92012-03-02 16:04:34683 const gfx::Size display_size = GetScreenSize();
[email protected]fe58acc22012-02-29 01:29:58684
685 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05686 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]fe58acc22012-02-29 01:29:58687 OPEN_ELEMENT_FOR_SCOPE("display");
[email protected]bc66d532012-03-23 01:57:05688 WriteIntAttribute("xsize", display_size.width());
689 WriteIntAttribute("ysize", display_size.height());
690 WriteIntAttribute("screens", GetScreenCount());
initial.commit09911bf2008-07-26 23:55:29691 }
692
693 {
694 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
695 int num_bookmarks_on_bookmark_bar =
696 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
697 int num_folders_on_bookmark_bar =
698 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
699 int num_bookmarks_in_other_bookmarks_folder =
700 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
701 int num_folders_in_other_bookmarks_folder =
702 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
703 {
704 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
705 WriteAttribute("name", "full-tree");
706 WriteIntAttribute("foldercount",
707 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
708 WriteIntAttribute("itemcount",
709 num_bookmarks_on_bookmark_bar +
710 num_bookmarks_in_other_bookmarks_folder);
711 }
712 {
713 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
714 WriteAttribute("name", "toolbar");
715 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
716 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
717 }
718 }
719
720 {
721 OPEN_ELEMENT_FOR_SCOPE("keywords");
722 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
723 }
724
725 if (profile_metrics)
726 WriteAllProfilesMetrics(*profile_metrics);
[email protected]767c9d92012-03-02 16:04:34727
[email protected]197c0772012-05-14 23:50:51728 RecordEnvironmentProto(plugin_list, google_update_metrics);
[email protected]bc66d532012-03-23 01:57:05729}
730
731void MetricsLog::RecordEnvironmentProto(
[email protected]197c0772012-05-14 23:50:51732 const std::vector<webkit::WebPluginInfo>& plugin_list,
733 const GoogleUpdateMetrics& google_update_metrics) {
[email protected]bc66d532012-03-23 01:57:05734 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
735 int install_date;
736 bool success = base::StringToInt(GetInstallDate(GetPrefService()),
737 &install_date);
738 DCHECK(success);
739 system_profile->set_install_date(install_date);
740
741 system_profile->set_application_locale(
742 content::GetContentClient()->browser()->GetApplicationLocale());
743
744 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
745 hardware->set_cpu_architecture(base::SysInfo::CPUArchitecture());
746 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
747#if defined(OS_WIN)
748 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
749#endif
750
751 SystemProfileProto::OS* os = system_profile->mutable_os();
752 os->set_name(base::SysInfo::OperatingSystemName());
753 os->set_version(base::SysInfo::OperatingSystemVersion());
754
755 const content::GPUInfo& gpu_info =
756 GpuDataManager::GetInstance()->GetGPUInfo();
757 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
[email protected]a094e2c2012-05-10 23:02:42758 gpu->set_vendor_id(gpu_info.gpu.vendor_id);
759 gpu->set_device_id(gpu_info.gpu.device_id);
[email protected]bc66d532012-03-23 01:57:05760 gpu->set_driver_version(gpu_info.driver_version);
761 gpu->set_driver_date(gpu_info.driver_date);
762 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
763 gpu_performance = gpu->mutable_performance_statistics();
764 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
765 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
766 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
767
768 const gfx::Size display_size = GetScreenSize();
769 hardware->set_primary_screen_width(display_size.width());
770 hardware->set_primary_screen_height(display_size.height());
771 hardware->set_screen_count(GetScreenCount());
772
[email protected]197c0772012-05-14 23:50:51773 WriteGoogleUpdateProto(google_update_metrics);
774
[email protected]bc66d532012-03-23 01:57:05775 bool write_as_xml = false;
776 WritePluginList(plugin_list, write_as_xml);
777
[email protected]ad2461c2012-04-27 21:11:03778 std::vector<SelectedGroupId> field_trial_ids;
[email protected]767c9d92012-03-02 16:04:34779 GetFieldTrialIds(&field_trial_ids);
780 WriteFieldTrials(field_trial_ids, system_profile);
initial.commit09911bf2008-07-26 23:55:29781}
782
[email protected]ed0fd002012-04-25 23:10:34783void MetricsLog::RecordProfilerData(
784 const tracked_objects::ProcessDataSnapshot& process_data,
785 content::ProcessType process_type) {
786 DCHECK(!locked());
787
[email protected]8f829682012-04-27 00:36:49788 if (tracked_objects::GetTimeSourceType() !=
789 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) {
[email protected]ed0fd002012-04-25 23:10:34790 // We currently only support the default time source, wall clock time.
791 return;
792 }
793
794 ProfilerEventProto* profile;
795 if (!uma_proto()->profiler_event_size()) {
796 // For the first process's data, add a new field to the protocol buffer.
797 profile = uma_proto()->add_profiler_event();
798 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
799 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
800 } else {
801 // For the remaining calls, re-use the existing field.
802 profile = uma_proto()->mutable_profiler_event(0);
803 }
804
805 WriteProfilerData(process_data, process_type, profile);
806}
807
initial.commit09911bf2008-07-26 23:55:29808void MetricsLog::WriteAllProfilesMetrics(
809 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51810 const std::string profile_prefix(prefs::kProfilePrefix);
initial.commit09911bf2008-07-26 23:55:29811 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
812 i != all_profiles_metrics.end_keys(); ++i) {
[email protected]e7b418b2010-07-30 19:47:47813 const std::string& key_name = *i;
initial.commit09911bf2008-07-26 23:55:29814 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
815 DictionaryValue* profile;
[email protected]4dad9ad82009-11-25 20:47:52816 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
817 &profile))
initial.commit09911bf2008-07-26 23:55:29818 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
819 }
820 }
821}
822
[email protected]e7b418b2010-07-30 19:47:47823void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29824 const DictionaryValue& profile_metrics) {
825 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47826 WriteAttribute("profileidhash", profileidhash);
initial.commit09911bf2008-07-26 23:55:29827 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
828 i != profile_metrics.end_keys(); ++i) {
829 Value* value;
[email protected]4dad9ad82009-11-25 20:47:52830 if (profile_metrics.GetWithoutPathExpansion(*i, &value)) {
[email protected]e7b418b2010-07-30 19:47:47831 DCHECK(*i != "id");
initial.commit09911bf2008-07-26 23:55:29832 switch (value->GetType()) {
833 case Value::TYPE_STRING: {
[email protected]5e324b72008-12-18 00:07:59834 std::string string_value;
initial.commit09911bf2008-07-26 23:55:29835 if (value->GetAsString(&string_value)) {
836 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47837 WriteAttribute("name", *i);
[email protected]5e324b72008-12-18 00:07:59838 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29839 }
840 break;
841 }
842
843 case Value::TYPE_BOOLEAN: {
844 bool bool_value;
845 if (value->GetAsBoolean(&bool_value)) {
846 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47847 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29848 WriteIntAttribute("value", bool_value ? 1 : 0);
849 }
850 break;
851 }
852
853 case Value::TYPE_INTEGER: {
854 int int_value;
855 if (value->GetAsInteger(&int_value)) {
856 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47857 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29858 WriteIntAttribute("value", int_value);
859 }
860 break;
861 }
862
863 default:
864 NOTREACHED();
865 break;
866 }
867 }
868 }
869}
870
871void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
[email protected]767c9d92012-03-02 16:04:34872 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29873
[email protected]fe58acc22012-02-29 01:29:58874 // Write the XML version.
[email protected]ffaf78a2008-11-12 17:38:33875 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29876 WriteAttribute("action", "autocomplete");
877 WriteAttribute("targetidhash", "");
878 // TODO(kochi): Properly track windows.
879 WriteIntAttribute("window", 0);
[email protected]6ebc3162011-12-19 13:44:00880 if (log.tab_id != -1) {
881 // If we know what tab the autocomplete URL was opened in, log it.
882 WriteIntAttribute("tab", static_cast<int>(log.tab_id));
883 }
initial.commit09911bf2008-07-26 23:55:29884 WriteCommonEventAttributes();
885
[email protected]65956312012-04-19 21:28:12886 std::vector<string16> terms;
887 const int num_terms =
888 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms));
[email protected]ffaf78a2008-11-12 17:38:33889 {
890 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29891
[email protected]ffaf78a2008-11-12 17:38:33892 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
[email protected]65956312012-04-19 21:28:12893 WriteIntAttribute("numterms", num_terms);
[email protected]ffaf78a2008-11-12 17:38:33894 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
895 WriteIntAttribute("completedlength",
896 static_cast<int>(log.inline_autocompleted_length));
[email protected]9e349762012-01-31 03:24:36897 if (log.elapsed_time_since_user_first_modified_omnibox !=
898 base::TimeDelta::FromMilliseconds(-1)) {
899 // Only upload the typing duration if it is set/valid.
900 WriteInt64Attribute("typingduration",
901 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
902 }
[email protected]381e2992008-12-16 01:41:00903 const std::string input_type(
904 AutocompleteInput::TypeToString(log.input_type));
905 if (!input_type.empty())
906 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:29907
[email protected]ffaf78a2008-11-12 17:38:33908 for (AutocompleteResult::const_iterator i(log.result.begin());
909 i != log.result.end(); ++i) {
910 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
911 if (i->provider)
912 WriteAttribute("provider", i->provider->name());
[email protected]381e2992008-12-16 01:41:00913 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
914 if (!result_type.empty())
915 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:33916 WriteIntAttribute("relevance", i->relevance);
917 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
918 }
initial.commit09911bf2008-07-26 23:55:29919 }
initial.commit09911bf2008-07-26 23:55:29920
[email protected]fe58acc22012-02-29 01:29:58921 // Write the protobuf version.
[email protected]767c9d92012-03-02 16:04:34922 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
[email protected]fe58acc22012-02-29 01:29:58923 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
924 if (log.tab_id != -1) {
925 // If we know what tab the autocomplete URL was opened in, log it.
926 omnibox_event->set_tab_id(log.tab_id);
927 }
928 omnibox_event->set_typed_length(log.text.length());
[email protected]660fe8f32012-05-03 20:01:08929 omnibox_event->set_just_deleted_text(log.just_deleted_text);
[email protected]65956312012-04-19 21:28:12930 omnibox_event->set_num_typed_terms(num_terms);
[email protected]fe58acc22012-02-29 01:29:58931 omnibox_event->set_selected_index(log.selected_index);
932 omnibox_event->set_completed_length(log.inline_autocompleted_length);
[email protected]65956312012-04-19 21:28:12933 if (log.elapsed_time_since_user_first_modified_omnibox !=
934 base::TimeDelta::FromMilliseconds(-1)) {
935 // Only upload the typing duration if it is set/valid.
936 omnibox_event->set_typing_duration_ms(
937 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
938 }
[email protected]ee902532012-05-01 23:54:49939 omnibox_event->set_current_page_classification(
940 log.current_page_classification);
[email protected]fe58acc22012-02-29 01:29:58941 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
942 for (AutocompleteResult::const_iterator i(log.result.begin());
943 i != log.result.end(); ++i) {
944 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
[email protected]0e9e8782012-05-15 23:01:51945 suggestion->set_provider(i->provider->AsOmniboxEventProviderType());
[email protected]fe58acc22012-02-29 01:29:58946 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
947 suggestion->set_relevance(i->relevance);
[email protected]cf6256f2012-06-12 23:36:01948 if (i->typed_count != -1)
949 suggestion->set_typed_count(i->typed_count);
[email protected]fe58acc22012-02-29 01:29:58950 suggestion->set_is_starred(i->starred);
951 }
[email protected]0e9e8782012-05-15 23:01:51952 for (ProvidersInfo::const_iterator i(log.providers_info.begin());
953 i != log.providers_info.end(); ++i) {
954 OmniboxEventProto::ProviderInfo* provider_info =
955 omnibox_event->add_provider_info();
956 provider_info->CopyFrom(*i);
957 }
[email protected]fe58acc22012-02-29 01:29:58958
initial.commit09911bf2008-07-26 23:55:29959 ++num_events_;
960}
[email protected]197c0772012-05-14 23:50:51961
962void MetricsLog::WriteGoogleUpdateProto(
963 const GoogleUpdateMetrics& google_update_metrics) {
964#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
965 SystemProfileProto::GoogleUpdate* google_update =
966 uma_proto()->mutable_system_profile()->mutable_google_update();
967
968 google_update->set_is_system_install(google_update_metrics.is_system_install);
969
970 if (!google_update_metrics.last_started_au.is_null()) {
971 google_update->set_last_automatic_start_timestamp(
972 google_update_metrics.last_started_au.ToTimeT());
973 }
974
975 if (!google_update_metrics.last_checked.is_null()) {
976 google_update->set_last_update_check_timestamp(
977 google_update_metrics.last_checked.ToTimeT());
978 }
979
980 if (!google_update_metrics.google_update_data.version.empty()) {
981 ProductDataToProto(google_update_metrics.google_update_data,
982 google_update->mutable_google_update_status());
983 }
984
985 if (!google_update_metrics.product_data.version.empty()) {
986 ProductDataToProto(google_update_metrics.product_data,
987 google_update->mutable_client_status());
988 }
989#endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
990}