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

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

Issue 558653002: Allow MetricsProviders to request an initial stability log. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Move all MetricsProvider implementation to .cc file. Created 6 years, 3 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 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 557
558 void MetricsService::InitializeMetricsState() { 558 void MetricsService::InitializeMetricsState() {
559 local_state_->SetString(metrics::prefs::kStabilityStatsVersion, 559 local_state_->SetString(metrics::prefs::kStabilityStatsVersion,
560 client_->GetVersionString()); 560 client_->GetVersionString());
561 local_state_->SetInt64(metrics::prefs::kStabilityStatsBuildTime, 561 local_state_->SetInt64(metrics::prefs::kStabilityStatsBuildTime,
562 MetricsLog::GetBuildTime()); 562 MetricsLog::GetBuildTime());
563 563
564 log_manager_.LoadPersistedUnsentLogs(); 564 log_manager_.LoadPersistedUnsentLogs();
565 565
566 session_id_ = local_state_->GetInteger(metrics::prefs::kMetricsSessionID); 566 session_id_ = local_state_->GetInteger(metrics::prefs::kMetricsSessionID);
567 567 bool exited_cleanly = true;
568 if (!local_state_->GetBoolean(metrics::prefs::kStabilityExitedCleanly)) { 568 if (!local_state_->GetBoolean(metrics::prefs::kStabilityExitedCleanly)) {
569 IncrementPrefValue(metrics::prefs::kStabilityCrashCount); 569 IncrementPrefValue(metrics::prefs::kStabilityCrashCount);
570 // Reset flag, and wait until we call LogNeedForCleanShutdown() before 570 // Reset flag, and wait until we call LogNeedForCleanShutdown() before
571 // monitoring. 571 // monitoring.
572 local_state_->SetBoolean(metrics::prefs::kStabilityExitedCleanly, true); 572 local_state_->SetBoolean(metrics::prefs::kStabilityExitedCleanly, true);
573 exited_cleanly = false;
574 }
573 575
576 if (!exited_cleanly || ProvidersHaveStabilityMetrics()) {
574 // TODO(rtenneti): On windows, consider saving/getting execution_phase from 577 // TODO(rtenneti): On windows, consider saving/getting execution_phase from
575 // the registry. 578 // the registry.
576 int execution_phase = 579 int execution_phase =
577 local_state_->GetInteger(metrics::prefs::kStabilityExecutionPhase); 580 local_state_->GetInteger(metrics::prefs::kStabilityExecutionPhase);
578 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", 581 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase",
579 execution_phase); 582 execution_phase);
580 583
581 // If the previous session didn't exit cleanly, then prepare an initial 584 // If the previous session didn't exit cleanly, or if any provider
582 // stability log if UMA is enabled. 585 // explicitly requests it, prepare an initial stability log -
586 // provided UMA is enabled.
583 if (state_manager_->IsMetricsReportingEnabled()) 587 if (state_manager_->IsMetricsReportingEnabled())
584 PrepareInitialStabilityLog(); 588 PrepareInitialStabilityLog();
585 } 589 }
586 590
587 // Update session ID. 591 // Update session ID.
588 ++session_id_; 592 ++session_id_;
589 local_state_->SetInteger(metrics::prefs::kMetricsSessionID, session_id_); 593 local_state_->SetInteger(metrics::prefs::kMetricsSessionID, session_id_);
590 594
591 // Stability bookkeeping 595 // Stability bookkeeping
592 IncrementPrefValue(metrics::prefs::kStabilityLaunchCount); 596 IncrementPrefValue(metrics::prefs::kStabilityLaunchCount);
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 break; 893 break;
890 894
891 default: 895 default:
892 NOTREACHED(); 896 NOTREACHED();
893 return; 897 return;
894 } 898 }
895 899
896 DCHECK(log_manager_.has_staged_log()); 900 DCHECK(log_manager_.has_staged_log());
897 } 901 }
898 902
903 bool MetricsService::ProvidersHaveStabilityMetrics() {
904 // Check whether any metrics provider has stability metrics.
905 for (size_t i = 0; i < metrics_providers_.size(); ++i) {
906 if (metrics_providers_[i]->HasStabilityMetrics())
907 return true;
908 }
909
910 return false;
911 }
912
899 void MetricsService::PrepareInitialStabilityLog() { 913 void MetricsService::PrepareInitialStabilityLog() {
900 DCHECK_EQ(INITIALIZED, state_); 914 DCHECK_EQ(INITIALIZED, state_);
901 DCHECK_NE(0, local_state_->GetInteger(metrics::prefs::kStabilityCrashCount));
902 915
903 scoped_ptr<MetricsLog> initial_stability_log( 916 scoped_ptr<MetricsLog> initial_stability_log(
904 CreateLog(MetricsLog::INITIAL_STABILITY_LOG)); 917 CreateLog(MetricsLog::INITIAL_STABILITY_LOG));
905 918
906 // Do not call NotifyOnDidCreateMetricsLog here because the stability 919 // Do not call NotifyOnDidCreateMetricsLog here because the stability
907 // log describes stats from the _previous_ session. 920 // log describes stats from the _previous_ session.
908 921
909 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) 922 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs())
910 return; 923 return;
911 924
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 local_state_->SetBoolean(path, value); 1189 local_state_->SetBoolean(path, value);
1177 RecordCurrentState(local_state_); 1190 RecordCurrentState(local_state_);
1178 } 1191 }
1179 1192
1180 void MetricsService::RecordCurrentState(PrefService* pref) { 1193 void MetricsService::RecordCurrentState(PrefService* pref) {
1181 pref->SetInt64(metrics::prefs::kStabilityLastTimestampSec, 1194 pref->SetInt64(metrics::prefs::kStabilityLastTimestampSec,
1182 base::Time::Now().ToTimeT()); 1195 base::Time::Now().ToTimeT());
1183 } 1196 }
1184 1197
1185 } // namespace metrics 1198 } // 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