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

Side by Side Diff: components/metrics/metrics_service.cc

Issue 2918533003: Send metrics with embedded system profiles after system startup. (Closed)
Patch Set: addressed final review comments Created 3 years, 6 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
« no previous file with comments | « components/metrics/metrics_service.h ('k') | components/metrics/metrics_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « components/metrics/metrics_service.h ('k') | components/metrics/metrics_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698