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