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

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_, 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_, incremental_uptime,
1178 uptime);
1178 1179
1179 RecordCurrentHistograms(); 1180 RecordCurrentHistograms();
1181 current_log->RecordGeneralMetrics(data_providers_);
Ilya Sherman 2014/05/19 14:45:00 Does it make sense to fold this into RecordEnviron
Alexei Svitkine (slow) 2014/05/19 15:23:02 I don't think it does. RecordEnvironment() records
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();
1437 MetricsLog* initial_stability_log_ptr = initial_stability_log.get();
Ilya Sherman 2014/05/19 14:45:00 Optiona nit: Perhaps it would be cleaner to access
Alexei Svitkine (slow) 2014/05/19 15:23:02 Fair enough, the static cast is why I did this and
1436 log_manager_.BeginLoggingWithLog(initial_stability_log.release()); 1438 log_manager_.BeginLoggingWithLog(initial_stability_log.release());
1439
1440 // Note: Some stability providers may record stability stats via histograms,
1441 // so this call has to be after BeginLoggingWithLog().
1442 initial_stability_log_ptr->RecordStabilityMetrics(data_providers_,
1443 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)
1441 log_manager_.FinishCurrentLog(); 1450 log_manager_.FinishCurrentLog();
1442 log_manager_.ResumePausedLog(); 1451 log_manager_.ResumePausedLog();
1443 1452
1444 // Store unsent logs, including the stability log that was just saved, so 1453 // 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. 1454 // that they're not lost in case of a crash before upload time.
1446 log_manager_.PersistUnsentLogs(); 1455 log_manager_.PersistUnsentLogs();
1447 1456
1448 has_initial_stability_log_ = true; 1457 has_initial_stability_log_ = true;
1449 } 1458 }
1450 1459
1451 void MetricsService::PrepareInitialMetricsLog() { 1460 void MetricsService::PrepareInitialMetricsLog() {
1452 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG); 1461 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG);
1453 initial_metrics_log_->set_hardware_class(hardware_class_); 1462 initial_metrics_log_->set_hardware_class(hardware_class_);
1454 1463
1455 std::vector<chrome_variations::ActiveGroupId> synthetic_trials; 1464 std::vector<chrome_variations::ActiveGroupId> synthetic_trials;
1456 GetCurrentSyntheticFieldTrials(&synthetic_trials); 1465 GetCurrentSyntheticFieldTrials(&synthetic_trials);
1457 initial_metrics_log_->RecordEnvironment(plugins_, google_update_metrics_, 1466 initial_metrics_log_->RecordEnvironment(data_providers_, plugins_,
1467 google_update_metrics_,
1458 synthetic_trials); 1468 synthetic_trials);
1459 PrefService* pref = g_browser_process->local_state(); 1469 PrefService* pref = g_browser_process->local_state();
1460 base::TimeDelta incremental_uptime; 1470 base::TimeDelta incremental_uptime;
1461 base::TimeDelta uptime; 1471 base::TimeDelta uptime;
1462 GetUptimes(pref, &incremental_uptime, &uptime); 1472 GetUptimes(pref, &incremental_uptime, &uptime);
1463 initial_metrics_log_->RecordStabilityMetrics(incremental_uptime, uptime); 1473 initial_metrics_log_->RecordStabilityMetrics(data_providers_,
1474 incremental_uptime, uptime);
Ilya Sherman 2014/05/19 14:45:00 Are you intentionally not recording general metric
Alexei Svitkine (slow) 2014/05/19 15:23:02 Oops, it was indeed not intentional. There was als
1464 1475
1465 // Histograms only get written to the current log, so make the new log current 1476 // Histograms only get written to the current log, so make the new log current
1466 // before writing them. 1477 // before writing them.
1467 log_manager_.PauseCurrentLog(); 1478 log_manager_.PauseCurrentLog();
1468 log_manager_.BeginLoggingWithLog(initial_metrics_log_.release()); 1479 log_manager_.BeginLoggingWithLog(initial_metrics_log_.release());
1469 #if defined(OS_ANDROID) 1480 #if defined(OS_ANDROID)
1470 ConvertAndroidStabilityPrefsToHistograms(pref); 1481 ConvertAndroidStabilityPrefsToHistograms(pref);
1471 #endif // defined(OS_ANDROID) 1482 #endif // defined(OS_ANDROID)
1472 RecordCurrentHistograms(); 1483 RecordCurrentHistograms();
1473 log_manager_.FinishCurrentLog(); 1484 log_manager_.FinishCurrentLog();
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1715 } 1726 }
1716 return; 1727 return;
1717 } 1728 }
1718 } 1729 }
1719 1730
1720 SyntheticTrialGroup trial_group = trial; 1731 SyntheticTrialGroup trial_group = trial;
1721 trial_group.start_time = base::TimeTicks::Now(); 1732 trial_group.start_time = base::TimeTicks::Now();
1722 synthetic_trial_groups_.push_back(trial_group); 1733 synthetic_trial_groups_.push_back(trial_group);
1723 } 1734 }
1724 1735
1736 void MetricsService::RegisterDataProvider(
1737 scoped_ptr<metrics::MetricsDataProvider> provider) {
1738 DCHECK_EQ(INITIALIZED, state_);
1739
Ilya Sherman 2014/05/19 14:45:00 Optional nit: I'd omit this blank line.
Alexei Svitkine (slow) 2014/05/19 15:23:02 Done.
1740 data_providers_.push_back(provider.release());
1741 }
1742
1725 void MetricsService::CheckForClonedInstall() { 1743 void MetricsService::CheckForClonedInstall() {
1726 state_manager_->CheckForClonedInstall(); 1744 state_manager_->CheckForClonedInstall();
1727 } 1745 }
1728 1746
1729 void MetricsService::GetCurrentSyntheticFieldTrials( 1747 void MetricsService::GetCurrentSyntheticFieldTrials(
1730 std::vector<chrome_variations::ActiveGroupId>* synthetic_trials) { 1748 std::vector<chrome_variations::ActiveGroupId>* synthetic_trials) {
1731 DCHECK(synthetic_trials); 1749 DCHECK(synthetic_trials);
1732 synthetic_trials->clear(); 1750 synthetic_trials->clear();
1733 const MetricsLog* current_log = 1751 const MetricsLog* current_log =
1734 static_cast<const MetricsLog*>(log_manager_.current_log()); 1752 static_cast<const MetricsLog*>(log_manager_.current_log());
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1962 if (metrics_service) 1980 if (metrics_service)
1963 metrics_service->AddObserver(observer); 1981 metrics_service->AddObserver(observer);
1964 } 1982 }
1965 1983
1966 void MetricsServiceHelper::RemoveMetricsServiceObserver( 1984 void MetricsServiceHelper::RemoveMetricsServiceObserver(
1967 MetricsServiceObserver* observer) { 1985 MetricsServiceObserver* observer) {
1968 MetricsService* metrics_service = g_browser_process->metrics_service(); 1986 MetricsService* metrics_service = g_browser_process->metrics_service();
1969 if (metrics_service) 1987 if (metrics_service)
1970 metrics_service->RemoveObserver(observer); 1988 metrics_service->RemoveObserver(observer);
1971 } 1989 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698