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

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 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 546
547 if (recording_active_) 547 if (recording_active_)
548 return; 548 return;
549 recording_active_ = true; 549 recording_active_ = true;
550 550
551 state_manager_->ForceClientIdCreation(); 551 state_manager_->ForceClientIdCreation();
552 crash_keys::SetClientID(state_manager_->client_id()); 552 crash_keys::SetClientID(state_manager_->client_id());
553 if (!log_manager_.current_log()) 553 if (!log_manager_.current_log())
554 OpenNewLog(); 554 OpenNewLog();
555 555
556 for (size_t i = 0; i < metrics_providers_.size(); ++i)
557 metrics_providers_[i]->OnRecordingEnabled();
558
556 SetUpNotifications(&registrar_, this); 559 SetUpNotifications(&registrar_, this);
557 base::RemoveActionCallback(action_callback_); 560 base::RemoveActionCallback(action_callback_);
558 action_callback_ = base::Bind(&MetricsService::OnUserAction, 561 action_callback_ = base::Bind(&MetricsService::OnUserAction,
559 base::Unretained(this)); 562 base::Unretained(this));
560 base::AddActionCallback(action_callback_); 563 base::AddActionCallback(action_callback_);
561 } 564 }
562 565
563 void MetricsService::DisableRecording() { 566 void MetricsService::DisableRecording() {
564 DCHECK(IsSingleThreaded()); 567 DCHECK(IsSingleThreaded());
565 568
566 if (!recording_active_) 569 if (!recording_active_)
567 return; 570 return;
568 recording_active_ = false; 571 recording_active_ = false;
569 572
570 base::RemoveActionCallback(action_callback_); 573 base::RemoveActionCallback(action_callback_);
571 registrar_.RemoveAll(); 574 registrar_.RemoveAll();
575
576 for (size_t i = 0; i < metrics_providers_.size(); ++i)
577 metrics_providers_[i]->OnRecordingDisabled();
578
572 PushPendingLogsToPersistentStorage(); 579 PushPendingLogsToPersistentStorage();
573 DCHECK(!log_manager_.has_staged_log()); 580 DCHECK(!log_manager_.has_staged_log());
574 } 581 }
575 582
576 bool MetricsService::recording_active() const { 583 bool MetricsService::recording_active() const {
577 DCHECK(IsSingleThreaded()); 584 DCHECK(IsSingleThreaded());
578 return recording_active_; 585 return recording_active_;
579 } 586 }
580 587
581 bool MetricsService::reporting_active() const { 588 bool MetricsService::reporting_active() const {
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 1167
1161 // Put incremental data (histogram deltas, and realtime stats deltas) at the 1168 // Put incremental data (histogram deltas, and realtime stats deltas) at the
1162 // end of all log transmissions (initial log handles this separately). 1169 // end of all log transmissions (initial log handles this separately).
1163 // RecordIncrementalStabilityElements only exists on the derived 1170 // RecordIncrementalStabilityElements only exists on the derived
1164 // MetricsLog class. 1171 // MetricsLog class.
1165 MetricsLog* current_log = 1172 MetricsLog* current_log =
1166 static_cast<MetricsLog*>(log_manager_.current_log()); 1173 static_cast<MetricsLog*>(log_manager_.current_log());
1167 DCHECK(current_log); 1174 DCHECK(current_log);
1168 std::vector<variations::ActiveGroupId> synthetic_trials; 1175 std::vector<variations::ActiveGroupId> synthetic_trials;
1169 GetCurrentSyntheticFieldTrials(&synthetic_trials); 1176 GetCurrentSyntheticFieldTrials(&synthetic_trials);
1170 current_log->RecordEnvironment(plugins_, google_update_metrics_, 1177 current_log->RecordEnvironment(metrics_providers_.get(), plugins_,
1171 synthetic_trials); 1178 google_update_metrics_, synthetic_trials);
1172 PrefService* pref = g_browser_process->local_state(); 1179 PrefService* pref = g_browser_process->local_state();
1173 base::TimeDelta incremental_uptime; 1180 base::TimeDelta incremental_uptime;
1174 base::TimeDelta uptime; 1181 base::TimeDelta uptime;
1175 GetUptimes(pref, &incremental_uptime, &uptime); 1182 GetUptimes(pref, &incremental_uptime, &uptime);
1176 current_log->RecordStabilityMetrics(incremental_uptime, uptime); 1183 current_log->RecordStabilityMetrics(metrics_providers_.get(),
1184 incremental_uptime, uptime);
1177 1185
1178 RecordCurrentHistograms(); 1186 RecordCurrentHistograms();
1187 current_log->RecordGeneralMetrics(metrics_providers_.get());
1179 1188
1180 log_manager_.FinishCurrentLog(); 1189 log_manager_.FinishCurrentLog();
1181 } 1190 }
1182 1191
1183 void MetricsService::PushPendingLogsToPersistentStorage() { 1192 void MetricsService::PushPendingLogsToPersistentStorage() {
1184 if (state_ < SENDING_INITIAL_STABILITY_LOG) 1193 if (state_ < SENDING_INITIAL_STABILITY_LOG)
1185 return; // We didn't and still don't have time to get plugin list etc. 1194 return; // We didn't and still don't have time to get plugin list etc.
1186 1195
1187 if (log_manager_.has_staged_log()) { 1196 if (log_manager_.has_staged_log()) {
1188 // We may race here, and send second copy of the log later. 1197 // We may race here, and send second copy of the log later.
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1420 1429
1421 scoped_ptr<MetricsLog> initial_stability_log( 1430 scoped_ptr<MetricsLog> initial_stability_log(
1422 new MetricsLog(state_manager_->client_id(), session_id_, 1431 new MetricsLog(state_manager_->client_id(), session_id_,
1423 MetricsLog::INITIAL_STABILITY_LOG)); 1432 MetricsLog::INITIAL_STABILITY_LOG));
1424 1433
1425 // Do not call NotifyOnDidCreateMetricsLog here because the stability 1434 // Do not call NotifyOnDidCreateMetricsLog here because the stability
1426 // log describes stats from the _previous_ session. 1435 // log describes stats from the _previous_ session.
1427 1436
1428 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) 1437 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs())
1429 return; 1438 return;
1430 initial_stability_log->RecordStabilityMetrics(base::TimeDelta(), 1439
1431 base::TimeDelta());
1432 log_manager_.LoadPersistedUnsentLogs(); 1440 log_manager_.LoadPersistedUnsentLogs();
1433 1441
1434 log_manager_.PauseCurrentLog(); 1442 log_manager_.PauseCurrentLog();
1435 log_manager_.BeginLoggingWithLog(initial_stability_log.release()); 1443 log_manager_.BeginLoggingWithLog(initial_stability_log.release());
1444
1445 // Note: Some stability providers may record stability stats via histograms,
1446 // so this call has to be after BeginLoggingWithLog().
1447 MetricsLog* current_log =
1448 static_cast<MetricsLog*>(log_manager_.current_log());
1449 current_log->RecordStabilityMetrics(metrics_providers_.get(),
1450 base::TimeDelta(), base::TimeDelta());
1451
1436 #if defined(OS_ANDROID) 1452 #if defined(OS_ANDROID)
1437 ConvertAndroidStabilityPrefsToHistograms(pref); 1453 ConvertAndroidStabilityPrefsToHistograms(pref);
1438 RecordCurrentStabilityHistograms(); 1454 RecordCurrentStabilityHistograms();
1439 #endif // defined(OS_ANDROID) 1455 #endif // defined(OS_ANDROID)
1456
1457 // Note: RecordGeneralMetrics() intentionally not called since this log is for
1458 // stability stats from a previous session only.
1459
1440 log_manager_.FinishCurrentLog(); 1460 log_manager_.FinishCurrentLog();
1441 log_manager_.ResumePausedLog(); 1461 log_manager_.ResumePausedLog();
1442 1462
1443 // Store unsent logs, including the stability log that was just saved, so 1463 // Store unsent logs, including the stability log that was just saved, so
1444 // that they're not lost in case of a crash before upload time. 1464 // that they're not lost in case of a crash before upload time.
1445 log_manager_.PersistUnsentLogs(); 1465 log_manager_.PersistUnsentLogs();
1446 1466
1447 has_initial_stability_log_ = true; 1467 has_initial_stability_log_ = true;
1448 } 1468 }
1449 1469
1450 void MetricsService::PrepareInitialMetricsLog() { 1470 void MetricsService::PrepareInitialMetricsLog() {
1451 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG); 1471 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG);
1452 initial_metrics_log_->set_hardware_class(hardware_class_); 1472 initial_metrics_log_->set_hardware_class(hardware_class_);
1453 1473
1454 std::vector<variations::ActiveGroupId> synthetic_trials; 1474 std::vector<variations::ActiveGroupId> synthetic_trials;
1455 GetCurrentSyntheticFieldTrials(&synthetic_trials); 1475 GetCurrentSyntheticFieldTrials(&synthetic_trials);
1456 initial_metrics_log_->RecordEnvironment(plugins_, google_update_metrics_, 1476 initial_metrics_log_->RecordEnvironment(metrics_providers_.get(), plugins_,
1477 google_update_metrics_,
1457 synthetic_trials); 1478 synthetic_trials);
1458 PrefService* pref = g_browser_process->local_state(); 1479 PrefService* pref = g_browser_process->local_state();
1459 base::TimeDelta incremental_uptime; 1480 base::TimeDelta incremental_uptime;
1460 base::TimeDelta uptime; 1481 base::TimeDelta uptime;
1461 GetUptimes(pref, &incremental_uptime, &uptime); 1482 GetUptimes(pref, &incremental_uptime, &uptime);
1462 initial_metrics_log_->RecordStabilityMetrics(incremental_uptime, uptime);
1463 1483
1464 // Histograms only get written to the current log, so make the new log current 1484 // Histograms only get written to the current log, so make the new log current
1465 // before writing them. 1485 // before writing them.
1466 log_manager_.PauseCurrentLog(); 1486 log_manager_.PauseCurrentLog();
1467 log_manager_.BeginLoggingWithLog(initial_metrics_log_.release()); 1487 log_manager_.BeginLoggingWithLog(initial_metrics_log_.release());
1488
1489 // Note: Some stability providers may record stability stats via histograms,
1490 // so this call has to be after BeginLoggingWithLog().
1491 MetricsLog* current_log =
1492 static_cast<MetricsLog*>(log_manager_.current_log());
1493 current_log->RecordStabilityMetrics(metrics_providers_.get(),
1494 base::TimeDelta(), base::TimeDelta());
1495
1468 #if defined(OS_ANDROID) 1496 #if defined(OS_ANDROID)
1469 ConvertAndroidStabilityPrefsToHistograms(pref); 1497 ConvertAndroidStabilityPrefsToHistograms(pref);
1470 #endif // defined(OS_ANDROID) 1498 #endif // defined(OS_ANDROID)
1471 RecordCurrentHistograms(); 1499 RecordCurrentHistograms();
1500
1501 current_log->RecordGeneralMetrics(metrics_providers_.get());
1502
1472 log_manager_.FinishCurrentLog(); 1503 log_manager_.FinishCurrentLog();
1473 log_manager_.ResumePausedLog(); 1504 log_manager_.ResumePausedLog();
1474 1505
1475 DCHECK(!log_manager_.has_staged_log()); 1506 DCHECK(!log_manager_.has_staged_log());
1476 log_manager_.StageNextLogForUpload(); 1507 log_manager_.StageNextLogForUpload();
1477 } 1508 }
1478 1509
1479 void MetricsService::SendStagedLog() { 1510 void MetricsService::SendStagedLog() {
1480 DCHECK(log_manager_.has_staged_log()); 1511 DCHECK(log_manager_.has_staged_log());
1481 1512
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 } 1745 }
1715 return; 1746 return;
1716 } 1747 }
1717 } 1748 }
1718 1749
1719 SyntheticTrialGroup trial_group = trial; 1750 SyntheticTrialGroup trial_group = trial;
1720 trial_group.start_time = base::TimeTicks::Now(); 1751 trial_group.start_time = base::TimeTicks::Now();
1721 synthetic_trial_groups_.push_back(trial_group); 1752 synthetic_trial_groups_.push_back(trial_group);
1722 } 1753 }
1723 1754
1755 void MetricsService::RegisterMetricsProvider(
1756 scoped_ptr<metrics::MetricsProvider> provider) {
1757 DCHECK_EQ(INITIALIZED, state_);
1758 metrics_providers_.push_back(provider.release());
1759 }
1760
1724 void MetricsService::CheckForClonedInstall( 1761 void MetricsService::CheckForClonedInstall(
1725 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { 1762 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
1726 state_manager_->CheckForClonedInstall(task_runner); 1763 state_manager_->CheckForClonedInstall(task_runner);
1727 } 1764 }
1728 1765
1729 void MetricsService::GetCurrentSyntheticFieldTrials( 1766 void MetricsService::GetCurrentSyntheticFieldTrials(
1730 std::vector<variations::ActiveGroupId>* synthetic_trials) { 1767 std::vector<variations::ActiveGroupId>* synthetic_trials) {
1731 DCHECK(synthetic_trials); 1768 DCHECK(synthetic_trials);
1732 synthetic_trials->clear(); 1769 synthetic_trials->clear();
1733 const MetricsLog* current_log = 1770 const MetricsLog* current_log =
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1955 if (metrics_service) 1992 if (metrics_service)
1956 metrics_service->AddObserver(observer); 1993 metrics_service->AddObserver(observer);
1957 } 1994 }
1958 1995
1959 void MetricsServiceHelper::RemoveMetricsServiceObserver( 1996 void MetricsServiceHelper::RemoveMetricsServiceObserver(
1960 MetricsServiceObserver* observer) { 1997 MetricsServiceObserver* observer) {
1961 MetricsService* metrics_service = g_browser_process->metrics_service(); 1998 MetricsService* metrics_service = g_browser_process->metrics_service();
1962 if (metrics_service) 1999 if (metrics_service)
1963 metrics_service->RemoveObserver(observer); 2000 metrics_service->RemoveObserver(observer);
1964 } 2001 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_service.h ('k') | chrome/browser/metrics/metrics_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698