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 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
526 local_state_->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); | 526 local_state_->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); |
527 local_state_->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); | 527 local_state_->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); |
528 local_state_->SetInteger(prefs::kStabilityCrashCount, 0); | 528 local_state_->SetInteger(prefs::kStabilityCrashCount, 0); |
529 local_state_->SetInteger(prefs::kStabilityDebuggerPresent, 0); | 529 local_state_->SetInteger(prefs::kStabilityDebuggerPresent, 0); |
530 local_state_->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); | 530 local_state_->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); |
531 local_state_->SetInteger(prefs::kStabilityExecutionPhase, | 531 local_state_->SetInteger(prefs::kStabilityExecutionPhase, |
532 UNINITIALIZED_PHASE); | 532 UNINITIALIZED_PHASE); |
533 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); | 533 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
534 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); | 534 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); |
535 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); | 535 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); |
536 local_state_->SetInteger(prefs::kStabilityDeferredCount, 0); | |
537 // Note: kStabilityDiscardCount is not cleared as its intent is to measure | |
538 // the number of times data is discarded, even across versions. | |
539 local_state_->SetInteger(prefs::kStabilityVersionMismatchCount, 0); | |
536 } | 540 } |
537 | 541 |
538 void MetricsService::PushExternalLog(const std::string& log) { | 542 void MetricsService::PushExternalLog(const std::string& log) { |
539 log_manager_.StoreLog(log, MetricsLog::ONGOING_LOG); | 543 log_manager_.StoreLog(log, MetricsLog::ONGOING_LOG); |
540 } | 544 } |
541 | 545 |
542 UpdateUsagePrefCallbackType MetricsService::GetDataUseForwardingCallback() { | 546 UpdateUsagePrefCallbackType MetricsService::GetDataUseForwardingCallback() { |
543 DCHECK(IsSingleThreaded()); | 547 DCHECK(IsSingleThreaded()); |
544 | 548 |
545 if (data_use_tracker_) { | 549 if (data_use_tracker_) { |
(...skipping 13 matching lines...) Expand all Loading... | |
559 //------------------------------------------------------------------------------ | 563 //------------------------------------------------------------------------------ |
560 | 564 |
561 | 565 |
562 //------------------------------------------------------------------------------ | 566 //------------------------------------------------------------------------------ |
563 // Initialization methods | 567 // Initialization methods |
564 | 568 |
565 void MetricsService::InitializeMetricsState() { | 569 void MetricsService::InitializeMetricsState() { |
566 const int64_t buildtime = MetricsLog::GetBuildTime(); | 570 const int64_t buildtime = MetricsLog::GetBuildTime(); |
567 const std::string version = client_->GetVersionString(); | 571 const std::string version = client_->GetVersionString(); |
568 bool version_changed = false; | 572 bool version_changed = false; |
569 if (local_state_->GetInt64(prefs::kStabilityStatsBuildTime) != buildtime || | 573 int64_t previous_buildtime = |
570 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) { | |
571 local_state_->SetString(prefs::kStabilityStatsVersion, version); | 578 local_state_->SetString(prefs::kStabilityStatsVersion, version); |
572 local_state_->SetInt64(prefs::kStabilityStatsBuildTime, buildtime); | 579 local_state_->SetInt64(prefs::kStabilityStatsBuildTime, buildtime); |
573 version_changed = true; | 580 version_changed = true; |
574 } | 581 } |
575 | 582 |
576 log_manager_.LoadPersistedUnsentLogs(); | 583 log_manager_.LoadPersistedUnsentLogs(); |
577 | 584 |
578 session_id_ = local_state_->GetInteger(prefs::kMetricsSessionID); | 585 session_id_ = local_state_->GetInteger(prefs::kMetricsSessionID); |
579 | 586 |
580 if (!clean_exit_beacon_.exited_cleanly()) { | 587 if (!clean_exit_beacon_.exited_cleanly()) { |
(...skipping 11 matching lines...) Expand all Loading... | |
592 // TODO(rtenneti): On windows, consider saving/getting execution_phase from | 599 // TODO(rtenneti): On windows, consider saving/getting execution_phase from |
593 // the registry. | 600 // the registry. |
594 int execution_phase = | 601 int execution_phase = |
595 local_state_->GetInteger(prefs::kStabilityExecutionPhase); | 602 local_state_->GetInteger(prefs::kStabilityExecutionPhase); |
596 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", | 603 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", |
597 execution_phase); | 604 execution_phase); |
598 | 605 |
599 // 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 |
600 // explicitly requests it, prepare an initial stability log - | 607 // explicitly requests it, prepare an initial stability log - |
601 // provided UMA is enabled. | 608 // provided UMA is enabled. |
602 if (state_manager_->IsMetricsReportingEnabled()) | 609 if (state_manager_->IsMetricsReportingEnabled()) { |
603 has_initial_stability_log = PrepareInitialStabilityLog(); | 610 has_initial_stability_log = PrepareInitialStabilityLog(previous_version); |
611 if (!has_initial_stability_log) | |
612 IncrementPrefValue(prefs::kStabilityDeferredCount); | |
613 } | |
604 } | 614 } |
605 | 615 |
606 // 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, |
607 // 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 |
608 // 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 |
609 // 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 |
610 // 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 |
611 // normally results in stats being accumulated). | 621 // normally results in stats being accumulated). |
612 if (!has_initial_stability_log && version_changed) | 622 if (!has_initial_stability_log && version_changed) { |
613 ClearSavedStabilityMetrics(); | 623 ClearSavedStabilityMetrics(); |
624 IncrementPrefValue(prefs::kStabilityDiscardCount); | |
625 } | |
614 | 626 |
615 // Update session ID. | 627 // Update session ID. |
616 ++session_id_; | 628 ++session_id_; |
617 local_state_->SetInteger(prefs::kMetricsSessionID, session_id_); | 629 local_state_->SetInteger(prefs::kMetricsSessionID, session_id_); |
618 | 630 |
619 // Stability bookkeeping | 631 // Stability bookkeeping |
620 IncrementPrefValue(prefs::kStabilityLaunchCount); | 632 IncrementPrefValue(prefs::kStabilityLaunchCount); |
621 | 633 |
622 DCHECK_EQ(UNINITIALIZED_PHASE, execution_phase_); | 634 DCHECK_EQ(UNINITIALIZED_PHASE, execution_phase_); |
623 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... | |
899 bool MetricsService::ProvidersHaveInitialStabilityMetrics() { | 911 bool MetricsService::ProvidersHaveInitialStabilityMetrics() { |
900 // Check whether any metrics provider has initial stability metrics. | 912 // Check whether any metrics provider has initial stability metrics. |
901 for (MetricsProvider* provider : metrics_providers_) { | 913 for (MetricsProvider* provider : metrics_providers_) { |
902 if (provider->HasInitialStabilityMetrics()) | 914 if (provider->HasInitialStabilityMetrics()) |
903 return true; | 915 return true; |
904 } | 916 } |
905 | 917 |
906 return false; | 918 return false; |
907 } | 919 } |
908 | 920 |
909 bool MetricsService::PrepareInitialStabilityLog() { | 921 bool MetricsService::PrepareInitialStabilityLog( |
922 const std::string& prefs_previous_version) { | |
910 DCHECK_EQ(INITIALIZED, state_); | 923 DCHECK_EQ(INITIALIZED, state_); |
911 | 924 |
912 std::unique_ptr<MetricsLog> initial_stability_log( | 925 std::unique_ptr<MetricsLog> initial_stability_log( |
913 CreateLog(MetricsLog::INITIAL_STABILITY_LOG)); | 926 CreateLog(MetricsLog::INITIAL_STABILITY_LOG)); |
914 | 927 |
915 // Do not call NotifyOnDidCreateMetricsLog here because the stability | 928 // Do not call NotifyOnDidCreateMetricsLog here because the stability |
916 // log describes stats from the _previous_ session. | 929 // log describes stats from the _previous_ session. |
917 | 930 std::string system_profile_app_version; |
918 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) | 931 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs( |
932 &system_profile_app_version)) | |
Alexei Svitkine (slow)
2016/09/02 17:57:49
Nit: Add {}'s
manzagop (departed)
2016/09/02 21:00:06
Done.
| |
919 return false; | 933 return false; |
934 if (system_profile_app_version != prefs_previous_version) | |
935 IncrementPrefValue(prefs::kStabilityVersionMismatchCount); | |
920 | 936 |
921 log_manager_.PauseCurrentLog(); | 937 log_manager_.PauseCurrentLog(); |
922 log_manager_.BeginLoggingWithLog(std::move(initial_stability_log)); | 938 log_manager_.BeginLoggingWithLog(std::move(initial_stability_log)); |
923 | 939 |
924 // Note: Some stability providers may record stability stats via histograms, | 940 // Note: Some stability providers may record stability stats via histograms, |
925 // so this call has to be after BeginLoggingWithLog(). | 941 // so this call has to be after BeginLoggingWithLog(). |
926 log_manager_.current_log()->RecordStabilityMetrics( | 942 log_manager_.current_log()->RecordStabilityMetrics( |
927 metrics_providers_.get(), base::TimeDelta(), base::TimeDelta()); | 943 metrics_providers_.get(), base::TimeDelta(), base::TimeDelta()); |
928 RecordCurrentStabilityHistograms(); | 944 RecordCurrentStabilityHistograms(); |
929 | 945 |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1208 base::Time::Now().ToTimeT()); | 1224 base::Time::Now().ToTimeT()); |
1209 } | 1225 } |
1210 | 1226 |
1211 void MetricsService::SkipAndDiscardUpload() { | 1227 void MetricsService::SkipAndDiscardUpload() { |
1212 log_manager_.DiscardStagedLog(); | 1228 log_manager_.DiscardStagedLog(); |
1213 scheduler_->UploadCancelled(); | 1229 scheduler_->UploadCancelled(); |
1214 log_upload_in_progress_ = false; | 1230 log_upload_in_progress_ = false; |
1215 } | 1231 } |
1216 | 1232 |
1217 } // namespace metrics | 1233 } // namespace metrics |
OLD | NEW |