Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: chrome/browser/metrics/metrics_service.cc

Issue 296483004: Introduce a MetricsDataProvider interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 1161
1162 // Put incremental data (histogram deltas, and realtime stats deltas) at the 1162 // Put incremental data (histogram deltas, and realtime stats deltas) at the
1163 // end of all log transmissions (initial log handles this separately). 1163 // end of all log transmissions (initial log handles this separately).
1164 // RecordIncrementalStabilityElements only exists on the derived 1164 // RecordIncrementalStabilityElements only exists on the derived
1165 // MetricsLog class. 1165 // MetricsLog class.
1166 MetricsLog* current_log = 1166 MetricsLog* current_log =
1167 static_cast<MetricsLog*>(log_manager_.current_log()); 1167 static_cast<MetricsLog*>(log_manager_.current_log());
1168 DCHECK(current_log); 1168 DCHECK(current_log);
1169 std::vector<chrome_variations::ActiveGroupId> synthetic_trials; 1169 std::vector<chrome_variations::ActiveGroupId> synthetic_trials;
1170 GetCurrentSyntheticFieldTrials(&synthetic_trials); 1170 GetCurrentSyntheticFieldTrials(&synthetic_trials);
1171 current_log->RecordEnvironment(plugins_, google_update_metrics_, 1171 current_log->RecordEnvironment(data_providers_.get(), plugins_,
1172 synthetic_trials); 1172 google_update_metrics_, synthetic_trials);
1173 PrefService* pref = g_browser_process->local_state(); 1173 PrefService* pref = g_browser_process->local_state();
1174 base::TimeDelta incremental_uptime; 1174 base::TimeDelta incremental_uptime;
1175 base::TimeDelta uptime; 1175 base::TimeDelta uptime;
1176 GetUptimes(pref, &incremental_uptime, &uptime); 1176 GetUptimes(pref, &incremental_uptime, &uptime);
1177 current_log->RecordStabilityMetrics(incremental_uptime, uptime); 1177 current_log->RecordStabilityMetrics(data_providers_.get(), incremental_uptime,
1178 uptime);
1178 1179
1179 RecordCurrentHistograms(); 1180 RecordCurrentHistograms();
1181 current_log->RecordGeneralMetrics(data_providers_.get());
1180 1182
1181 log_manager_.FinishCurrentLog(); 1183 log_manager_.FinishCurrentLog();
1182 } 1184 }
1183 1185
1184 void MetricsService::PushPendingLogsToPersistentStorage() { 1186 void MetricsService::PushPendingLogsToPersistentStorage() {
1185 if (state_ < SENDING_INITIAL_STABILITY_LOG) 1187 if (state_ < SENDING_INITIAL_STABILITY_LOG)
1186 return; // We didn't and still don't have time to get plugin list etc. 1188 return; // We didn't and still don't have time to get plugin list etc.
1187 1189
1188 if (log_manager_.has_staged_log()) { 1190 if (log_manager_.has_staged_log()) {
1189 // We may race here, and send second copy of the log later. 1191 // We may race here, and send second copy of the log later.
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 1423
1422 scoped_ptr<MetricsLog> initial_stability_log( 1424 scoped_ptr<MetricsLog> initial_stability_log(
1423 new MetricsLog(state_manager_->client_id(), session_id_, 1425 new MetricsLog(state_manager_->client_id(), session_id_,
1424 MetricsLog::INITIAL_STABILITY_LOG)); 1426 MetricsLog::INITIAL_STABILITY_LOG));
1425 1427
1426 // Do not call NotifyOnDidCreateMetricsLog here because the stability 1428 // Do not call NotifyOnDidCreateMetricsLog here because the stability
1427 // log describes stats from the _previous_ session. 1429 // log describes stats from the _previous_ session.
1428 1430
1429 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) 1431 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs())
1430 return; 1432 return;
1431 initial_stability_log->RecordStabilityMetrics(base::TimeDelta(), 1433
1432 base::TimeDelta());
1433 log_manager_.LoadPersistedUnsentLogs(); 1434 log_manager_.LoadPersistedUnsentLogs();
1434 1435
1435 log_manager_.PauseCurrentLog(); 1436 log_manager_.PauseCurrentLog();
1436 log_manager_.BeginLoggingWithLog(initial_stability_log.release()); 1437 log_manager_.BeginLoggingWithLog(initial_stability_log.release());
1438
1439 // Note: Some stability providers may record stability stats via histograms,
1440 // so this call has to be after BeginLoggingWithLog().
1441 MetricsLog* current_log =
1442 static_cast<MetricsLog*>(log_manager_.current_log());
1443 current_log->RecordStabilityMetrics(data_providers_.get(), base::TimeDelta(),
1444 base::TimeDelta());
1445
1437 #if defined(OS_ANDROID) 1446 #if defined(OS_ANDROID)
1438 ConvertAndroidStabilityPrefsToHistograms(pref); 1447 ConvertAndroidStabilityPrefsToHistograms(pref);
1439 RecordCurrentStabilityHistograms(); 1448 RecordCurrentStabilityHistograms();
1440 #endif // defined(OS_ANDROID) 1449 #endif // defined(OS_ANDROID)
1450
1451 // Note: RecordGeneralMetrics() intentionally not called since this log is for
1452 // stability stats from a previous session only.
1453
1441 log_manager_.FinishCurrentLog(); 1454 log_manager_.FinishCurrentLog();
1442 log_manager_.ResumePausedLog(); 1455 log_manager_.ResumePausedLog();
1443 1456
1444 // Store unsent logs, including the stability log that was just saved, so 1457 // Store unsent logs, including the stability log that was just saved, so
1445 // that they're not lost in case of a crash before upload time. 1458 // that they're not lost in case of a crash before upload time.
1446 log_manager_.PersistUnsentLogs(); 1459 log_manager_.PersistUnsentLogs();
1447 1460
1448 has_initial_stability_log_ = true; 1461 has_initial_stability_log_ = true;
1449 } 1462 }
1450 1463
1451 void MetricsService::PrepareInitialMetricsLog() { 1464 void MetricsService::PrepareInitialMetricsLog() {
1452 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG); 1465 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG);
1453 initial_metrics_log_->set_hardware_class(hardware_class_); 1466 initial_metrics_log_->set_hardware_class(hardware_class_);
1454 1467
1455 std::vector<chrome_variations::ActiveGroupId> synthetic_trials; 1468 std::vector<chrome_variations::ActiveGroupId> synthetic_trials;
1456 GetCurrentSyntheticFieldTrials(&synthetic_trials); 1469 GetCurrentSyntheticFieldTrials(&synthetic_trials);
1457 initial_metrics_log_->RecordEnvironment(plugins_, google_update_metrics_, 1470 initial_metrics_log_->RecordEnvironment(data_providers_.get(), plugins_,
1471 google_update_metrics_,
1458 synthetic_trials); 1472 synthetic_trials);
1459 PrefService* pref = g_browser_process->local_state(); 1473 PrefService* pref = g_browser_process->local_state();
1460 base::TimeDelta incremental_uptime; 1474 base::TimeDelta incremental_uptime;
1461 base::TimeDelta uptime; 1475 base::TimeDelta uptime;
1462 GetUptimes(pref, &incremental_uptime, &uptime); 1476 GetUptimes(pref, &incremental_uptime, &uptime);
1463 initial_metrics_log_->RecordStabilityMetrics(incremental_uptime, uptime);
1464 1477
1465 // Histograms only get written to the current log, so make the new log current 1478 // Histograms only get written to the current log, so make the new log current
1466 // before writing them. 1479 // before writing them.
1467 log_manager_.PauseCurrentLog(); 1480 log_manager_.PauseCurrentLog();
1468 log_manager_.BeginLoggingWithLog(initial_metrics_log_.release()); 1481 log_manager_.BeginLoggingWithLog(initial_metrics_log_.release());
1482
1483 // Note: Some stability providers may record stability stats via histograms,
1484 // so this call has to be after BeginLoggingWithLog().
1485 MetricsLog* current_log =
1486 static_cast<MetricsLog*>(log_manager_.current_log());
1487 current_log->RecordStabilityMetrics(data_providers_.get(), base::TimeDelta(),
1488 base::TimeDelta());
1489
1469 #if defined(OS_ANDROID) 1490 #if defined(OS_ANDROID)
1470 ConvertAndroidStabilityPrefsToHistograms(pref); 1491 ConvertAndroidStabilityPrefsToHistograms(pref);
1471 #endif // defined(OS_ANDROID) 1492 #endif // defined(OS_ANDROID)
1472 RecordCurrentHistograms(); 1493 RecordCurrentHistograms();
1494
1495 current_log->RecordGeneralMetrics(data_providers_.get());
1496
1473 log_manager_.FinishCurrentLog(); 1497 log_manager_.FinishCurrentLog();
1474 log_manager_.ResumePausedLog(); 1498 log_manager_.ResumePausedLog();
1475 1499
1476 DCHECK(!log_manager_.has_staged_log()); 1500 DCHECK(!log_manager_.has_staged_log());
1477 log_manager_.StageNextLogForUpload(); 1501 log_manager_.StageNextLogForUpload();
1478 } 1502 }
1479 1503
1480 void MetricsService::SendStagedLog() { 1504 void MetricsService::SendStagedLog() {
1481 DCHECK(log_manager_.has_staged_log()); 1505 DCHECK(log_manager_.has_staged_log());
1482 1506
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1715 } 1739 }
1716 return; 1740 return;
1717 } 1741 }
1718 } 1742 }
1719 1743
1720 SyntheticTrialGroup trial_group = trial; 1744 SyntheticTrialGroup trial_group = trial;
1721 trial_group.start_time = base::TimeTicks::Now(); 1745 trial_group.start_time = base::TimeTicks::Now();
1722 synthetic_trial_groups_.push_back(trial_group); 1746 synthetic_trial_groups_.push_back(trial_group);
1723 } 1747 }
1724 1748
1749 void MetricsService::RegisterDataProvider(
1750 scoped_ptr<metrics::MetricsDataProvider> provider) {
1751 DCHECK_EQ(INITIALIZED, state_);
1752 data_providers_.push_back(provider.release());
1753 }
1754
1725 void MetricsService::CheckForClonedInstall() { 1755 void MetricsService::CheckForClonedInstall() {
1726 state_manager_->CheckForClonedInstall(); 1756 state_manager_->CheckForClonedInstall();
1727 } 1757 }
1728 1758
1729 void MetricsService::GetCurrentSyntheticFieldTrials( 1759 void MetricsService::GetCurrentSyntheticFieldTrials(
1730 std::vector<chrome_variations::ActiveGroupId>* synthetic_trials) { 1760 std::vector<chrome_variations::ActiveGroupId>* synthetic_trials) {
1731 DCHECK(synthetic_trials); 1761 DCHECK(synthetic_trials);
1732 synthetic_trials->clear(); 1762 synthetic_trials->clear();
1733 const MetricsLog* current_log = 1763 const MetricsLog* current_log =
1734 static_cast<const MetricsLog*>(log_manager_.current_log()); 1764 static_cast<const MetricsLog*>(log_manager_.current_log());
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1962 if (metrics_service) 1992 if (metrics_service)
1963 metrics_service->AddObserver(observer); 1993 metrics_service->AddObserver(observer);
1964 } 1994 }
1965 1995
1966 void MetricsServiceHelper::RemoveMetricsServiceObserver( 1996 void MetricsServiceHelper::RemoveMetricsServiceObserver(
1967 MetricsServiceObserver* observer) { 1997 MetricsServiceObserver* observer) {
1968 MetricsService* metrics_service = g_browser_process->metrics_service(); 1998 MetricsService* metrics_service = g_browser_process->metrics_service();
1969 if (metrics_service) 1999 if (metrics_service)
1970 metrics_service->RemoveObserver(observer); 2000 metrics_service->RemoveObserver(observer);
1971 } 2001 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698