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 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 log_manager_.BeginLoggingWithLog(CreateLog(MetricsLog::ONGOING_LOG)); | 618 log_manager_.BeginLoggingWithLog(CreateLog(MetricsLog::ONGOING_LOG)); |
619 NotifyOnDidCreateMetricsLog(); | 619 NotifyOnDidCreateMetricsLog(); |
620 if (state_ == INITIALIZED) { | 620 if (state_ == INITIALIZED) { |
621 // We only need to schedule that run once. | 621 // We only need to schedule that run once. |
622 state_ = INIT_TASK_SCHEDULED; | 622 state_ = INIT_TASK_SCHEDULED; |
623 | 623 |
624 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 624 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
625 FROM_HERE, base::Bind(&MetricsService::StartInitTask, | 625 FROM_HERE, base::Bind(&MetricsService::StartInitTask, |
626 self_ptr_factory_.GetWeakPtr()), | 626 self_ptr_factory_.GetWeakPtr()), |
627 base::TimeDelta::FromSeconds(kInitializationDelaySeconds)); | 627 base::TimeDelta::FromSeconds(kInitializationDelaySeconds)); |
| 628 |
| 629 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 630 FROM_HERE, |
| 631 base::Bind(&MetricsService::PrepareProviderMetricsTask, |
| 632 self_ptr_factory_.GetWeakPtr()), |
| 633 base::TimeDelta::FromSeconds(2 * kInitializationDelaySeconds)); |
628 } | 634 } |
629 } | 635 } |
630 | 636 |
631 void MetricsService::StartInitTask() { | 637 void MetricsService::StartInitTask() { |
632 client_->InitializeSystemProfileMetrics( | 638 client_->InitializeSystemProfileMetrics( |
633 base::Bind(&MetricsService::FinishedInitTask, | 639 base::Bind(&MetricsService::FinishedInitTask, |
634 self_ptr_factory_.GetWeakPtr())); | 640 self_ptr_factory_.GetWeakPtr())); |
635 } | 641 } |
636 | 642 |
637 void MetricsService::CloseCurrentLog() { | 643 void MetricsService::CloseCurrentLog() { |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 DCHECK(log_manager_.current_log()); | 970 DCHECK(log_manager_.current_log()); |
965 // "true" indicates that StatisticsRecorder should include histograms in | 971 // "true" indicates that StatisticsRecorder should include histograms in |
966 // persistent storage. | 972 // persistent storage. |
967 histogram_snapshot_manager_.PrepareDeltas( | 973 histogram_snapshot_manager_.PrepareDeltas( |
968 base::StatisticsRecorder::begin(true), base::StatisticsRecorder::end(), | 974 base::StatisticsRecorder::begin(true), base::StatisticsRecorder::end(), |
969 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag); | 975 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag); |
970 for (auto& provider : metrics_providers_) | 976 for (auto& provider : metrics_providers_) |
971 provider->RecordInitialHistogramSnapshots(&histogram_snapshot_manager_); | 977 provider->RecordInitialHistogramSnapshots(&histogram_snapshot_manager_); |
972 } | 978 } |
973 | 979 |
| 980 bool MetricsService::PrepareProviderMetricsLog() { |
| 981 DCHECK(thread_checker_.CalledOnValidThread()); |
| 982 |
| 983 // Create a new log. This will have some defaut values injected in it but |
| 984 // those will be overwritten when an embedded profile is extracted. |
| 985 std::unique_ptr<MetricsLog> log = CreateLog(MetricsLog::INDEPENDENT_LOG); |
| 986 |
| 987 for (auto& provider : metrics_providers_) { |
| 988 if (log->LoadIndependentMetrics(provider.get())) { |
| 989 log_manager_.PauseCurrentLog(); |
| 990 log_manager_.BeginLoggingWithLog(std::move(log)); |
| 991 log_manager_.FinishCurrentLog(log_store()); |
| 992 log_manager_.ResumePausedLog(); |
| 993 return true; |
| 994 } |
| 995 } |
| 996 return false; |
| 997 } |
| 998 |
| 999 void MetricsService::PrepareProviderMetricsTask() { |
| 1000 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1001 bool found = PrepareProviderMetricsLog(); |
| 1002 base::TimeDelta next_check = found ? base::TimeDelta::FromSeconds(5) |
| 1003 : base::TimeDelta::FromMinutes(15); |
| 1004 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1005 FROM_HERE, |
| 1006 base::Bind(&MetricsService::PrepareProviderMetricsTask, |
| 1007 self_ptr_factory_.GetWeakPtr()), |
| 1008 next_check); |
| 1009 } |
| 1010 |
974 void MetricsService::LogCleanShutdown(bool end_completed) { | 1011 void MetricsService::LogCleanShutdown(bool end_completed) { |
975 DCHECK(thread_checker_.CalledOnValidThread()); | 1012 DCHECK(thread_checker_.CalledOnValidThread()); |
976 // Redundant setting to assure that we always reset this value at shutdown | 1013 // Redundant setting to assure that we always reset this value at shutdown |
977 // (and that we don't use some alternate path, and not call LogCleanShutdown). | 1014 // (and that we don't use some alternate path, and not call LogCleanShutdown). |
978 clean_shutdown_status_ = CLEANLY_SHUTDOWN; | 1015 clean_shutdown_status_ = CLEANLY_SHUTDOWN; |
979 client_->OnLogCleanShutdown(); | 1016 client_->OnLogCleanShutdown(); |
980 clean_exit_beacon_.WriteBeaconValue(true); | 1017 clean_exit_beacon_.WriteBeaconValue(true); |
981 SetExecutionPhase(ExecutionPhase::SHUTDOWN_COMPLETE, local_state_); | 1018 SetExecutionPhase(ExecutionPhase::SHUTDOWN_COMPLETE, local_state_); |
982 StabilityMetricsProvider(local_state_).MarkSessionEndCompleted(end_completed); | 1019 StabilityMetricsProvider(local_state_).MarkSessionEndCompleted(end_completed); |
983 } | 1020 } |
984 | 1021 |
985 } // namespace metrics | 1022 } // namespace metrics |
OLD | NEW |