| 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 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 | 551 |
| 552 //------------------------------------------------------------------------------ | 552 //------------------------------------------------------------------------------ |
| 553 // private methods | 553 // private methods |
| 554 //------------------------------------------------------------------------------ | 554 //------------------------------------------------------------------------------ |
| 555 | 555 |
| 556 | 556 |
| 557 //------------------------------------------------------------------------------ | 557 //------------------------------------------------------------------------------ |
| 558 // Initialization methods | 558 // Initialization methods |
| 559 | 559 |
| 560 void MetricsService::InitializeMetricsState() { | 560 void MetricsService::InitializeMetricsState() { |
| 561 local_state_->SetString(metrics::prefs::kStabilityStatsVersion, | 561 const int64 buildtime = MetricsLog::GetBuildTime(); |
| 562 client_->GetVersionString()); | 562 const std::string version = client_->GetVersionString(); |
| 563 local_state_->SetInt64(metrics::prefs::kStabilityStatsBuildTime, | 563 bool version_changed = false; |
| 564 MetricsLog::GetBuildTime()); | 564 if (local_state_->GetInt64(prefs::kStabilityStatsBuildTime) != buildtime || |
| 565 local_state_->GetString(prefs::kStabilityStatsVersion) != version) { |
| 566 local_state_->SetString(metrics::prefs::kStabilityStatsVersion, version); |
| 567 local_state_->SetInt64(metrics::prefs::kStabilityStatsBuildTime, buildtime); |
| 568 version_changed = true; |
| 569 } |
| 565 | 570 |
| 566 log_manager_.LoadPersistedUnsentLogs(); | 571 log_manager_.LoadPersistedUnsentLogs(); |
| 567 | 572 |
| 568 session_id_ = local_state_->GetInteger(metrics::prefs::kMetricsSessionID); | 573 session_id_ = local_state_->GetInteger(metrics::prefs::kMetricsSessionID); |
| 569 | 574 |
| 570 if (!clean_exit_beacon_.exited_cleanly()) { | 575 if (!clean_exit_beacon_.exited_cleanly()) { |
| 571 IncrementPrefValue(metrics::prefs::kStabilityCrashCount); | 576 IncrementPrefValue(metrics::prefs::kStabilityCrashCount); |
| 572 // Reset flag, and wait until we call LogNeedForCleanShutdown() before | 577 // Reset flag, and wait until we call LogNeedForCleanShutdown() before |
| 573 // monitoring. | 578 // monitoring. |
| 574 clean_exit_beacon_.WriteBeaconValue(true); | 579 clean_exit_beacon_.WriteBeaconValue(true); |
| 575 } | 580 } |
| 576 | 581 |
| 577 if (!clean_exit_beacon_.exited_cleanly() || ProvidersHaveStabilityMetrics()) { | 582 if (!clean_exit_beacon_.exited_cleanly() || ProvidersHaveStabilityMetrics()) { |
| 578 // TODO(rtenneti): On windows, consider saving/getting execution_phase from | 583 // TODO(rtenneti): On windows, consider saving/getting execution_phase from |
| 579 // the registry. | 584 // the registry. |
| 580 int execution_phase = | 585 int execution_phase = |
| 581 local_state_->GetInteger(metrics::prefs::kStabilityExecutionPhase); | 586 local_state_->GetInteger(metrics::prefs::kStabilityExecutionPhase); |
| 582 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", | 587 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", |
| 583 execution_phase); | 588 execution_phase); |
| 584 | 589 |
| 585 // If the previous session didn't exit cleanly, or if any provider | 590 // If the previous session didn't exit cleanly, or if any provider |
| 586 // explicitly requests it, prepare an initial stability log - | 591 // explicitly requests it, prepare an initial stability log - |
| 587 // provided UMA is enabled. | 592 // provided UMA is enabled. |
| 588 if (state_manager_->IsMetricsReportingEnabled()) | 593 if (state_manager_->IsMetricsReportingEnabled()) |
| 589 PrepareInitialStabilityLog(); | 594 PrepareInitialStabilityLog(); |
| 590 } | 595 } |
| 591 | 596 |
| 597 // If no initial stability log was generated and there was a version upgrade, |
| 598 // clear the stability stats from the previous version (so that they don't get |
| 599 // attributed to the current version). This could otherwise happen due to a |
| 600 // number of different edge cases, such as if the last version crashed before |
| 601 // it could save off a system profile or if UMA reporting is disabled (which |
| 602 // normally results in stats being accumulated). |
| 603 if (!has_initial_stability_log_ && version_changed) { |
| 604 for (size_t i = 0; i < metrics_providers_.size(); ++i) |
| 605 metrics_providers_[i]->ClearSavedStabilityMetrics(); |
| 606 |
| 607 // Reset the prefs that are managed by MetricsService/MetricsLog directly. |
| 608 local_state_->SetInteger(prefs::kStabilityCrashCount, 0); |
| 609 local_state_->SetInteger(prefs::kStabilityExecutionPhase, |
| 610 UNINITIALIZED_PHASE); |
| 611 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
| 612 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); |
| 613 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); |
| 614 } |
| 615 |
| 592 // Update session ID. | 616 // Update session ID. |
| 593 ++session_id_; | 617 ++session_id_; |
| 594 local_state_->SetInteger(metrics::prefs::kMetricsSessionID, session_id_); | 618 local_state_->SetInteger(metrics::prefs::kMetricsSessionID, session_id_); |
| 595 | 619 |
| 596 // Stability bookkeeping | 620 // Stability bookkeeping |
| 597 IncrementPrefValue(metrics::prefs::kStabilityLaunchCount); | 621 IncrementPrefValue(metrics::prefs::kStabilityLaunchCount); |
| 598 | 622 |
| 599 DCHECK_EQ(UNINITIALIZED_PHASE, execution_phase_); | 623 DCHECK_EQ(UNINITIALIZED_PHASE, execution_phase_); |
| 600 SetExecutionPhase(START_METRICS_RECORDING, local_state_); | 624 SetExecutionPhase(START_METRICS_RECORDING, local_state_); |
| 601 | 625 |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 local_state_->SetBoolean(path, value); | 1215 local_state_->SetBoolean(path, value); |
| 1192 RecordCurrentState(local_state_); | 1216 RecordCurrentState(local_state_); |
| 1193 } | 1217 } |
| 1194 | 1218 |
| 1195 void MetricsService::RecordCurrentState(PrefService* pref) { | 1219 void MetricsService::RecordCurrentState(PrefService* pref) { |
| 1196 pref->SetInt64(metrics::prefs::kStabilityLastTimestampSec, | 1220 pref->SetInt64(metrics::prefs::kStabilityLastTimestampSec, |
| 1197 base::Time::Now().ToTimeT()); | 1221 base::Time::Now().ToTimeT()); |
| 1198 } | 1222 } |
| 1199 | 1223 |
| 1200 } // namespace metrics | 1224 } // namespace metrics |
| OLD | NEW |