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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
569 if (!local_state_->GetBoolean(metrics::prefs::kStabilityExitedCleanly)) { | 569 if (ShouldPrepareStabilityLog()) { |
570 IncrementPrefValue(metrics::prefs::kStabilityCrashCount); | 570 if (!local_state_->GetBoolean(metrics::prefs::kStabilityExitedCleanly)) { |
Alexei Svitkine (slow)
2014/09/09 15:34:28
It's kind of confusing to have the check for this
Sigurður Ásgeirsson
2014/09/09 17:13:40
Yups, that's much clearer.
| |
571 // Reset flag, and wait until we call LogNeedForCleanShutdown() before | 571 IncrementPrefValue(metrics::prefs::kStabilityCrashCount); |
572 // monitoring. | 572 |
573 local_state_->SetBoolean(metrics::prefs::kStabilityExitedCleanly, true); | 573 // Reset flag, and wait until we call LogNeedForCleanShutdown() before |
574 // monitoring. | |
575 local_state_->SetBoolean(metrics::prefs::kStabilityExitedCleanly, true); | |
576 } | |
574 | 577 |
575 // TODO(rtenneti): On windows, consider saving/getting execution_phase from | 578 // TODO(rtenneti): On windows, consider saving/getting execution_phase from |
576 // the registry. | 579 // the registry. |
577 int execution_phase = | 580 int execution_phase = |
578 local_state_->GetInteger(metrics::prefs::kStabilityExecutionPhase); | 581 local_state_->GetInteger(metrics::prefs::kStabilityExecutionPhase); |
579 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", | 582 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", |
580 execution_phase); | 583 execution_phase); |
581 | 584 |
582 // If the previous session didn't exit cleanly, then prepare an initial | 585 // If the previous session didn't exit cleanly, then prepare an initial |
Alexei Svitkine (slow)
2014/09/09 15:34:28
Update comment.
Sigurður Ásgeirsson
2014/09/09 17:13:40
Done.
| |
583 // stability log if UMA is enabled. | 586 // stability log if UMA is enabled. |
584 if (state_manager_->IsMetricsReportingEnabled()) | 587 if (state_manager_->IsMetricsReportingEnabled()) |
585 PrepareInitialStabilityLog(); | 588 PrepareInitialStabilityLog(); |
586 } | 589 } |
587 | 590 |
588 // Update session ID. | 591 // Update session ID. |
589 ++session_id_; | 592 ++session_id_; |
590 local_state_->SetInteger(metrics::prefs::kMetricsSessionID, session_id_); | 593 local_state_->SetInteger(metrics::prefs::kMetricsSessionID, session_id_); |
591 | 594 |
592 // Stability bookkeeping | 595 // Stability bookkeeping |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
902 break; | 905 break; |
903 | 906 |
904 default: | 907 default: |
905 NOTREACHED(); | 908 NOTREACHED(); |
906 return; | 909 return; |
907 } | 910 } |
908 | 911 |
909 DCHECK(log_manager_.has_staged_log()); | 912 DCHECK(log_manager_.has_staged_log()); |
910 } | 913 } |
911 | 914 |
915 bool MetricsService::ShouldPrepareStabilityLog() { | |
916 // Prepare a stability log if we had a crash in the previous session. | |
917 if (!local_state_->GetBoolean(metrics::prefs::kStabilityExitedCleanly)) | |
918 return true; | |
919 | |
920 // Or if any of the registered providers request it. | |
921 for (size_t i = 0; i < metrics_providers_.size(); ++i) { | |
922 if (metrics_providers_[i]->HasStabilityMetrics()) | |
923 return true; | |
924 } | |
925 | |
926 return false; | |
927 } | |
928 | |
912 void MetricsService::PrepareInitialStabilityLog() { | 929 void MetricsService::PrepareInitialStabilityLog() { |
913 DCHECK_EQ(INITIALIZED, state_); | 930 DCHECK_EQ(INITIALIZED, state_); |
914 DCHECK_NE(0, local_state_->GetInteger(metrics::prefs::kStabilityCrashCount)); | |
915 | 931 |
916 scoped_ptr<MetricsLog> initial_stability_log( | 932 scoped_ptr<MetricsLog> initial_stability_log( |
917 CreateLog(MetricsLog::INITIAL_STABILITY_LOG)); | 933 CreateLog(MetricsLog::INITIAL_STABILITY_LOG)); |
918 | 934 |
919 // Do not call NotifyOnDidCreateMetricsLog here because the stability | 935 // Do not call NotifyOnDidCreateMetricsLog here because the stability |
920 // log describes stats from the _previous_ session. | 936 // log describes stats from the _previous_ session. |
921 | 937 |
922 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) | 938 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) |
923 return; | 939 return; |
924 | 940 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1185 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { | 1201 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { |
1186 DCHECK(IsSingleThreaded()); | 1202 DCHECK(IsSingleThreaded()); |
1187 local_state_->SetBoolean(path, value); | 1203 local_state_->SetBoolean(path, value); |
1188 RecordCurrentState(local_state_); | 1204 RecordCurrentState(local_state_); |
1189 } | 1205 } |
1190 | 1206 |
1191 void MetricsService::RecordCurrentState(PrefService* pref) { | 1207 void MetricsService::RecordCurrentState(PrefService* pref) { |
1192 pref->SetInt64(metrics::prefs::kStabilityLastTimestampSec, | 1208 pref->SetInt64(metrics::prefs::kStabilityLastTimestampSec, |
1193 Time::Now().ToTimeT()); | 1209 Time::Now().ToTimeT()); |
1194 } | 1210 } |
OLD | NEW |