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( | |
Alexei Svitkine (slow)
2017/06/08 23:59:30
Please use the new post task APIs in base please.
bcwhite
2017/06/09 15:09:27
That API runs tasks on threads it owns rather than
| |
630 FROM_HERE, | |
631 base::Bind(&MetricsService::RecordIndependentHistogramJob, | |
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::RecordIndependentHistogramLog() { | |
Alexei Svitkine (slow)
2017/06/08 23:59:30
Nit: Add thread_checker_ tests here and below.
bcwhite
2017/06/09 15:09:27
Done.
| |
981 std::unique_ptr<MetricsLog> log = CreateLog(MetricsLog::INDEPENDENT_LOG); | |
Alexei Svitkine (slow)
2017/06/08 23:59:31
CreateLog() uses session_id_ but this is not corre
bcwhite
2017/06/09 15:09:27
Done.
| |
982 for (auto& provider : metrics_providers_) { | |
983 if (log->LoadIndependentMetrics(provider.get())) { | |
984 log_manager_.PauseCurrentLog(); | |
985 log_manager_.BeginLoggingWithLog(std::move(log)); | |
986 log_manager_.FinishCurrentLog(log_store()); | |
987 log_manager_.ResumePausedLog(); | |
988 return true; | |
989 } | |
990 } | |
991 return false; | |
992 } | |
993 | |
994 void MetricsService::RecordIndependentHistogramJob() { | |
995 bool found = RecordIndependentHistogramLog(); | |
996 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
997 FROM_HERE, | |
998 base::Bind(&MetricsService::RecordIndependentHistogramJob, | |
999 self_ptr_factory_.GetWeakPtr()), | |
1000 base::TimeDelta::FromSeconds(found ? 5 : 900)); | |
Alexei Svitkine (slow)
2017/06/08 23:59:30
Nit: instead FromMinutes(15) and move the found to
bcwhite
2017/06/09 15:09:27
Done.
| |
1001 } | |
1002 | |
974 void MetricsService::LogCleanShutdown(bool end_completed) { | 1003 void MetricsService::LogCleanShutdown(bool end_completed) { |
975 DCHECK(thread_checker_.CalledOnValidThread()); | 1004 DCHECK(thread_checker_.CalledOnValidThread()); |
976 // Redundant setting to assure that we always reset this value at shutdown | 1005 // 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). | 1006 // (and that we don't use some alternate path, and not call LogCleanShutdown). |
978 clean_shutdown_status_ = CLEANLY_SHUTDOWN; | 1007 clean_shutdown_status_ = CLEANLY_SHUTDOWN; |
979 client_->OnLogCleanShutdown(); | 1008 client_->OnLogCleanShutdown(); |
980 clean_exit_beacon_.WriteBeaconValue(true); | 1009 clean_exit_beacon_.WriteBeaconValue(true); |
981 SetExecutionPhase(ExecutionPhase::SHUTDOWN_COMPLETE, local_state_); | 1010 SetExecutionPhase(ExecutionPhase::SHUTDOWN_COMPLETE, local_state_); |
982 StabilityMetricsProvider(local_state_).MarkSessionEndCompleted(end_completed); | 1011 StabilityMetricsProvider(local_state_).MarkSessionEndCompleted(end_completed); |
983 } | 1012 } |
984 | 1013 |
985 } // namespace metrics | 1014 } // namespace metrics |
OLD | NEW |