Chromium Code Reviews| 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 #include "base/strings/utf_string_conversions.h" | 178 #include "base/strings/utf_string_conversions.h" |
| 179 #include "base/threading/platform_thread.h" | 179 #include "base/threading/platform_thread.h" |
| 180 #include "base/threading/thread.h" | 180 #include "base/threading/thread.h" |
| 181 #include "base/threading/thread_restrictions.h" | 181 #include "base/threading/thread_restrictions.h" |
| 182 #include "base/tracked_objects.h" | 182 #include "base/tracked_objects.h" |
| 183 #include "base/values.h" | 183 #include "base/values.h" |
| 184 #include "chrome/browser/browser_process.h" | 184 #include "chrome/browser/browser_process.h" |
| 185 #include "chrome/browser/chrome_notification_types.h" | 185 #include "chrome/browser/chrome_notification_types.h" |
| 186 #include "chrome/browser/io_thread.h" | 186 #include "chrome/browser/io_thread.h" |
| 187 #include "chrome/browser/memory_details.h" | 187 #include "chrome/browser/memory_details.h" |
| 188 #include "chrome/browser/metrics/android_metrics_provider_android.h" | |
|
Ilya Sherman
2014/05/21 09:15:28
nit: Only for Android builds?
Alexei Svitkine (slow)
2014/05/21 09:48:47
Done.
| |
| 188 #include "chrome/browser/metrics/compression_utils.h" | 189 #include "chrome/browser/metrics/compression_utils.h" |
| 189 #include "chrome/browser/metrics/metrics_log.h" | 190 #include "chrome/browser/metrics/metrics_log.h" |
| 190 #include "chrome/browser/metrics/metrics_state_manager.h" | 191 #include "chrome/browser/metrics/metrics_state_manager.h" |
| 191 #include "chrome/browser/metrics/time_ticks_experiment_win.h" | 192 #include "chrome/browser/metrics/time_ticks_experiment_win.h" |
| 192 #include "chrome/browser/metrics/tracking_synchronizer.h" | 193 #include "chrome/browser/metrics/tracking_synchronizer.h" |
| 193 #include "chrome/browser/net/http_pipelining_compatibility_client.h" | 194 #include "chrome/browser/net/http_pipelining_compatibility_client.h" |
| 194 #include "chrome/browser/net/network_stats.h" | 195 #include "chrome/browser/net/network_stats.h" |
| 195 #include "chrome/browser/omnibox/omnibox_log.h" | 196 #include "chrome/browser/omnibox/omnibox_log.h" |
| 196 #include "chrome/browser/ui/browser_otr_state.h" | 197 #include "chrome/browser/ui/browser_otr_state.h" |
| 197 #include "chrome/common/chrome_constants.h" | 198 #include "chrome/common/chrome_constants.h" |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 registry->RegisterListPref(metrics::prefs::kMetricsOngoingLogs); | 448 registry->RegisterListPref(metrics::prefs::kMetricsOngoingLogs); |
| 448 | 449 |
| 449 registry->RegisterInt64Pref(prefs::kInstallDate, 0); | 450 registry->RegisterInt64Pref(prefs::kInstallDate, 0); |
| 450 registry->RegisterInt64Pref(prefs::kUninstallMetricsPageLoadCount, 0); | 451 registry->RegisterInt64Pref(prefs::kUninstallMetricsPageLoadCount, 0); |
| 451 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0); | 452 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0); |
| 452 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0); | 453 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0); |
| 453 registry->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0); | 454 registry->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0); |
| 454 registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0); | 455 registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0); |
| 455 | 456 |
| 456 #if defined(OS_ANDROID) | 457 #if defined(OS_ANDROID) |
| 457 RegisterPrefsAndroid(registry); | 458 // TODO(asvitkine): Move this out of here. |
| 459 AndroidMetricsProvider::RegisterPrefs(registry); | |
| 458 #endif // defined(OS_ANDROID) | 460 #endif // defined(OS_ANDROID) |
| 459 } | 461 } |
| 460 | 462 |
| 461 MetricsService::MetricsService(metrics::MetricsStateManager* state_manager) | 463 MetricsService::MetricsService(metrics::MetricsStateManager* state_manager) |
| 462 : MetricsServiceBase(g_browser_process->local_state(), | 464 : MetricsServiceBase(g_browser_process->local_state(), |
| 463 kUploadLogAvoidRetransmitSize), | 465 kUploadLogAvoidRetransmitSize), |
| 464 state_manager_(state_manager), | 466 state_manager_(state_manager), |
| 465 recording_active_(false), | 467 recording_active_(false), |
| 466 reporting_active_(false), | 468 reporting_active_(false), |
| 467 test_mode_active_(false), | 469 test_mode_active_(false), |
| 468 state_(INITIALIZED), | 470 state_(INITIALIZED), |
| 469 has_initial_stability_log_(false), | 471 has_initial_stability_log_(false), |
| 470 idle_since_last_transmission_(false), | 472 idle_since_last_transmission_(false), |
| 471 session_id_(-1), | 473 session_id_(-1), |
| 472 next_window_id_(0), | 474 next_window_id_(0), |
| 473 self_ptr_factory_(this), | 475 self_ptr_factory_(this), |
| 474 state_saver_factory_(this), | 476 state_saver_factory_(this), |
| 475 waiting_for_asynchronous_reporting_step_(false), | 477 waiting_for_asynchronous_reporting_step_(false), |
| 476 num_async_histogram_fetches_in_progress_(0) { | 478 num_async_histogram_fetches_in_progress_(0) { |
| 477 DCHECK(IsSingleThreaded()); | 479 DCHECK(IsSingleThreaded()); |
| 478 DCHECK(state_manager_); | 480 DCHECK(state_manager_); |
| 479 | 481 |
| 482 #if defined(OS_ANDROID) | |
| 483 // TODO(asvitkine): Move this out of MetricsService. | |
| 484 RegisterMetricsProvider( | |
| 485 scoped_ptr<metrics::MetricsProvider>(new AndroidMetricsProvider( | |
| 486 g_browser_process->local_state()))); | |
| 487 #endif // defined(OS_ANDROID) | |
|
Ilya Sherman
2014/05/21 09:15:28
Hmm, why did you move this out of InitializeMetric
Alexei Svitkine (slow)
2014/05/21 09:48:47
Yes, either location is fine - as long as this hap
| |
| 488 | |
| 480 BrowserChildProcessObserver::Add(this); | 489 BrowserChildProcessObserver::Add(this); |
| 481 } | 490 } |
| 482 | 491 |
| 483 MetricsService::~MetricsService() { | 492 MetricsService::~MetricsService() { |
| 484 DisableRecording(); | 493 DisableRecording(); |
| 485 | 494 |
| 486 BrowserChildProcessObserver::Remove(this); | 495 BrowserChildProcessObserver::Remove(this); |
| 487 } | 496 } |
| 488 | 497 |
| 489 void MetricsService::InitializeMetricsRecordingState() { | 498 void MetricsService::InitializeMetricsRecordingState() { |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 854 | 863 |
| 855 PrefService* pref = g_browser_process->local_state(); | 864 PrefService* pref = g_browser_process->local_state(); |
| 856 DCHECK(pref); | 865 DCHECK(pref); |
| 857 | 866 |
| 858 pref->SetString(prefs::kStabilityStatsVersion, | 867 pref->SetString(prefs::kStabilityStatsVersion, |
| 859 MetricsLog::GetVersionString()); | 868 MetricsLog::GetVersionString()); |
| 860 pref->SetInt64(prefs::kStabilityStatsBuildTime, MetricsLog::GetBuildTime()); | 869 pref->SetInt64(prefs::kStabilityStatsBuildTime, MetricsLog::GetBuildTime()); |
| 861 | 870 |
| 862 session_id_ = pref->GetInteger(prefs::kMetricsSessionID); | 871 session_id_ = pref->GetInteger(prefs::kMetricsSessionID); |
| 863 | 872 |
| 864 #if defined(OS_ANDROID) | |
| 865 LogAndroidStabilityToPrefs(pref); | |
| 866 #endif // defined(OS_ANDROID) | |
| 867 | |
| 868 if (!pref->GetBoolean(prefs::kStabilityExitedCleanly)) { | 873 if (!pref->GetBoolean(prefs::kStabilityExitedCleanly)) { |
| 869 IncrementPrefValue(prefs::kStabilityCrashCount); | 874 IncrementPrefValue(prefs::kStabilityCrashCount); |
| 870 // Reset flag, and wait until we call LogNeedForCleanShutdown() before | 875 // Reset flag, and wait until we call LogNeedForCleanShutdown() before |
| 871 // monitoring. | 876 // monitoring. |
| 872 pref->SetBoolean(prefs::kStabilityExitedCleanly, true); | 877 pref->SetBoolean(prefs::kStabilityExitedCleanly, true); |
| 873 | 878 |
| 874 // TODO(rtenneti): On windows, consider saving/getting execution_phase from | 879 // TODO(rtenneti): On windows, consider saving/getting execution_phase from |
| 875 // the registry. | 880 // the registry. |
| 876 int execution_phase = pref->GetInteger(prefs::kStabilityExecutionPhase); | 881 int execution_phase = pref->GetInteger(prefs::kStabilityExecutionPhase); |
| 877 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", | 882 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1441 | 1446 |
| 1442 log_manager_.PauseCurrentLog(); | 1447 log_manager_.PauseCurrentLog(); |
| 1443 log_manager_.BeginLoggingWithLog(initial_stability_log.release()); | 1448 log_manager_.BeginLoggingWithLog(initial_stability_log.release()); |
| 1444 | 1449 |
| 1445 // Note: Some stability providers may record stability stats via histograms, | 1450 // Note: Some stability providers may record stability stats via histograms, |
| 1446 // so this call has to be after BeginLoggingWithLog(). | 1451 // so this call has to be after BeginLoggingWithLog(). |
| 1447 MetricsLog* current_log = | 1452 MetricsLog* current_log = |
| 1448 static_cast<MetricsLog*>(log_manager_.current_log()); | 1453 static_cast<MetricsLog*>(log_manager_.current_log()); |
| 1449 current_log->RecordStabilityMetrics(metrics_providers_.get(), | 1454 current_log->RecordStabilityMetrics(metrics_providers_.get(), |
| 1450 base::TimeDelta(), base::TimeDelta()); | 1455 base::TimeDelta(), base::TimeDelta()); |
| 1451 | |
| 1452 #if defined(OS_ANDROID) | |
| 1453 ConvertAndroidStabilityPrefsToHistograms(pref); | |
| 1454 RecordCurrentStabilityHistograms(); | 1456 RecordCurrentStabilityHistograms(); |
| 1455 #endif // defined(OS_ANDROID) | |
| 1456 | 1457 |
| 1457 // Note: RecordGeneralMetrics() intentionally not called since this log is for | 1458 // Note: RecordGeneralMetrics() intentionally not called since this log is for |
| 1458 // stability stats from a previous session only. | 1459 // stability stats from a previous session only. |
| 1459 | 1460 |
| 1460 log_manager_.FinishCurrentLog(); | 1461 log_manager_.FinishCurrentLog(); |
| 1461 log_manager_.ResumePausedLog(); | 1462 log_manager_.ResumePausedLog(); |
| 1462 | 1463 |
| 1463 // Store unsent logs, including the stability log that was just saved, so | 1464 // Store unsent logs, including the stability log that was just saved, so |
| 1464 // that they're not lost in case of a crash before upload time. | 1465 // that they're not lost in case of a crash before upload time. |
| 1465 log_manager_.PersistUnsentLogs(); | 1466 log_manager_.PersistUnsentLogs(); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1485 // before writing them. | 1486 // before writing them. |
| 1486 log_manager_.PauseCurrentLog(); | 1487 log_manager_.PauseCurrentLog(); |
| 1487 log_manager_.BeginLoggingWithLog(initial_metrics_log_.release()); | 1488 log_manager_.BeginLoggingWithLog(initial_metrics_log_.release()); |
| 1488 | 1489 |
| 1489 // Note: Some stability providers may record stability stats via histograms, | 1490 // Note: Some stability providers may record stability stats via histograms, |
| 1490 // so this call has to be after BeginLoggingWithLog(). | 1491 // so this call has to be after BeginLoggingWithLog(). |
| 1491 MetricsLog* current_log = | 1492 MetricsLog* current_log = |
| 1492 static_cast<MetricsLog*>(log_manager_.current_log()); | 1493 static_cast<MetricsLog*>(log_manager_.current_log()); |
| 1493 current_log->RecordStabilityMetrics(metrics_providers_.get(), | 1494 current_log->RecordStabilityMetrics(metrics_providers_.get(), |
| 1494 base::TimeDelta(), base::TimeDelta()); | 1495 base::TimeDelta(), base::TimeDelta()); |
| 1495 | |
| 1496 #if defined(OS_ANDROID) | |
| 1497 ConvertAndroidStabilityPrefsToHistograms(pref); | |
| 1498 #endif // defined(OS_ANDROID) | |
| 1499 RecordCurrentHistograms(); | 1496 RecordCurrentHistograms(); |
| 1500 | 1497 |
| 1501 current_log->RecordGeneralMetrics(metrics_providers_.get()); | 1498 current_log->RecordGeneralMetrics(metrics_providers_.get()); |
| 1502 | 1499 |
| 1503 log_manager_.FinishCurrentLog(); | 1500 log_manager_.FinishCurrentLog(); |
| 1504 log_manager_.ResumePausedLog(); | 1501 log_manager_.ResumePausedLog(); |
| 1505 | 1502 |
| 1506 DCHECK(!log_manager_.has_staged_log()); | 1503 DCHECK(!log_manager_.has_staged_log()); |
| 1507 log_manager_.StageNextLogForUpload(); | 1504 log_manager_.StageNextLogForUpload(); |
| 1508 } | 1505 } |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1992 if (metrics_service) | 1989 if (metrics_service) |
| 1993 metrics_service->AddObserver(observer); | 1990 metrics_service->AddObserver(observer); |
| 1994 } | 1991 } |
| 1995 | 1992 |
| 1996 void MetricsServiceHelper::RemoveMetricsServiceObserver( | 1993 void MetricsServiceHelper::RemoveMetricsServiceObserver( |
| 1997 MetricsServiceObserver* observer) { | 1994 MetricsServiceObserver* observer) { |
| 1998 MetricsService* metrics_service = g_browser_process->metrics_service(); | 1995 MetricsService* metrics_service = g_browser_process->metrics_service(); |
| 1999 if (metrics_service) | 1996 if (metrics_service) |
| 2000 metrics_service->RemoveObserver(observer); | 1997 metrics_service->RemoveObserver(observer); |
| 2001 } | 1998 } |
| OLD | NEW |