Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Side by Side Diff: components/metrics/stability_metrics_provider.cc

Issue 2687393004: Gather stability prefs into managing objects. (Closed)
Patch Set: Remove unused method Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/proto/system_profile.pb.h"
9 #include "components/metrics/stability_pref_names.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 // The server refuses data that doesn't have certain values. crashcount and
rkaplow 2017/02/14 20:11:19 ? Is this obsolete? Not sure if this is tring to r
Steven Holte 2017/02/15 22:42:09 After checking with Ilya, this comment dates back
57 // launchcount are currently "required" in the "stability" group.
58 // TODO(isherman): Stop writing these attributes specially once the migration
59 // to protobufs is complete.
60 int launch_count = local_state_->GetInteger(prefs::kStabilityLaunchCount);
61 if (launch_count)
62 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0);
63 int crash_count = local_state_->GetInteger(prefs::kStabilityCrashCount);
64 if (crash_count)
65 local_state_->SetInteger(prefs::kStabilityCrashCount, 0);
66 stability->set_launch_count(launch_count);
67 stability->set_crash_count(crash_count);
68
69 PrefService* pref = local_state_;
70 int incomplete_shutdown_count =
71 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
72 if (incomplete_shutdown_count) {
73 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
74 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
75 }
76
77 int breakpad_registration_success_count =
78 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
79 if (breakpad_registration_success_count) {
80 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
81 stability->set_breakpad_registration_success_count(
82 breakpad_registration_success_count);
83 }
84
85 int breakpad_registration_failure_count =
86 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
87 if (breakpad_registration_failure_count) {
88 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
89 stability->set_breakpad_registration_failure_count(
90 breakpad_registration_failure_count);
91 }
92
93 int debugger_present_count =
94 pref->GetInteger(prefs::kStabilityDebuggerPresent);
95 if (debugger_present_count) {
96 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
97 stability->set_debugger_present_count(debugger_present_count);
98 }
99
100 int debugger_not_present_count =
101 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
102 if (debugger_not_present_count) {
103 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
104 stability->set_debugger_not_present_count(debugger_not_present_count);
105 }
106
107 // Note: only logging the following histograms for non-zero values.
108 int deferred_count = pref->GetInteger(prefs::kStabilityDeferredCount);
109 if (deferred_count) {
110 local_state_->SetInteger(prefs::kStabilityDeferredCount, 0);
111 UMA_STABILITY_HISTOGRAM_COUNTS_100(
112 "Stability.Internals.InitialStabilityLogDeferredCount", deferred_count);
113 }
114
115 int discard_count = local_state_->GetInteger(prefs::kStabilityDiscardCount);
116 if (discard_count) {
117 local_state_->SetInteger(prefs::kStabilityDiscardCount, 0);
118 UMA_STABILITY_HISTOGRAM_COUNTS_100("Stability.Internals.DataDiscardCount",
119 discard_count);
120 }
121
122 int version_mismatch_count =
123 local_state_->GetInteger(prefs::kStabilityVersionMismatchCount);
124 if (version_mismatch_count) {
125 local_state_->SetInteger(prefs::kStabilityVersionMismatchCount, 0);
126 UMA_STABILITY_HISTOGRAM_COUNTS_100(
127 "Stability.Internals.VersionMismatchCount", version_mismatch_count);
128 }
129 }
130
131 void StabilityMetricsProvider::RecordBreakpadRegistration(bool success) {
132 if (!success)
133 IncrementPrefValue(prefs::kStabilityBreakpadRegistrationFail);
134 else
135 IncrementPrefValue(prefs::kStabilityBreakpadRegistrationSuccess);
136 }
137
138 void StabilityMetricsProvider::RecordBreakpadHasDebugger(bool has_debugger) {
139 if (!has_debugger)
140 IncrementPrefValue(prefs::kStabilityDebuggerNotPresent);
141 else
142 IncrementPrefValue(prefs::kStabilityDebuggerPresent);
143 }
144
145 void StabilityMetricsProvider::CheckLastSessionEndCompleted() {
146 if (!local_state_->GetBoolean(prefs::kStabilitySessionEndCompleted)) {
147 IncrementPrefValue(prefs::kStabilityIncompleteSessionEndCount);
148 // This is marked false when we get a WM_ENDSESSION.
149 MarkSessionEndCompleted(true);
150 }
151 }
152
153 void StabilityMetricsProvider::MarkSessionEndCompleted(bool end_completed) {
154 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, end_completed);
155 }
156
157 void StabilityMetricsProvider::LogCrash() {
158 IncrementPrefValue(prefs::kStabilityCrashCount);
159 }
160
161 void StabilityMetricsProvider::LogStabilityLogDeferred() {
162 IncrementPrefValue(prefs::kStabilityDeferredCount);
163 }
164
165 void StabilityMetricsProvider::LogStabilityDataDiscarded() {
166 IncrementPrefValue(prefs::kStabilityDiscardCount);
167 }
168
169 void StabilityMetricsProvider::LogLaunch() {
170 IncrementPrefValue(prefs::kStabilityLaunchCount);
171 }
172
173 void StabilityMetricsProvider::LogStabilityVersionMismatch() {
174 IncrementPrefValue(prefs::kStabilityVersionMismatchCount);
175 }
176
177 void StabilityMetricsProvider::IncrementPrefValue(const char* path) {
178 int value = local_state_->GetInteger(path);
179 local_state_->SetInteger(path, value + 1);
180 }
181
182 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698