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 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 | 558 |
559 void MetricsService::InitializeMetricsState() { | 559 void MetricsService::InitializeMetricsState() { |
560 local_state_->SetString(metrics::prefs::kStabilityStatsVersion, | 560 local_state_->SetString(metrics::prefs::kStabilityStatsVersion, |
561 client_->GetVersionString()); | 561 client_->GetVersionString()); |
562 local_state_->SetInt64(metrics::prefs::kStabilityStatsBuildTime, | 562 local_state_->SetInt64(metrics::prefs::kStabilityStatsBuildTime, |
563 MetricsLog::GetBuildTime()); | 563 MetricsLog::GetBuildTime()); |
564 | 564 |
565 log_manager_.LoadPersistedUnsentLogs(); | 565 log_manager_.LoadPersistedUnsentLogs(); |
566 | 566 |
567 session_id_ = local_state_->GetInteger(metrics::prefs::kMetricsSessionID); | 567 session_id_ = local_state_->GetInteger(metrics::prefs::kMetricsSessionID); |
568 | 568 bool exited_cleanly = true; |
569 if (!local_state_->GetBoolean(metrics::prefs::kStabilityExitedCleanly)) { | 569 if (!local_state_->GetBoolean(metrics::prefs::kStabilityExitedCleanly)) { |
570 IncrementPrefValue(metrics::prefs::kStabilityCrashCount); | 570 IncrementPrefValue(metrics::prefs::kStabilityCrashCount); |
571 // Reset flag, and wait until we call LogNeedForCleanShutdown() before | |
572 // monitoring. | |
Alexei Svitkine (slow)
2014/09/09 17:24:43
Nit: Preserve the comment.
Sigurður Ásgeirsson
2014/09/09 19:27:00
Oops, my bad. Done.
| |
573 local_state_->SetBoolean(metrics::prefs::kStabilityExitedCleanly, true); | 571 local_state_->SetBoolean(metrics::prefs::kStabilityExitedCleanly, true); |
572 exited_cleanly = false; | |
573 } | |
574 | 574 |
575 if (!exited_cleanly || ProvidersHaveStabilityMetrics()) { | |
575 // TODO(rtenneti): On windows, consider saving/getting execution_phase from | 576 // TODO(rtenneti): On windows, consider saving/getting execution_phase from |
576 // the registry. | 577 // the registry. |
577 int execution_phase = | 578 int execution_phase = |
578 local_state_->GetInteger(metrics::prefs::kStabilityExecutionPhase); | 579 local_state_->GetInteger(metrics::prefs::kStabilityExecutionPhase); |
579 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", | 580 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", |
580 execution_phase); | 581 execution_phase); |
581 | 582 |
582 // If the previous session didn't exit cleanly, then prepare an initial | 583 // If the previous session didn't exit cleanly, or if any provider |
583 // stability log if UMA is enabled. | 584 // explicitly requests it, prepare an initial stability log - |
585 // provided UMA is enabled. | |
584 if (state_manager_->IsMetricsReportingEnabled()) | 586 if (state_manager_->IsMetricsReportingEnabled()) |
585 PrepareInitialStabilityLog(); | 587 PrepareInitialStabilityLog(); |
586 } | 588 } |
587 | 589 |
588 // Update session ID. | 590 // Update session ID. |
589 ++session_id_; | 591 ++session_id_; |
590 local_state_->SetInteger(metrics::prefs::kMetricsSessionID, session_id_); | 592 local_state_->SetInteger(metrics::prefs::kMetricsSessionID, session_id_); |
591 | 593 |
592 // Stability bookkeeping | 594 // Stability bookkeeping |
593 IncrementPrefValue(metrics::prefs::kStabilityLaunchCount); | 595 IncrementPrefValue(metrics::prefs::kStabilityLaunchCount); |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
902 break; | 904 break; |
903 | 905 |
904 default: | 906 default: |
905 NOTREACHED(); | 907 NOTREACHED(); |
906 return; | 908 return; |
907 } | 909 } |
908 | 910 |
909 DCHECK(log_manager_.has_staged_log()); | 911 DCHECK(log_manager_.has_staged_log()); |
910 } | 912 } |
911 | 913 |
914 bool MetricsService::ProvidersHaveStabilityMetrics() { | |
915 // Check whether any metrics provider has stability metrics. | |
916 for (size_t i = 0; i < metrics_providers_.size(); ++i) { | |
917 if (metrics_providers_[i]->HasStabilityMetrics()) | |
918 return true; | |
919 } | |
920 | |
921 return false; | |
922 } | |
923 | |
912 void MetricsService::PrepareInitialStabilityLog() { | 924 void MetricsService::PrepareInitialStabilityLog() { |
913 DCHECK_EQ(INITIALIZED, state_); | 925 DCHECK_EQ(INITIALIZED, state_); |
914 DCHECK_NE(0, local_state_->GetInteger(metrics::prefs::kStabilityCrashCount)); | |
915 | 926 |
916 scoped_ptr<MetricsLog> initial_stability_log( | 927 scoped_ptr<MetricsLog> initial_stability_log( |
917 CreateLog(MetricsLog::INITIAL_STABILITY_LOG)); | 928 CreateLog(MetricsLog::INITIAL_STABILITY_LOG)); |
918 | 929 |
919 // Do not call NotifyOnDidCreateMetricsLog here because the stability | 930 // Do not call NotifyOnDidCreateMetricsLog here because the stability |
920 // log describes stats from the _previous_ session. | 931 // log describes stats from the _previous_ session. |
921 | 932 |
922 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) | 933 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) |
923 return; | 934 return; |
924 | 935 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1185 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { | 1196 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { |
1186 DCHECK(IsSingleThreaded()); | 1197 DCHECK(IsSingleThreaded()); |
1187 local_state_->SetBoolean(path, value); | 1198 local_state_->SetBoolean(path, value); |
1188 RecordCurrentState(local_state_); | 1199 RecordCurrentState(local_state_); |
1189 } | 1200 } |
1190 | 1201 |
1191 void MetricsService::RecordCurrentState(PrefService* pref) { | 1202 void MetricsService::RecordCurrentState(PrefService* pref) { |
1192 pref->SetInt64(metrics::prefs::kStabilityLastTimestampSec, | 1203 pref->SetInt64(metrics::prefs::kStabilityLastTimestampSec, |
1193 Time::Now().ToTimeT()); | 1204 Time::Now().ToTimeT()); |
1194 } | 1205 } |
OLD | NEW |