OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 //------------------------------------------------------------------------------ | 5 //------------------------------------------------------------------------------ |
6 // Description of the life cycle of a instance of MetricsService. | 6 // Description of the life cycle of a instance of MetricsService. |
7 // | 7 // |
8 // OVERVIEW | 8 // OVERVIEW |
9 // | 9 // |
10 // A MetricsService instance is typically created at application startup. It is | 10 // A MetricsService instance is typically created at application startup. It is |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 #include <algorithm> | 166 #include <algorithm> |
167 | 167 |
168 #include "base/bind.h" | 168 #include "base/bind.h" |
169 #include "base/callback.h" | 169 #include "base/callback.h" |
170 #include "base/command_line.h" | 170 #include "base/command_line.h" |
171 #include "base/metrics/histogram.h" | 171 #include "base/metrics/histogram.h" |
172 #include "base/metrics/sparse_histogram.h" | 172 #include "base/metrics/sparse_histogram.h" |
173 #include "base/metrics/statistics_recorder.h" | 173 #include "base/metrics/statistics_recorder.h" |
174 #include "base/prefs/pref_registry_simple.h" | 174 #include "base/prefs/pref_registry_simple.h" |
175 #include "base/prefs/pref_service.h" | 175 #include "base/prefs/pref_service.h" |
176 #include "base/prefs/scoped_user_pref_update.h" | |
177 #include "base/strings/string_number_conversions.h" | 176 #include "base/strings/string_number_conversions.h" |
178 #include "base/strings/utf_string_conversions.h" | 177 #include "base/strings/utf_string_conversions.h" |
179 #include "base/threading/platform_thread.h" | 178 #include "base/threading/platform_thread.h" |
180 #include "base/threading/thread.h" | 179 #include "base/threading/thread.h" |
181 #include "base/threading/thread_restrictions.h" | 180 #include "base/threading/thread_restrictions.h" |
182 #include "base/tracked_objects.h" | 181 #include "base/tracked_objects.h" |
183 #include "base/values.h" | 182 #include "base/values.h" |
184 #include "chrome/browser/browser_process.h" | 183 #include "chrome/browser/browser_process.h" |
185 #include "chrome/browser/chrome_notification_types.h" | 184 #include "chrome/browser/chrome_notification_types.h" |
186 #include "chrome/browser/io_thread.h" | 185 #include "chrome/browser/io_thread.h" |
187 #include "chrome/browser/memory_details.h" | 186 #include "chrome/browser/memory_details.h" |
188 #include "chrome/browser/metrics/compression_utils.h" | 187 #include "chrome/browser/metrics/compression_utils.h" |
189 #include "chrome/browser/metrics/metrics_log.h" | 188 #include "chrome/browser/metrics/metrics_log.h" |
190 #include "chrome/browser/metrics/metrics_state_manager.h" | 189 #include "chrome/browser/metrics/metrics_state_manager.h" |
191 #include "chrome/browser/metrics/omnibox_metrics_provider.h" | 190 #include "chrome/browser/metrics/omnibox_metrics_provider.h" |
192 #include "chrome/browser/metrics/tracking_synchronizer.h" | 191 #include "chrome/browser/metrics/tracking_synchronizer.h" |
193 #include "chrome/browser/ui/browser_otr_state.h" | 192 #include "chrome/browser/ui/browser_otr_state.h" |
194 #include "chrome/common/chrome_constants.h" | 193 #include "chrome/common/chrome_constants.h" |
195 #include "chrome/common/chrome_switches.h" | 194 #include "chrome/common/chrome_switches.h" |
196 #include "chrome/common/crash_keys.h" | 195 #include "chrome/common/crash_keys.h" |
197 #include "chrome/common/pref_names.h" | 196 #include "chrome/common/pref_names.h" |
198 #include "chrome/common/render_messages.h" | 197 #include "chrome/common/render_messages.h" |
199 #include "chrome/common/variations/variations_util.h" | 198 #include "chrome/common/variations/variations_util.h" |
200 #include "components/metrics/metrics_log_manager.h" | 199 #include "components/metrics/metrics_log_manager.h" |
201 #include "components/metrics/metrics_pref_names.h" | 200 #include "components/metrics/metrics_pref_names.h" |
202 #include "components/metrics/metrics_reporting_scheduler.h" | 201 #include "components/metrics/metrics_reporting_scheduler.h" |
203 #include "components/metrics/metrics_service_client.h" | 202 #include "components/metrics/metrics_service_client.h" |
204 #include "components/variations/entropy_provider.h" | 203 #include "components/variations/entropy_provider.h" |
205 #include "components/variations/metrics_util.h" | |
206 #include "content/public/browser/child_process_data.h" | 204 #include "content/public/browser/child_process_data.h" |
207 #include "content/public/browser/histogram_fetcher.h" | 205 #include "content/public/browser/histogram_fetcher.h" |
208 #include "content/public/browser/load_notification_details.h" | 206 #include "content/public/browser/load_notification_details.h" |
209 #include "content/public/browser/notification_service.h" | 207 #include "content/public/browser/notification_service.h" |
210 #include "content/public/browser/plugin_service.h" | |
211 #include "content/public/browser/render_process_host.h" | 208 #include "content/public/browser/render_process_host.h" |
212 #include "content/public/browser/user_metrics.h" | 209 #include "content/public/browser/user_metrics.h" |
213 #include "content/public/browser/web_contents.h" | 210 #include "content/public/browser/web_contents.h" |
214 #include "content/public/common/process_type.h" | |
215 #include "content/public/common/webplugininfo.h" | |
216 #include "extensions/browser/process_map.h" | 211 #include "extensions/browser/process_map.h" |
217 #include "net/base/load_flags.h" | 212 #include "net/base/load_flags.h" |
218 #include "net/url_request/url_fetcher.h" | 213 #include "net/url_request/url_fetcher.h" |
219 | 214 |
215 #if defined(ENABLE_PLUGINS) | |
216 // TODO(asvitkine): Move this out of MetricsService. | |
217 #include "chrome/browser/metrics/plugin_metrics_provider.h" | |
218 #endif | |
219 | |
220 #if defined(OS_CHROMEOS) | 220 #if defined(OS_CHROMEOS) |
221 #include "chrome/browser/chromeos/settings/cros_settings.h" | 221 #include "chrome/browser/chromeos/settings/cros_settings.h" |
222 #include "chromeos/system/statistics_provider.h" | 222 #include "chromeos/system/statistics_provider.h" |
223 #endif | 223 #endif |
224 | 224 |
225 #if defined(OS_WIN) | 225 #if defined(OS_WIN) |
226 #include <windows.h> // Needed for STATUS_* codes | 226 #include <windows.h> // Needed for STATUS_* codes |
227 #include "base/win/registry.h" | 227 #include "base/win/registry.h" |
228 #include "chrome/browser/metrics/google_update_metrics_provider_win.h" | 228 #include "chrome/browser/metrics/google_update_metrics_provider_win.h" |
229 #endif | 229 #endif |
230 | 230 |
231 #if defined(OS_ANDROID) | 231 #if defined(OS_ANDROID) |
232 // TODO(asvitkine): Move this out of MetricsService. | 232 // TODO(asvitkine): Move this out of MetricsService. |
233 #include "chrome/browser/metrics/android_metrics_provider.h" | 233 #include "chrome/browser/metrics/android_metrics_provider.h" |
234 #else | 234 #else |
235 #include "chrome/browser/service_process/service_process_control.h" | 235 #include "chrome/browser/service_process/service_process_control.h" |
236 #endif | 236 #endif |
237 | 237 |
238 using base::Time; | 238 using base::Time; |
239 using content::BrowserThread; | 239 using content::BrowserThread; |
240 using content::ChildProcessData; | |
241 using content::LoadNotificationDetails; | 240 using content::LoadNotificationDetails; |
242 using content::PluginService; | |
243 using metrics::MetricsLogManager; | 241 using metrics::MetricsLogManager; |
244 | 242 |
245 namespace { | 243 namespace { |
246 | 244 |
247 // Check to see that we're being called on only one thread. | 245 // Check to see that we're being called on only one thread. |
248 bool IsSingleThreaded() { | 246 bool IsSingleThreaded() { |
249 static base::PlatformThreadId thread_id = 0; | 247 static base::PlatformThreadId thread_id = 0; |
250 if (!thread_id) | 248 if (!thread_id) |
251 thread_id = base::PlatformThread::CurrentId(); | 249 thread_id = base::PlatformThread::CurrentId(); |
252 return base::PlatformThread::CurrentId() == thread_id; | 250 return base::PlatformThread::CurrentId() == thread_id; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 SyntheticTrialGroup::~SyntheticTrialGroup() { | 333 SyntheticTrialGroup::~SyntheticTrialGroup() { |
336 } | 334 } |
337 | 335 |
338 // static | 336 // static |
339 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ = | 337 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ = |
340 MetricsService::CLEANLY_SHUTDOWN; | 338 MetricsService::CLEANLY_SHUTDOWN; |
341 | 339 |
342 MetricsService::ExecutionPhase MetricsService::execution_phase_ = | 340 MetricsService::ExecutionPhase MetricsService::execution_phase_ = |
343 MetricsService::UNINITIALIZED_PHASE; | 341 MetricsService::UNINITIALIZED_PHASE; |
344 | 342 |
345 // This is used to quickly log stats from child process related notifications in | |
346 // MetricsService::child_stats_buffer_. The buffer's contents are transferred | |
347 // out when Local State is periodically saved. The information is then | |
348 // reported to the UMA server on next launch. | |
349 struct MetricsService::ChildProcessStats { | |
350 public: | |
351 explicit ChildProcessStats(int process_type) | |
352 : process_launches(0), | |
353 process_crashes(0), | |
354 instances(0), | |
355 loading_errors(0), | |
356 process_type(process_type) {} | |
357 | |
358 // This constructor is only used by the map to return some default value for | |
359 // an index for which no value has been assigned. | |
360 ChildProcessStats() | |
361 : process_launches(0), | |
362 process_crashes(0), | |
363 instances(0), | |
364 loading_errors(0), | |
365 process_type(content::PROCESS_TYPE_UNKNOWN) {} | |
366 | |
367 // The number of times that the given child process has been launched | |
368 int process_launches; | |
369 | |
370 // The number of times that the given child process has crashed | |
371 int process_crashes; | |
372 | |
373 // The number of instances of this child process that have been created. | |
374 // An instance is a DOM object rendered by this child process during a page | |
375 // load. | |
376 int instances; | |
377 | |
378 // The number of times there was an error loading an instance of this child | |
379 // process. | |
380 int loading_errors; | |
381 | |
382 int process_type; | |
383 }; | |
384 | |
385 // Handles asynchronous fetching of memory details. | 343 // Handles asynchronous fetching of memory details. |
386 // Will run the provided task after finished. | 344 // Will run the provided task after finished. |
387 class MetricsMemoryDetails : public MemoryDetails { | 345 class MetricsMemoryDetails : public MemoryDetails { |
388 public: | 346 public: |
389 explicit MetricsMemoryDetails(const base::Closure& callback) | 347 explicit MetricsMemoryDetails(const base::Closure& callback) |
390 : callback_(callback) {} | 348 : callback_(callback) {} |
391 | 349 |
392 virtual void OnDetailsAvailable() OVERRIDE { | 350 virtual void OnDetailsAvailable() OVERRIDE { |
393 base::MessageLoop::current()->PostTask(FROM_HERE, callback_); | 351 base::MessageLoop::current()->PostTask(FROM_HERE, callback_); |
394 } | 352 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
446 registry->RegisterInt64Pref(prefs::kUninstallMetricsPageLoadCount, 0); | 404 registry->RegisterInt64Pref(prefs::kUninstallMetricsPageLoadCount, 0); |
447 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0); | 405 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0); |
448 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0); | 406 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0); |
449 registry->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0); | 407 registry->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0); |
450 registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0); | 408 registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0); |
451 | 409 |
452 #if defined(OS_ANDROID) | 410 #if defined(OS_ANDROID) |
453 // TODO(asvitkine): Move this out of here. | 411 // TODO(asvitkine): Move this out of here. |
454 AndroidMetricsProvider::RegisterPrefs(registry); | 412 AndroidMetricsProvider::RegisterPrefs(registry); |
455 #endif // defined(OS_ANDROID) | 413 #endif // defined(OS_ANDROID) |
414 | |
415 PluginMetricsProvider::RegisterPrefs(registry); | |
456 } | 416 } |
457 | 417 |
458 MetricsService::MetricsService(metrics::MetricsStateManager* state_manager, | 418 MetricsService::MetricsService(metrics::MetricsStateManager* state_manager, |
459 metrics::MetricsServiceClient* client) | 419 metrics::MetricsServiceClient* client) |
460 : MetricsServiceBase(g_browser_process->local_state(), | 420 : MetricsServiceBase(g_browser_process->local_state(), |
461 kUploadLogAvoidRetransmitSize), | 421 kUploadLogAvoidRetransmitSize), |
462 state_manager_(state_manager), | 422 state_manager_(state_manager), |
463 client_(client), | 423 client_(client), |
464 recording_active_(false), | 424 recording_active_(false), |
465 reporting_active_(false), | 425 reporting_active_(false), |
(...skipping 20 matching lines...) Expand all Loading... | |
486 | 446 |
487 // TODO(asvitkine): Move this out of MetricsService. | 447 // TODO(asvitkine): Move this out of MetricsService. |
488 RegisterMetricsProvider( | 448 RegisterMetricsProvider( |
489 scoped_ptr<metrics::MetricsProvider>(new OmniboxMetricsProvider)); | 449 scoped_ptr<metrics::MetricsProvider>(new OmniboxMetricsProvider)); |
490 | 450 |
491 #if defined(OS_WIN) | 451 #if defined(OS_WIN) |
492 google_update_metrics_provider_ = new GoogleUpdateMetricsProviderWin; | 452 google_update_metrics_provider_ = new GoogleUpdateMetricsProviderWin; |
493 RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider>( | 453 RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider>( |
494 google_update_metrics_provider_)); | 454 google_update_metrics_provider_)); |
495 #endif | 455 #endif |
456 | |
457 #if defined(ENABLE_PLUGINS) | |
458 plugin_metrics_provider_ = new PluginMetricsProvider( | |
459 g_browser_process->local_state()); | |
460 RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider>( | |
461 plugin_metrics_provider_)); | |
462 #endif | |
463 | |
496 BrowserChildProcessObserver::Add(this); | 464 BrowserChildProcessObserver::Add(this); |
497 } | 465 } |
498 | 466 |
499 MetricsService::~MetricsService() { | 467 MetricsService::~MetricsService() { |
500 DisableRecording(); | 468 DisableRecording(); |
501 | 469 |
502 BrowserChildProcessObserver::Remove(this); | 470 BrowserChildProcessObserver::Remove(this); |
503 } | 471 } |
504 | 472 |
505 void MetricsService::InitializeMetricsRecordingState() { | 473 void MetricsService::InitializeMetricsRecordingState() { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
611 content::NotificationRegistrar* registrar, | 579 content::NotificationRegistrar* registrar, |
612 content::NotificationObserver* observer) { | 580 content::NotificationObserver* observer) { |
613 registrar->Add(observer, content::NOTIFICATION_LOAD_START, | 581 registrar->Add(observer, content::NOTIFICATION_LOAD_START, |
614 content::NotificationService::AllSources()); | 582 content::NotificationService::AllSources()); |
615 registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 583 registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
616 content::NotificationService::AllSources()); | 584 content::NotificationService::AllSources()); |
617 registrar->Add(observer, content::NOTIFICATION_RENDER_WIDGET_HOST_HANG, | 585 registrar->Add(observer, content::NOTIFICATION_RENDER_WIDGET_HOST_HANG, |
618 content::NotificationService::AllSources()); | 586 content::NotificationService::AllSources()); |
619 } | 587 } |
620 | 588 |
621 void MetricsService::BrowserChildProcessHostConnected( | |
622 const content::ChildProcessData& data) { | |
623 GetChildProcessStats(data).process_launches++; | |
624 } | |
625 | |
626 void MetricsService::BrowserChildProcessCrashed( | 589 void MetricsService::BrowserChildProcessCrashed( |
627 const content::ChildProcessData& data) { | 590 const content::ChildProcessData& data) { |
628 GetChildProcessStats(data).process_crashes++; | |
629 // Exclude plugin crashes from the count below because we report them via | 591 // Exclude plugin crashes from the count below because we report them via |
630 // a separate UMA metric. | 592 // a separate UMA metric. |
593 // TODO(asvitkine): Move this into ChromeStabilityStatsProvider. | |
631 if (!IsPluginProcess(data.process_type)) | 594 if (!IsPluginProcess(data.process_type)) |
632 IncrementPrefValue(prefs::kStabilityChildProcessCrashCount); | 595 IncrementPrefValue(prefs::kStabilityChildProcessCrashCount); |
633 } | 596 } |
634 | 597 |
635 void MetricsService::BrowserChildProcessInstanceCreated( | |
636 const content::ChildProcessData& data) { | |
637 GetChildProcessStats(data).instances++; | |
638 } | |
639 | |
640 void MetricsService::Observe(int type, | 598 void MetricsService::Observe(int type, |
641 const content::NotificationSource& source, | 599 const content::NotificationSource& source, |
642 const content::NotificationDetails& details) { | 600 const content::NotificationDetails& details) { |
643 DCHECK(log_manager_.current_log()); | 601 DCHECK(log_manager_.current_log()); |
644 DCHECK(IsSingleThreaded()); | 602 DCHECK(IsSingleThreaded()); |
645 | 603 |
646 switch (type) { | 604 switch (type) { |
647 case content::NOTIFICATION_LOAD_START: { | 605 case content::NOTIFICATION_LOAD_START: { |
648 content::NavigationController* controller = | 606 content::NavigationController* controller = |
649 content::Source<content::NavigationController>(source).ptr(); | 607 content::Source<content::NavigationController>(source).ptr(); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
912 target_loop->PostTask(FROM_HERE, | 870 target_loop->PostTask(FROM_HERE, |
913 base::Bind(&MetricsService::OnInitTaskGotHardwareClass, | 871 base::Bind(&MetricsService::OnInitTaskGotHardwareClass, |
914 self, hardware_class)); | 872 self, hardware_class)); |
915 } | 873 } |
916 | 874 |
917 void MetricsService::OnInitTaskGotHardwareClass( | 875 void MetricsService::OnInitTaskGotHardwareClass( |
918 const std::string& hardware_class) { | 876 const std::string& hardware_class) { |
919 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); | 877 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); |
920 hardware_class_ = hardware_class; | 878 hardware_class_ = hardware_class; |
921 | 879 |
880 const base::Closure got_metrics_callback = | |
Ilya Sherman
2014/05/22 14:52:20
nit: Perhaps "got_plugin_info_callback"?
Alexei Svitkine (slow)
2014/05/22 15:38:54
Done.
| |
881 base::Bind(&MetricsService::OnInitTaskGotPluginInfo, | |
882 self_ptr_factory_.GetWeakPtr()); | |
883 | |
922 #if defined(ENABLE_PLUGINS) | 884 #if defined(ENABLE_PLUGINS) |
923 // Start the next part of the init task: loading plugin information. | 885 plugin_metrics_provider_->GetPluginInformation(got_metrics_callback); |
924 PluginService::GetInstance()->GetPlugins( | |
925 base::Bind(&MetricsService::OnInitTaskGotPluginInfo, | |
926 self_ptr_factory_.GetWeakPtr())); | |
927 #else | 886 #else |
928 std::vector<content::WebPluginInfo> plugin_list_empty; | 887 got_metrics_callback.Run(); |
929 OnInitTaskGotPluginInfo(plugin_list_empty); | 888 #endif |
930 #endif // defined(ENABLE_PLUGINS) | |
931 } | 889 } |
932 | 890 |
933 void MetricsService::OnInitTaskGotPluginInfo( | 891 void MetricsService::OnInitTaskGotPluginInfo() { |
934 const std::vector<content::WebPluginInfo>& plugins) { | |
935 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); | 892 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); |
936 plugins_ = plugins; | |
937 | 893 |
938 const base::Closure got_metrics_callback = | 894 const base::Closure got_metrics_callback = |
939 base::Bind(&MetricsService::OnInitTaskGotGoogleUpdateData, | 895 base::Bind(&MetricsService::OnInitTaskGotGoogleUpdateData, |
940 self_ptr_factory_.GetWeakPtr()); | 896 self_ptr_factory_.GetWeakPtr()); |
941 | 897 |
942 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) | 898 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) |
943 google_update_metrics_provider_->GetGoogleUpdateData(got_metrics_callback); | 899 google_update_metrics_provider_->GetGoogleUpdateData(got_metrics_callback); |
944 #else | 900 #else |
945 got_metrics_callback.Run(); | 901 got_metrics_callback.Run(); |
946 #endif | 902 #endif |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1096 | 1052 |
1097 // Put incremental data (histogram deltas, and realtime stats deltas) at the | 1053 // Put incremental data (histogram deltas, and realtime stats deltas) at the |
1098 // end of all log transmissions (initial log handles this separately). | 1054 // end of all log transmissions (initial log handles this separately). |
1099 // RecordIncrementalStabilityElements only exists on the derived | 1055 // RecordIncrementalStabilityElements only exists on the derived |
1100 // MetricsLog class. | 1056 // MetricsLog class. |
1101 MetricsLog* current_log = | 1057 MetricsLog* current_log = |
1102 static_cast<MetricsLog*>(log_manager_.current_log()); | 1058 static_cast<MetricsLog*>(log_manager_.current_log()); |
1103 DCHECK(current_log); | 1059 DCHECK(current_log); |
1104 std::vector<variations::ActiveGroupId> synthetic_trials; | 1060 std::vector<variations::ActiveGroupId> synthetic_trials; |
1105 GetCurrentSyntheticFieldTrials(&synthetic_trials); | 1061 GetCurrentSyntheticFieldTrials(&synthetic_trials); |
1106 current_log->RecordEnvironment(metrics_providers_.get(), plugins_, | 1062 current_log->RecordEnvironment(metrics_providers_.get(), synthetic_trials); |
1107 synthetic_trials); | |
1108 PrefService* pref = g_browser_process->local_state(); | 1063 PrefService* pref = g_browser_process->local_state(); |
1109 base::TimeDelta incremental_uptime; | 1064 base::TimeDelta incremental_uptime; |
1110 base::TimeDelta uptime; | 1065 base::TimeDelta uptime; |
1111 GetUptimes(pref, &incremental_uptime, &uptime); | 1066 GetUptimes(pref, &incremental_uptime, &uptime); |
1112 current_log->RecordStabilityMetrics(metrics_providers_.get(), | 1067 current_log->RecordStabilityMetrics(metrics_providers_.get(), |
1113 incremental_uptime, uptime); | 1068 incremental_uptime, uptime); |
1114 | 1069 |
1115 RecordCurrentHistograms(); | 1070 RecordCurrentHistograms(); |
1116 current_log->RecordGeneralMetrics(metrics_providers_.get()); | 1071 current_log->RecordGeneralMetrics(metrics_providers_.get()); |
1117 | 1072 |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1391 | 1346 |
1392 has_initial_stability_log_ = true; | 1347 has_initial_stability_log_ = true; |
1393 } | 1348 } |
1394 | 1349 |
1395 void MetricsService::PrepareInitialMetricsLog() { | 1350 void MetricsService::PrepareInitialMetricsLog() { |
1396 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG); | 1351 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG); |
1397 initial_metrics_log_->set_hardware_class(hardware_class_); | 1352 initial_metrics_log_->set_hardware_class(hardware_class_); |
1398 | 1353 |
1399 std::vector<variations::ActiveGroupId> synthetic_trials; | 1354 std::vector<variations::ActiveGroupId> synthetic_trials; |
1400 GetCurrentSyntheticFieldTrials(&synthetic_trials); | 1355 GetCurrentSyntheticFieldTrials(&synthetic_trials); |
1401 initial_metrics_log_->RecordEnvironment(metrics_providers_.get(), plugins_, | 1356 initial_metrics_log_->RecordEnvironment(metrics_providers_.get(), |
1402 synthetic_trials); | 1357 synthetic_trials); |
1403 PrefService* pref = g_browser_process->local_state(); | 1358 PrefService* pref = g_browser_process->local_state(); |
1404 base::TimeDelta incremental_uptime; | 1359 base::TimeDelta incremental_uptime; |
1405 base::TimeDelta uptime; | 1360 base::TimeDelta uptime; |
1406 GetUptimes(pref, &incremental_uptime, &uptime); | 1361 GetUptimes(pref, &incremental_uptime, &uptime); |
1407 | 1362 |
1408 // Histograms only get written to the current log, so make the new log current | 1363 // Histograms only get written to the current log, so make the new log current |
1409 // before writing them. | 1364 // before writing them. |
1410 log_manager_.PauseCurrentLog(); | 1365 log_manager_.PauseCurrentLog(); |
1411 log_manager_.BeginLoggingWithLog(initial_metrics_log_.release()); | 1366 log_manager_.BeginLoggingWithLog(initial_metrics_log_.release()); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1711 IncrementPrefValue(prefs::kStabilitySystemUncleanShutdownCount); | 1666 IncrementPrefValue(prefs::kStabilitySystemUncleanShutdownCount); |
1712 else | 1667 else |
1713 NOTREACHED() << "Unexpected Chrome OS crash type " << crash_type; | 1668 NOTREACHED() << "Unexpected Chrome OS crash type " << crash_type; |
1714 // Wake up metrics logs sending if necessary now that new | 1669 // Wake up metrics logs sending if necessary now that new |
1715 // log data is available. | 1670 // log data is available. |
1716 HandleIdleSinceLastTransmission(false); | 1671 HandleIdleSinceLastTransmission(false); |
1717 } | 1672 } |
1718 #endif // OS_CHROMEOS | 1673 #endif // OS_CHROMEOS |
1719 | 1674 |
1720 void MetricsService::LogPluginLoadingError(const base::FilePath& plugin_path) { | 1675 void MetricsService::LogPluginLoadingError(const base::FilePath& plugin_path) { |
1721 content::WebPluginInfo plugin; | 1676 #if defined(ENABLE_PLUGINS) |
1722 bool success = | 1677 // TODO(asvitkine): Move this out of here. |
1723 content::PluginService::GetInstance()->GetPluginInfoByPath(plugin_path, | 1678 plugin_metrics_provider_->LogPluginLoadingError(plugin_path); |
1724 &plugin); | 1679 #endif |
1725 DCHECK(success); | |
1726 ChildProcessStats& stats = child_process_stats_buffer_[plugin.name]; | |
1727 // Initialize the type if this entry is new. | |
1728 if (stats.process_type == content::PROCESS_TYPE_UNKNOWN) { | |
1729 // The plug-in process might not actually of type PLUGIN (which means | |
1730 // NPAPI), but we only care that it is *a* plug-in process. | |
1731 stats.process_type = content::PROCESS_TYPE_PLUGIN; | |
1732 } else { | |
1733 DCHECK(IsPluginProcess(stats.process_type)); | |
1734 } | |
1735 stats.loading_errors++; | |
1736 } | |
1737 | |
1738 MetricsService::ChildProcessStats& MetricsService::GetChildProcessStats( | |
1739 const content::ChildProcessData& data) { | |
1740 const base::string16& child_name = data.name; | |
1741 if (!ContainsKey(child_process_stats_buffer_, child_name)) { | |
1742 child_process_stats_buffer_[child_name] = | |
1743 ChildProcessStats(data.process_type); | |
1744 } | |
1745 return child_process_stats_buffer_[child_name]; | |
1746 } | |
1747 | |
1748 void MetricsService::RecordPluginChanges(PrefService* pref) { | |
1749 ListPrefUpdate update(pref, prefs::kStabilityPluginStats); | |
1750 base::ListValue* plugins = update.Get(); | |
1751 DCHECK(plugins); | |
1752 | |
1753 for (base::ListValue::iterator value_iter = plugins->begin(); | |
1754 value_iter != plugins->end(); ++value_iter) { | |
1755 if (!(*value_iter)->IsType(base::Value::TYPE_DICTIONARY)) { | |
1756 NOTREACHED(); | |
1757 continue; | |
1758 } | |
1759 | |
1760 base::DictionaryValue* plugin_dict = | |
1761 static_cast<base::DictionaryValue*>(*value_iter); | |
1762 std::string plugin_name; | |
1763 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name); | |
1764 if (plugin_name.empty()) { | |
1765 NOTREACHED(); | |
1766 continue; | |
1767 } | |
1768 | |
1769 // TODO(viettrungluu): remove conversions | |
1770 base::string16 name16 = base::UTF8ToUTF16(plugin_name); | |
1771 if (child_process_stats_buffer_.find(name16) == | |
1772 child_process_stats_buffer_.end()) { | |
1773 continue; | |
1774 } | |
1775 | |
1776 ChildProcessStats stats = child_process_stats_buffer_[name16]; | |
1777 if (stats.process_launches) { | |
1778 int launches = 0; | |
1779 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches); | |
1780 launches += stats.process_launches; | |
1781 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, launches); | |
1782 } | |
1783 if (stats.process_crashes) { | |
1784 int crashes = 0; | |
1785 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes); | |
1786 crashes += stats.process_crashes; | |
1787 plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, crashes); | |
1788 } | |
1789 if (stats.instances) { | |
1790 int instances = 0; | |
1791 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances); | |
1792 instances += stats.instances; | |
1793 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, instances); | |
1794 } | |
1795 if (stats.loading_errors) { | |
1796 int loading_errors = 0; | |
1797 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors, | |
1798 &loading_errors); | |
1799 loading_errors += stats.loading_errors; | |
1800 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, | |
1801 loading_errors); | |
1802 } | |
1803 | |
1804 child_process_stats_buffer_.erase(name16); | |
1805 } | |
1806 | |
1807 // Now go through and add dictionaries for plugins that didn't already have | |
1808 // reports in Local State. | |
1809 for (std::map<base::string16, ChildProcessStats>::iterator cache_iter = | |
1810 child_process_stats_buffer_.begin(); | |
1811 cache_iter != child_process_stats_buffer_.end(); ++cache_iter) { | |
1812 ChildProcessStats stats = cache_iter->second; | |
1813 | |
1814 // Insert only plugins information into the plugins list. | |
1815 if (!IsPluginProcess(stats.process_type)) | |
1816 continue; | |
1817 | |
1818 // TODO(viettrungluu): remove conversion | |
1819 std::string plugin_name = base::UTF16ToUTF8(cache_iter->first); | |
1820 | |
1821 base::DictionaryValue* plugin_dict = new base::DictionaryValue; | |
1822 | |
1823 plugin_dict->SetString(prefs::kStabilityPluginName, plugin_name); | |
1824 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, | |
1825 stats.process_launches); | |
1826 plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, | |
1827 stats.process_crashes); | |
1828 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, | |
1829 stats.instances); | |
1830 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, | |
1831 stats.loading_errors); | |
1832 plugins->Append(plugin_dict); | |
1833 } | |
1834 child_process_stats_buffer_.clear(); | |
1835 } | 1680 } |
1836 | 1681 |
1837 bool MetricsService::ShouldLogEvents() { | 1682 bool MetricsService::ShouldLogEvents() { |
1838 // We simply don't log events to UMA if there is a single incognito | 1683 // We simply don't log events to UMA if there is a single incognito |
1839 // session visible. The problem is that we always notify using the orginal | 1684 // session visible. The problem is that we always notify using the orginal |
1840 // profile in order to simplify notification processing. | 1685 // profile in order to simplify notification processing. |
1841 return !chrome::IsOffTheRecordSessionActive(); | 1686 return !chrome::IsOffTheRecordSessionActive(); |
1842 } | 1687 } |
1843 | 1688 |
1844 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { | 1689 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { |
1845 DCHECK(IsSingleThreaded()); | 1690 DCHECK(IsSingleThreaded()); |
1846 | 1691 |
1847 PrefService* pref = g_browser_process->local_state(); | 1692 PrefService* pref = g_browser_process->local_state(); |
1848 DCHECK(pref); | 1693 DCHECK(pref); |
1849 | 1694 |
1850 pref->SetBoolean(path, value); | 1695 pref->SetBoolean(path, value); |
1851 RecordCurrentState(pref); | 1696 RecordCurrentState(pref); |
1852 } | 1697 } |
1853 | 1698 |
1854 void MetricsService::RecordCurrentState(PrefService* pref) { | 1699 void MetricsService::RecordCurrentState(PrefService* pref) { |
1855 pref->SetInt64(prefs::kStabilityLastTimestampSec, Time::Now().ToTimeT()); | 1700 pref->SetInt64(prefs::kStabilityLastTimestampSec, Time::Now().ToTimeT()); |
1856 | 1701 |
1857 RecordPluginChanges(pref); | 1702 #if defined(ENABLE_PLUGINS) |
1703 plugin_metrics_provider_->RecordPluginChanges(); | |
1704 #endif | |
1858 } | 1705 } |
1859 | 1706 |
1860 // static | 1707 // static |
1861 bool MetricsService::IsPluginProcess(int process_type) { | 1708 bool MetricsService::IsPluginProcess(int process_type) { |
1862 return (process_type == content::PROCESS_TYPE_PLUGIN || | 1709 return (process_type == content::PROCESS_TYPE_PLUGIN || |
1863 process_type == content::PROCESS_TYPE_PPAPI_PLUGIN || | 1710 process_type == content::PROCESS_TYPE_PPAPI_PLUGIN || |
1864 process_type == content::PROCESS_TYPE_PPAPI_BROKER); | 1711 process_type == content::PROCESS_TYPE_PPAPI_BROKER); |
1865 } | 1712 } |
1866 | 1713 |
1867 // static | 1714 // static |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1904 if (metrics_service) | 1751 if (metrics_service) |
1905 metrics_service->AddObserver(observer); | 1752 metrics_service->AddObserver(observer); |
1906 } | 1753 } |
1907 | 1754 |
1908 void MetricsServiceHelper::RemoveMetricsServiceObserver( | 1755 void MetricsServiceHelper::RemoveMetricsServiceObserver( |
1909 MetricsServiceObserver* observer) { | 1756 MetricsServiceObserver* observer) { |
1910 MetricsService* metrics_service = g_browser_process->metrics_service(); | 1757 MetricsService* metrics_service = g_browser_process->metrics_service(); |
1911 if (metrics_service) | 1758 if (metrics_service) |
1912 metrics_service->RemoveObserver(observer); | 1759 metrics_service->RemoveObserver(observer); |
1913 } | 1760 } |
OLD | NEW |