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 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 for (MetricsProvider* provider : metrics_providers_) | 522 for (MetricsProvider* provider : metrics_providers_) |
523 provider->ClearSavedStabilityMetrics(); | 523 provider->ClearSavedStabilityMetrics(); |
524 | 524 |
525 // Reset the prefs that are managed by MetricsService/MetricsLog directly. | 525 // Reset the prefs that are managed by MetricsService/MetricsLog directly. |
526 local_state_->SetInteger(prefs::kStabilityCrashCount, 0); | 526 local_state_->SetInteger(prefs::kStabilityCrashCount, 0); |
527 local_state_->SetInteger(prefs::kStabilityExecutionPhase, | 527 local_state_->SetInteger(prefs::kStabilityExecutionPhase, |
528 UNINITIALIZED_PHASE); | 528 UNINITIALIZED_PHASE); |
529 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); | 529 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
530 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); | 530 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); |
531 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); | 531 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); |
| 532 local_state_->SetInteger(prefs::kStabilityDeferredCount, 0); |
| 533 // Note: kStabilityDiscardCount is not cleared as its intent is to measure |
| 534 // the number of times data is discarded, even across versions. |
| 535 local_state_->SetInteger(prefs::kStabilityVersionMismatchCount, 0); |
| 536 |
| 537 // DO NOT SUBMIT: ask reviewer whether need to clear some prefs used in |
| 538 // metrics logs but not cleared, eg kStabilityBreakpadRegistrationFail, |
| 539 // kStabilityDebuggerPresent and even kStabilitySavedSystemProfile, etc. |
532 } | 540 } |
533 | 541 |
534 void MetricsService::PushExternalLog(const std::string& log) { | 542 void MetricsService::PushExternalLog(const std::string& log) { |
535 log_manager_.StoreLog(log, MetricsLog::ONGOING_LOG); | 543 log_manager_.StoreLog(log, MetricsLog::ONGOING_LOG); |
536 } | 544 } |
537 | 545 |
538 UpdateUsagePrefCallbackType MetricsService::GetDataUseForwardingCallback() { | 546 UpdateUsagePrefCallbackType MetricsService::GetDataUseForwardingCallback() { |
539 DCHECK(IsSingleThreaded()); | 547 DCHECK(IsSingleThreaded()); |
540 | 548 |
541 if (data_use_tracker_) { | 549 if (data_use_tracker_) { |
(...skipping 13 matching lines...) Expand all Loading... |
555 //------------------------------------------------------------------------------ | 563 //------------------------------------------------------------------------------ |
556 | 564 |
557 | 565 |
558 //------------------------------------------------------------------------------ | 566 //------------------------------------------------------------------------------ |
559 // Initialization methods | 567 // Initialization methods |
560 | 568 |
561 void MetricsService::InitializeMetricsState() { | 569 void MetricsService::InitializeMetricsState() { |
562 const int64_t buildtime = MetricsLog::GetBuildTime(); | 570 const int64_t buildtime = MetricsLog::GetBuildTime(); |
563 const std::string version = client_->GetVersionString(); | 571 const std::string version = client_->GetVersionString(); |
564 bool version_changed = false; | 572 bool version_changed = false; |
565 if (local_state_->GetInt64(prefs::kStabilityStatsBuildTime) != buildtime || | 573 int64_t previous_buildtime = |
566 local_state_->GetString(prefs::kStabilityStatsVersion) != version) { | 574 local_state_->GetInt64(prefs::kStabilityStatsBuildTime); |
| 575 std::string previous_version = |
| 576 local_state_->GetString(prefs::kStabilityStatsVersion); |
| 577 if (previous_buildtime != buildtime || previous_version != version) { |
567 local_state_->SetString(prefs::kStabilityStatsVersion, version); | 578 local_state_->SetString(prefs::kStabilityStatsVersion, version); |
568 local_state_->SetInt64(prefs::kStabilityStatsBuildTime, buildtime); | 579 local_state_->SetInt64(prefs::kStabilityStatsBuildTime, buildtime); |
569 version_changed = true; | 580 version_changed = true; |
570 } | 581 } |
571 | 582 |
572 log_manager_.LoadPersistedUnsentLogs(); | 583 log_manager_.LoadPersistedUnsentLogs(); |
573 | 584 |
574 session_id_ = local_state_->GetInteger(prefs::kMetricsSessionID); | 585 session_id_ = local_state_->GetInteger(prefs::kMetricsSessionID); |
575 | 586 |
576 if (!clean_exit_beacon_.exited_cleanly()) { | 587 if (!clean_exit_beacon_.exited_cleanly()) { |
(...skipping 11 matching lines...) Expand all Loading... |
588 // TODO(rtenneti): On windows, consider saving/getting execution_phase from | 599 // TODO(rtenneti): On windows, consider saving/getting execution_phase from |
589 // the registry. | 600 // the registry. |
590 int execution_phase = | 601 int execution_phase = |
591 local_state_->GetInteger(prefs::kStabilityExecutionPhase); | 602 local_state_->GetInteger(prefs::kStabilityExecutionPhase); |
592 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", | 603 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", |
593 execution_phase); | 604 execution_phase); |
594 | 605 |
595 // If the previous session didn't exit cleanly, or if any provider | 606 // If the previous session didn't exit cleanly, or if any provider |
596 // explicitly requests it, prepare an initial stability log - | 607 // explicitly requests it, prepare an initial stability log - |
597 // provided UMA is enabled. | 608 // provided UMA is enabled. |
598 if (state_manager_->IsMetricsReportingEnabled()) | 609 if (state_manager_->IsMetricsReportingEnabled()) { |
599 has_initial_stability_log = PrepareInitialStabilityLog(); | 610 has_initial_stability_log = PrepareInitialStabilityLog(previous_version); |
| 611 if (!has_initial_stability_log) |
| 612 IncrementPrefValue(prefs::kStabilityDeferredCount); |
| 613 } |
600 } | 614 } |
601 | 615 |
602 // If no initial stability log was generated and there was a version upgrade, | 616 // If no initial stability log was generated and there was a version upgrade, |
603 // clear the stability stats from the previous version (so that they don't get | 617 // clear the stability stats from the previous version (so that they don't get |
604 // attributed to the current version). This could otherwise happen due to a | 618 // attributed to the current version). This could otherwise happen due to a |
605 // number of different edge cases, such as if the last version crashed before | 619 // number of different edge cases, such as if the last version crashed before |
606 // it could save off a system profile or if UMA reporting is disabled (which | 620 // it could save off a system profile or if UMA reporting is disabled (which |
607 // normally results in stats being accumulated). | 621 // normally results in stats being accumulated). |
608 if (!has_initial_stability_log && version_changed) | 622 if (!has_initial_stability_log && version_changed) { |
609 ClearSavedStabilityMetrics(); | 623 ClearSavedStabilityMetrics(); |
| 624 IncrementPrefValue(prefs::kStabilityDiscardCount); |
| 625 } |
610 | 626 |
611 // Update session ID. | 627 // Update session ID. |
612 ++session_id_; | 628 ++session_id_; |
613 local_state_->SetInteger(prefs::kMetricsSessionID, session_id_); | 629 local_state_->SetInteger(prefs::kMetricsSessionID, session_id_); |
614 | 630 |
615 // Stability bookkeeping | 631 // Stability bookkeeping |
616 IncrementPrefValue(prefs::kStabilityLaunchCount); | 632 IncrementPrefValue(prefs::kStabilityLaunchCount); |
617 | 633 |
618 DCHECK_EQ(UNINITIALIZED_PHASE, execution_phase_); | 634 DCHECK_EQ(UNINITIALIZED_PHASE, execution_phase_); |
619 SetExecutionPhase(START_METRICS_RECORDING, local_state_); | 635 SetExecutionPhase(START_METRICS_RECORDING, local_state_); |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 bool MetricsService::ProvidersHaveInitialStabilityMetrics() { | 911 bool MetricsService::ProvidersHaveInitialStabilityMetrics() { |
896 // Check whether any metrics provider has initial stability metrics. | 912 // Check whether any metrics provider has initial stability metrics. |
897 for (MetricsProvider* provider : metrics_providers_) { | 913 for (MetricsProvider* provider : metrics_providers_) { |
898 if (provider->HasInitialStabilityMetrics()) | 914 if (provider->HasInitialStabilityMetrics()) |
899 return true; | 915 return true; |
900 } | 916 } |
901 | 917 |
902 return false; | 918 return false; |
903 } | 919 } |
904 | 920 |
905 bool MetricsService::PrepareInitialStabilityLog() { | 921 bool MetricsService::PrepareInitialStabilityLog( |
| 922 const std::string& prefs_previous_version) { |
906 DCHECK_EQ(INITIALIZED, state_); | 923 DCHECK_EQ(INITIALIZED, state_); |
907 | 924 |
908 std::unique_ptr<MetricsLog> initial_stability_log( | 925 std::unique_ptr<MetricsLog> initial_stability_log( |
909 CreateLog(MetricsLog::INITIAL_STABILITY_LOG)); | 926 CreateLog(MetricsLog::INITIAL_STABILITY_LOG)); |
910 | 927 |
911 // Do not call NotifyOnDidCreateMetricsLog here because the stability | 928 // Do not call NotifyOnDidCreateMetricsLog here because the stability |
912 // log describes stats from the _previous_ session. | 929 // log describes stats from the _previous_ session. |
913 | 930 std::string system_profile_app_version; |
914 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) | 931 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs( |
| 932 &system_profile_app_version)) |
915 return false; | 933 return false; |
| 934 if (system_profile_app_version != prefs_previous_version) |
| 935 IncrementPrefValue(prefs::kStabilityVersionMismatchCount); |
916 | 936 |
917 log_manager_.PauseCurrentLog(); | 937 log_manager_.PauseCurrentLog(); |
918 log_manager_.BeginLoggingWithLog(std::move(initial_stability_log)); | 938 log_manager_.BeginLoggingWithLog(std::move(initial_stability_log)); |
919 | 939 |
920 // Note: Some stability providers may record stability stats via histograms, | 940 // Note: Some stability providers may record stability stats via histograms, |
921 // so this call has to be after BeginLoggingWithLog(). | 941 // so this call has to be after BeginLoggingWithLog(). |
922 log_manager_.current_log()->RecordStabilityMetrics( | 942 log_manager_.current_log()->RecordStabilityMetrics( |
923 metrics_providers_.get(), base::TimeDelta(), base::TimeDelta()); | 943 metrics_providers_.get(), base::TimeDelta(), base::TimeDelta()); |
924 RecordCurrentStabilityHistograms(); | 944 RecordCurrentStabilityHistograms(); |
925 | 945 |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 base::Time::Now().ToTimeT()); | 1225 base::Time::Now().ToTimeT()); |
1206 } | 1226 } |
1207 | 1227 |
1208 void MetricsService::SkipAndDiscardUpload() { | 1228 void MetricsService::SkipAndDiscardUpload() { |
1209 log_manager_.DiscardStagedLog(); | 1229 log_manager_.DiscardStagedLog(); |
1210 scheduler_->UploadCancelled(); | 1230 scheduler_->UploadCancelled(); |
1211 log_upload_in_progress_ = false; | 1231 log_upload_in_progress_ = false; |
1212 } | 1232 } |
1213 | 1233 |
1214 } // namespace metrics | 1234 } // namespace metrics |
OLD | NEW |