OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 | 383 |
384 if (recording_state_ == ACTIVE) | 384 if (recording_state_ == ACTIVE) |
385 return; | 385 return; |
386 recording_state_ = ACTIVE; | 386 recording_state_ = ACTIVE; |
387 | 387 |
388 state_manager_->ForceClientIdCreation(); | 388 state_manager_->ForceClientIdCreation(); |
389 client_->SetMetricsClientId(state_manager_->client_id()); | 389 client_->SetMetricsClientId(state_manager_->client_id()); |
390 if (!log_manager_.current_log()) | 390 if (!log_manager_.current_log()) |
391 OpenNewLog(); | 391 OpenNewLog(); |
392 | 392 |
393 for (size_t i = 0; i < metrics_providers_.size(); ++i) | 393 for (auto& provider : metrics_providers_) |
394 metrics_providers_[i]->OnRecordingEnabled(); | 394 provider->OnRecordingEnabled(); |
395 | 395 |
396 base::RemoveActionCallback(action_callback_); | 396 base::RemoveActionCallback(action_callback_); |
397 action_callback_ = base::Bind(&MetricsService::OnUserAction, | 397 action_callback_ = base::Bind(&MetricsService::OnUserAction, |
398 base::Unretained(this)); | 398 base::Unretained(this)); |
399 base::AddActionCallback(action_callback_); | 399 base::AddActionCallback(action_callback_); |
400 } | 400 } |
401 | 401 |
402 void MetricsService::DisableRecording() { | 402 void MetricsService::DisableRecording() { |
403 DCHECK(IsSingleThreaded()); | 403 DCHECK(IsSingleThreaded()); |
404 | 404 |
405 if (recording_state_ == INACTIVE) | 405 if (recording_state_ == INACTIVE) |
406 return; | 406 return; |
407 recording_state_ = INACTIVE; | 407 recording_state_ = INACTIVE; |
408 | 408 |
409 client_->OnRecordingDisabled(); | 409 client_->OnRecordingDisabled(); |
410 | 410 |
411 base::RemoveActionCallback(action_callback_); | 411 base::RemoveActionCallback(action_callback_); |
412 | 412 |
413 for (size_t i = 0; i < metrics_providers_.size(); ++i) | 413 for (auto& provider : metrics_providers_) |
414 metrics_providers_[i]->OnRecordingDisabled(); | 414 provider->OnRecordingDisabled(); |
415 | 415 |
416 PushPendingLogsToPersistentStorage(); | 416 PushPendingLogsToPersistentStorage(); |
417 } | 417 } |
418 | 418 |
419 bool MetricsService::recording_active() const { | 419 bool MetricsService::recording_active() const { |
420 DCHECK(IsSingleThreaded()); | 420 DCHECK(IsSingleThreaded()); |
421 return recording_state_ == ACTIVE; | 421 return recording_state_ == ACTIVE; |
422 } | 422 } |
423 | 423 |
424 bool MetricsService::reporting_active() const { | 424 bool MetricsService::reporting_active() const { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 } | 519 } |
520 | 520 |
521 void MetricsService::RecordBreakpadHasDebugger(bool has_debugger) { | 521 void MetricsService::RecordBreakpadHasDebugger(bool has_debugger) { |
522 if (!has_debugger) | 522 if (!has_debugger) |
523 IncrementPrefValue(prefs::kStabilityDebuggerNotPresent); | 523 IncrementPrefValue(prefs::kStabilityDebuggerNotPresent); |
524 else | 524 else |
525 IncrementPrefValue(prefs::kStabilityDebuggerPresent); | 525 IncrementPrefValue(prefs::kStabilityDebuggerPresent); |
526 } | 526 } |
527 | 527 |
528 void MetricsService::ClearSavedStabilityMetrics() { | 528 void MetricsService::ClearSavedStabilityMetrics() { |
529 for (size_t i = 0; i < metrics_providers_.size(); ++i) | 529 for (auto& provider : metrics_providers_) |
530 metrics_providers_[i]->ClearSavedStabilityMetrics(); | 530 provider->ClearSavedStabilityMetrics(); |
531 | 531 |
532 // Reset the prefs that are managed by MetricsService/MetricsLog directly. | 532 // Reset the prefs that are managed by MetricsService/MetricsLog directly. |
533 local_state_->SetInteger(prefs::kStabilityCrashCount, 0); | 533 local_state_->SetInteger(prefs::kStabilityCrashCount, 0); |
534 local_state_->SetInteger(prefs::kStabilityExecutionPhase, | 534 local_state_->SetInteger(prefs::kStabilityExecutionPhase, |
535 UNINITIALIZED_PHASE); | 535 UNINITIALIZED_PHASE); |
536 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); | 536 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
537 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); | 537 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); |
538 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); | 538 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); |
539 } | 539 } |
540 | 540 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
672 const int64_t incremental_time_secs = incremental_uptime->InSeconds(); | 672 const int64_t incremental_time_secs = incremental_uptime->InSeconds(); |
673 if (incremental_time_secs > 0) { | 673 if (incremental_time_secs > 0) { |
674 int64_t metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec); | 674 int64_t metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec); |
675 metrics_uptime += incremental_time_secs; | 675 metrics_uptime += incremental_time_secs; |
676 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime); | 676 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime); |
677 } | 677 } |
678 } | 678 } |
679 | 679 |
680 void MetricsService::NotifyOnDidCreateMetricsLog() { | 680 void MetricsService::NotifyOnDidCreateMetricsLog() { |
681 DCHECK(IsSingleThreaded()); | 681 DCHECK(IsSingleThreaded()); |
682 for (size_t i = 0; i < metrics_providers_.size(); ++i) | 682 for (auto& provider : metrics_providers_) |
683 metrics_providers_[i]->OnDidCreateMetricsLog(); | 683 provider->OnDidCreateMetricsLog(); |
684 } | 684 } |
685 | 685 |
686 //------------------------------------------------------------------------------ | 686 //------------------------------------------------------------------------------ |
687 // State save methods | 687 // State save methods |
688 | 688 |
689 void MetricsService::ScheduleNextStateSave() { | 689 void MetricsService::ScheduleNextStateSave() { |
690 state_saver_factory_.InvalidateWeakPtrs(); | 690 state_saver_factory_.InvalidateWeakPtrs(); |
691 | 691 |
692 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 692 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
693 FROM_HERE, base::Bind(&MetricsService::SaveLocalState, | 693 FROM_HERE, base::Bind(&MetricsService::SaveLocalState, |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
861 scheduler_->UploadFinished(true, log_manager_.has_unsent_logs()); | 861 scheduler_->UploadFinished(true, log_manager_.has_unsent_logs()); |
862 return; | 862 return; |
863 } | 863 } |
864 if (!log_manager_.has_staged_log()) | 864 if (!log_manager_.has_staged_log()) |
865 log_manager_.StageNextLogForUpload(); | 865 log_manager_.StageNextLogForUpload(); |
866 SendStagedLog(); | 866 SendStagedLog(); |
867 } | 867 } |
868 | 868 |
869 bool MetricsService::ProvidersHaveInitialStabilityMetrics() { | 869 bool MetricsService::ProvidersHaveInitialStabilityMetrics() { |
870 // Check whether any metrics provider has initial stability metrics. | 870 // Check whether any metrics provider has initial stability metrics. |
871 for (size_t i = 0; i < metrics_providers_.size(); ++i) { | 871 for (auto& provider : metrics_providers_) { |
872 if (metrics_providers_[i]->HasInitialStabilityMetrics()) | 872 if (provider->HasInitialStabilityMetrics()) |
873 return true; | 873 return true; |
874 } | 874 } |
875 | 875 |
876 return false; | 876 return false; |
877 } | 877 } |
878 | 878 |
879 bool MetricsService::PrepareInitialStabilityLog() { | 879 bool MetricsService::PrepareInitialStabilityLog() { |
880 DCHECK_EQ(INITIALIZED, state_); | 880 DCHECK_EQ(INITIALIZED, state_); |
881 | 881 |
882 scoped_ptr<MetricsLog> initial_stability_log( | 882 scoped_ptr<MetricsLog> initial_stability_log( |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1100 | 1100 |
1101 void MetricsService::RecordCurrentEnvironment(MetricsLog* log) { | 1101 void MetricsService::RecordCurrentEnvironment(MetricsLog* log) { |
1102 std::vector<variations::ActiveGroupId> synthetic_trials; | 1102 std::vector<variations::ActiveGroupId> synthetic_trials; |
1103 GetSyntheticFieldTrialsOlderThan(log->creation_time(), &synthetic_trials); | 1103 GetSyntheticFieldTrialsOlderThan(log->creation_time(), &synthetic_trials); |
1104 log->RecordEnvironment(metrics_providers_.get(), synthetic_trials, | 1104 log->RecordEnvironment(metrics_providers_.get(), synthetic_trials, |
1105 GetInstallDate(), GetMetricsReportingEnabledDate()); | 1105 GetInstallDate(), GetMetricsReportingEnabledDate()); |
1106 } | 1106 } |
1107 | 1107 |
1108 void MetricsService::RecordCurrentHistograms() { | 1108 void MetricsService::RecordCurrentHistograms() { |
1109 DCHECK(log_manager_.current_log()); | 1109 DCHECK(log_manager_.current_log()); |
1110 // "true" indicates that StatisticsRecorder should include histograms in | 1110 histogram_snapshot_manager_.StartDeltas(); |
1111 // persistent storage. | 1111 // "true" to the begin() call indicates that StatisticsRecorder should include |
1112 histogram_snapshot_manager_.PrepareDeltas( | 1112 // histograms held in persistent storage. |
1113 base::StatisticsRecorder::begin(true), base::StatisticsRecorder::end(), | 1113 auto end = base::StatisticsRecorder::end(); |
1114 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag); | 1114 for (auto it = base::StatisticsRecorder::begin(true); it != end; ++it) { |
1115 if ((*it)->flags() & base::Histogram::kUmaStabilityHistogramFlag) | |
1116 histogram_snapshot_manager_.PrepareDelta(*it); | |
1117 } | |
1118 for (auto& provider : metrics_providers_) | |
Alexei Svitkine (slow)
2016/02/17 21:55:36
Nit: "for (MetricsProvider* provider : metrics_pro
bcwhite
2016/02/18 01:46:57
Done.
| |
1119 provider->RecordHistogramSnapshots(&histogram_snapshot_manager_); | |
1120 histogram_snapshot_manager_.FinishDeltas(); | |
1115 } | 1121 } |
1116 | 1122 |
1117 void MetricsService::RecordCurrentStabilityHistograms() { | 1123 void MetricsService::RecordCurrentStabilityHistograms() { |
1118 DCHECK(log_manager_.current_log()); | 1124 DCHECK(log_manager_.current_log()); |
1119 // "true" indicates that StatisticsRecorder should include histograms in | 1125 // "true" indicates that StatisticsRecorder should include histograms in |
1120 // persistent storage. | 1126 // persistent storage. |
1121 histogram_snapshot_manager_.PrepareDeltas( | 1127 histogram_snapshot_manager_.PrepareDeltas( |
1122 base::StatisticsRecorder::begin(true), base::StatisticsRecorder::end(), | 1128 base::StatisticsRecorder::begin(true), base::StatisticsRecorder::end(), |
1123 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag); | 1129 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag); |
1124 } | 1130 } |
(...skipping 27 matching lines...) Expand all Loading... | |
1152 base::Time::Now().ToTimeT()); | 1158 base::Time::Now().ToTimeT()); |
1153 } | 1159 } |
1154 | 1160 |
1155 void MetricsService::SkipAndDiscardUpload() { | 1161 void MetricsService::SkipAndDiscardUpload() { |
1156 log_manager_.DiscardStagedLog(); | 1162 log_manager_.DiscardStagedLog(); |
1157 scheduler_->UploadCancelled(); | 1163 scheduler_->UploadCancelled(); |
1158 log_upload_in_progress_ = false; | 1164 log_upload_in_progress_ = false; |
1159 } | 1165 } |
1160 | 1166 |
1161 } // namespace metrics | 1167 } // namespace metrics |
OLD | NEW |