| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/metrics/stability_metrics_provider.h" |
| 6 |
| 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "components/metrics/metrics_pref_names.h" |
| 9 #include "components/metrics/proto/system_profile.pb.h" |
| 10 #include "components/prefs/pref_registry_simple.h" |
| 11 #include "components/prefs/pref_service.h" |
| 12 |
| 13 namespace metrics { |
| 14 |
| 15 StabilityMetricsProvider::StabilityMetricsProvider(PrefService* local_state) |
| 16 : local_state_(local_state) {} |
| 17 |
| 18 StabilityMetricsProvider::~StabilityMetricsProvider() = default; |
| 19 |
| 20 // static |
| 21 void StabilityMetricsProvider::RegisterPrefs(PrefRegistrySimple* registry) { |
| 22 registry->RegisterIntegerPref(prefs::kStabilityCrashCount, 0); |
| 23 registry->RegisterIntegerPref(prefs::kStabilityIncompleteSessionEndCount, 0); |
| 24 registry->RegisterBooleanPref(prefs::kStabilitySessionEndCompleted, true); |
| 25 registry->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0); |
| 26 registry->RegisterIntegerPref(prefs::kStabilityBreakpadRegistrationFail, 0); |
| 27 registry->RegisterIntegerPref(prefs::kStabilityBreakpadRegistrationSuccess, |
| 28 0); |
| 29 registry->RegisterIntegerPref(prefs::kStabilityDebuggerPresent, 0); |
| 30 registry->RegisterIntegerPref(prefs::kStabilityDebuggerNotPresent, 0); |
| 31 registry->RegisterIntegerPref(prefs::kStabilityDeferredCount, 0); |
| 32 registry->RegisterIntegerPref(prefs::kStabilityDiscardCount, 0); |
| 33 registry->RegisterIntegerPref(prefs::kStabilityVersionMismatchCount, 0); |
| 34 } |
| 35 |
| 36 void StabilityMetricsProvider::ClearSavedStabilityMetrics() { |
| 37 local_state_->SetInteger(prefs::kStabilityCrashCount, 0); |
| 38 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
| 39 local_state_->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); |
| 40 local_state_->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); |
| 41 local_state_->SetInteger(prefs::kStabilityDebuggerPresent, 0); |
| 42 local_state_->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); |
| 43 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); |
| 44 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); |
| 45 local_state_->SetInteger(prefs::kStabilityDeferredCount, 0); |
| 46 // Note: kStabilityDiscardCount is not cleared as its intent is to measure |
| 47 // the number of times data is discarded, even across versions. |
| 48 local_state_->SetInteger(prefs::kStabilityVersionMismatchCount, 0); |
| 49 } |
| 50 |
| 51 void StabilityMetricsProvider::ProvideStabilityMetrics( |
| 52 SystemProfileProto* system_profile) { |
| 53 SystemProfileProto::Stability* stability = |
| 54 system_profile->mutable_stability(); |
| 55 |
| 56 int launch_count = local_state_->GetInteger(prefs::kStabilityLaunchCount); |
| 57 if (launch_count) { |
| 58 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); |
| 59 stability->set_launch_count(launch_count); |
| 60 } |
| 61 int crash_count = local_state_->GetInteger(prefs::kStabilityCrashCount); |
| 62 if (crash_count) { |
| 63 local_state_->SetInteger(prefs::kStabilityCrashCount, 0); |
| 64 stability->set_crash_count(crash_count); |
| 65 } |
| 66 |
| 67 int incomplete_shutdown_count = |
| 68 local_state_->GetInteger(prefs::kStabilityIncompleteSessionEndCount); |
| 69 if (incomplete_shutdown_count) { |
| 70 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
| 71 stability->set_incomplete_shutdown_count(incomplete_shutdown_count); |
| 72 } |
| 73 |
| 74 int breakpad_registration_success_count = |
| 75 local_state_->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess); |
| 76 if (breakpad_registration_success_count) { |
| 77 local_state_->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); |
| 78 stability->set_breakpad_registration_success_count( |
| 79 breakpad_registration_success_count); |
| 80 } |
| 81 |
| 82 int breakpad_registration_failure_count = |
| 83 local_state_->GetInteger(prefs::kStabilityBreakpadRegistrationFail); |
| 84 if (breakpad_registration_failure_count) { |
| 85 local_state_->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); |
| 86 stability->set_breakpad_registration_failure_count( |
| 87 breakpad_registration_failure_count); |
| 88 } |
| 89 |
| 90 int debugger_present_count = |
| 91 local_state_->GetInteger(prefs::kStabilityDebuggerPresent); |
| 92 if (debugger_present_count) { |
| 93 local_state_->SetInteger(prefs::kStabilityDebuggerPresent, 0); |
| 94 stability->set_debugger_present_count(debugger_present_count); |
| 95 } |
| 96 |
| 97 int debugger_not_present_count = |
| 98 local_state_->GetInteger(prefs::kStabilityDebuggerNotPresent); |
| 99 if (debugger_not_present_count) { |
| 100 local_state_->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); |
| 101 stability->set_debugger_not_present_count(debugger_not_present_count); |
| 102 } |
| 103 |
| 104 // Note: only logging the following histograms for non-zero values. |
| 105 int deferred_count = local_state_->GetInteger(prefs::kStabilityDeferredCount); |
| 106 if (deferred_count) { |
| 107 local_state_->SetInteger(prefs::kStabilityDeferredCount, 0); |
| 108 UMA_STABILITY_HISTOGRAM_COUNTS_100( |
| 109 "Stability.Internals.InitialStabilityLogDeferredCount", deferred_count); |
| 110 } |
| 111 |
| 112 int discard_count = local_state_->GetInteger(prefs::kStabilityDiscardCount); |
| 113 if (discard_count) { |
| 114 local_state_->SetInteger(prefs::kStabilityDiscardCount, 0); |
| 115 UMA_STABILITY_HISTOGRAM_COUNTS_100("Stability.Internals.DataDiscardCount", |
| 116 discard_count); |
| 117 } |
| 118 |
| 119 int version_mismatch_count = |
| 120 local_state_->GetInteger(prefs::kStabilityVersionMismatchCount); |
| 121 if (version_mismatch_count) { |
| 122 local_state_->SetInteger(prefs::kStabilityVersionMismatchCount, 0); |
| 123 UMA_STABILITY_HISTOGRAM_COUNTS_100( |
| 124 "Stability.Internals.VersionMismatchCount", version_mismatch_count); |
| 125 } |
| 126 } |
| 127 |
| 128 void StabilityMetricsProvider::RecordBreakpadRegistration(bool success) { |
| 129 if (!success) |
| 130 IncrementPrefValue(prefs::kStabilityBreakpadRegistrationFail); |
| 131 else |
| 132 IncrementPrefValue(prefs::kStabilityBreakpadRegistrationSuccess); |
| 133 } |
| 134 |
| 135 void StabilityMetricsProvider::RecordBreakpadHasDebugger(bool has_debugger) { |
| 136 if (!has_debugger) |
| 137 IncrementPrefValue(prefs::kStabilityDebuggerNotPresent); |
| 138 else |
| 139 IncrementPrefValue(prefs::kStabilityDebuggerPresent); |
| 140 } |
| 141 |
| 142 void StabilityMetricsProvider::CheckLastSessionEndCompleted() { |
| 143 if (!local_state_->GetBoolean(prefs::kStabilitySessionEndCompleted)) { |
| 144 IncrementPrefValue(prefs::kStabilityIncompleteSessionEndCount); |
| 145 // This is marked false when we get a WM_ENDSESSION. |
| 146 MarkSessionEndCompleted(true); |
| 147 } |
| 148 } |
| 149 |
| 150 void StabilityMetricsProvider::MarkSessionEndCompleted(bool end_completed) { |
| 151 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, end_completed); |
| 152 } |
| 153 |
| 154 void StabilityMetricsProvider::LogCrash() { |
| 155 IncrementPrefValue(prefs::kStabilityCrashCount); |
| 156 } |
| 157 |
| 158 void StabilityMetricsProvider::LogStabilityLogDeferred() { |
| 159 IncrementPrefValue(prefs::kStabilityDeferredCount); |
| 160 } |
| 161 |
| 162 void StabilityMetricsProvider::LogStabilityDataDiscarded() { |
| 163 IncrementPrefValue(prefs::kStabilityDiscardCount); |
| 164 } |
| 165 |
| 166 void StabilityMetricsProvider::LogLaunch() { |
| 167 IncrementPrefValue(prefs::kStabilityLaunchCount); |
| 168 } |
| 169 |
| 170 void StabilityMetricsProvider::LogStabilityVersionMismatch() { |
| 171 IncrementPrefValue(prefs::kStabilityVersionMismatchCount); |
| 172 } |
| 173 |
| 174 void StabilityMetricsProvider::IncrementPrefValue(const char* path) { |
| 175 int value = local_state_->GetInteger(path); |
| 176 local_state_->SetInteger(path, value + 1); |
| 177 } |
| 178 |
| 179 } // namespace metrics |
| OLD | NEW |