blob: 7dfd9184bef9a7455b796de0ccd873fe2ee8482c [file] [log] [blame]
David Zeuthen33bae492014-02-25 16:16:18 -08001// Copyright 2014 The Chromium OS 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
Gilad Arnoldcf175a02014-07-10 16:48:47 -07005#ifndef UPDATE_ENGINE_METRICS_H_
6#define UPDATE_ENGINE_METRICS_H_
David Zeuthen33bae492014-02-25 16:16:18 -08007
8#include <base/time/time.h>
9
10#include "update_engine/constants.h"
11#include "update_engine/error_code.h"
12
13namespace chromeos_update_engine {
14
15class SystemState;
16
17namespace metrics {
18
19// UpdateEngine.Daily.* metrics.
20extern const char kMetricDailyOSAgeDays[];
21
22// UpdateEngine.Check.* metrics.
23extern const char kMetricCheckDownloadErrorCode[];
24extern const char kMetricCheckReaction[];
25extern const char kMetricCheckResult[];
26extern const char kMetricCheckTimeSinceLastCheckMinutes[];
27extern const char kMetricCheckTimeSinceLastCheckUptimeMinutes[];
28
29// UpdateEngine.Attempt.* metrics.
30extern const char kMetricAttemptNumber[];
31extern const char kMetricAttemptPayloadType[];
32extern const char kMetricAttemptPayloadSizeMiB[];
David Zeuthenb281f072014-04-02 10:20:19 -070033extern const char kMetricAttemptConnectionType[];
David Zeuthen33bae492014-02-25 16:16:18 -080034extern const char kMetricAttemptDurationMinutes[];
35extern const char kMetricAttemptDurationUptimeMinutes[];
36extern const char kMetricAttemptTimeSinceLastAttemptSeconds[];
37extern const char kMetricAttemptTimeSinceLastAttemptUptimeSeconds[];
David Zeuthen33bae492014-02-25 16:16:18 -080038extern const char kMetricAttemptPayloadBytesDownloaded[];
39extern const char kMetricAttemptPayloadDownloadSpeedKBps[];
40extern const char kMetricAttemptDownloadSource[];
41extern const char kMetricAttemptResult[];
42extern const char kMetricAttemptInternalErrorCode[];
43extern const char kMetricAttemptDownloadErrorCode[];
44
45// UpdateEngine.SuccessfulUpdate.* metrics.
46extern const char kMetricSuccessfulUpdateAttemptCount[];
47extern const char kMetricSuccessfulUpdateBytesDownloadedMiB[];
48extern const char kMetricSuccessfulUpdateDownloadOverheadPercentage[];
49extern const char kMetricSuccessfulUpdateDownloadSourcesUsed[];
50extern const char kMetricSuccessfulUpdatePayloadType[];
51extern const char kMetricSuccessfulUpdatePayloadSizeMiB[];
52extern const char kMetricSuccessfulUpdateTotalDurationMinutes[];
53extern const char kMetricSuccessfulUpdateRebootCount[];
54extern const char kMetricSuccessfulUpdateUpdatesAbandonedCount[];
55extern const char kMetricSuccessfulUpdateUrlSwitchCount[];
56
David Zeuthen96197df2014-04-16 12:22:39 -070057// UpdateEngine.Rollback.* metric.
58extern const char kMetricRollbackResult[];
59
David Zeuthen33bae492014-02-25 16:16:18 -080060// UpdateEngine.* metrics.
61extern const char kMetricFailedUpdateCount[];
62extern const char kMetricInstallDateProvisioningSource[];
63extern const char kMetricTimeToRebootMinutes[];
64
65// The possible outcomes when checking for updates.
66//
67// This is used in the UpdateEngine.Check.Result histogram.
68enum class CheckResult {
69 kUpdateAvailable, // Response indicates an update is available.
70 kNoUpdateAvailable, // Response indicates no updates are available.
71 kDownloadError, // Error downloading response from Omaha.
72 kParsingError, // Error parsing response.
73 kRebootPending, // No update check was performed a reboot is pending.
74
75 kNumConstants,
76 kUnset = -1
77};
78
79// Possible ways a device can react to a new update being available.
80//
81// This is used in the UpdateEngine.Check.Reaction histogram.
82enum class CheckReaction {
83 kUpdating, // Device proceeds to download and apply update.
84 kIgnored , // Device-policy dictates ignoring the update.
85 kDeferring, // Device-policy dictates waiting.
86 kBackingOff, // Previous errors dictates waiting.
87
88 kNumConstants,
89 kUnset = -1
90};
91
92// The possible ways that downloading from a HTTP or HTTPS server can fail.
93//
94// This is used in the UpdateEngine.Check.DownloadErrorCode and
95// UpdateEngine.Attempt.DownloadErrorCode histograms.
96enum class DownloadErrorCode {
97 // Errors that can happen in the field. See http://crbug.com/355745
98 // for how we plan to add more detail in the future.
99 kDownloadError = 0, // Error downloading data from server.
100
101 // IMPORTANT: When adding a new error code, add at the bottom of the
102 // above block and before the kInputMalformed field. This
103 // is to ensure that error codes are not reordered.
104
105 // This error code is used to convey that malformed input was given
106 // to the utils::GetDownloadErrorCode() function. This should never
107 // happen but if it does it's because of an internal update_engine
108 // error and we're interested in knowing this.
109 kInputMalformed = 100,
110
111 // Bucket for capturing HTTP status codes not in the 200-599
112 // range. This should never happen in practice but if it does we
113 // want to know.
114 kHttpStatusOther = 101,
115
116 // Above 200 and below 600, the value is the HTTP status code.
117 kHttpStatus200 = 200,
118
119 kNumConstants = 600,
120
121 kUnset = -1
122};
123
124// Possible ways an update attempt can end.
125//
126// This is used in the UpdateEngine.Attempt.Result histogram.
127enum class AttemptResult {
128 kUpdateSucceeded, // The update succeeded.
129 kInternalError, // An internal error occurred.
130 kPayloadDownloadError, // Failure while downloading payload.
131 kMetadataMalformed, // Metadata was malformed.
132 kOperationMalformed, // An operation was malformed.
133 kOperationExecutionError, // An operation failed to execute.
134 kMetadataVerificationFailed, // Metadata verification failed.
135 kPayloadVerificationFailed, // Payload verification failed.
136 kVerificationFailed, // Root or Kernel partition verification failed.
137 kPostInstallFailed, // The postinstall step failed.
138 kAbnormalTermination, // The attempt ended abnormally.
139
140 kNumConstants,
141
142 kUnset = -1
143};
144
David Zeuthenb281f072014-04-02 10:20:19 -0700145// Possible ways the device is connected to the Internet.
146//
147// This is used in the UpdateEngine.Attempt.ConnectionType histogram.
148enum class ConnectionType {
149 kUnknown, // Unknown.
150 kEthernet, // Ethernet.
151 kWifi, // Wireless.
152 kWimax, // WiMax.
153 kBluetooth, // Bluetooth.
154 kCellular, // Cellular.
155 kTetheredEthernet, // Tethered (Ethernet).
156 kTetheredWifi, // Tethered (Wifi).
157
158 kNumConstants,
159 kUnset = -1
160};
161
David Zeuthen96197df2014-04-16 12:22:39 -0700162// Possible ways a rollback can end.
163//
164// This is used in the UpdateEngine.Rollback histogram.
165enum class RollbackResult {
166 kFailed,
167 kSuccess,
168
169 kNumConstants
170};
171
172// Helper function to report metrics related to rollback. The
173// following metrics are reported:
174//
175// |kMetricRollbackResult|
176void ReportRollbackMetrics(SystemState *system_state,
177 RollbackResult result);
178
David Zeuthen33bae492014-02-25 16:16:18 -0800179// Helper function to report metrics reported once a day. The
180// following metrics are reported:
181//
182// |kMetricDailyOSAgeDays|
183void ReportDailyMetrics(SystemState *system_state,
184 base::TimeDelta os_age);
185
186// Helper function to report metrics after completing an update check
187// with the ChromeOS update server ("Omaha"). The following metrics
188// are reported:
189//
190// |kMetricCheckResult|
191// |kMetricCheckReaction|
192// |kMetricCheckDownloadErrorCode|
193// |kMetricCheckTimeSinceLastCheckMinutes|
194// |kMetricCheckTimeSinceLastCheckUptimeMinutes|
195//
196// The |kMetricCheckResult| metric will only be reported if |result|
197// is not |kUnset|.
198//
199// The |kMetricCheckReaction| metric will only be reported if
200// |reaction| is not |kUnset|.
201//
202// The |kMetricCheckDownloadErrorCode| will only be reported if
203// |download_error_code| is not |kUnset|.
204//
205// The values for the |kMetricCheckTimeSinceLastCheckMinutes| and
206// |kMetricCheckTimeSinceLastCheckUptimeMinutes| metrics are
207// automatically reported and calculated by maintaining persistent
208// and process-local state variables.
209void ReportUpdateCheckMetrics(SystemState *system_state,
210 CheckResult result,
211 CheckReaction reaction,
212 DownloadErrorCode download_error_code);
213
214
215// Helper function to report metrics after the completion of each
216// update attempt. The following metrics are reported:
217//
218// |kMetricAttemptNumber|
219// |kMetricAttemptPayloadType|
220// |kMetricAttemptPayloadSizeMiB|
221// |kMetricAttemptDurationSeconds|
222// |kMetricAttemptDurationUptimeSeconds|
223// |kMetricAttemptTimeSinceLastAttemptMinutes|
224// |kMetricAttemptTimeSinceLastAttemptUptimeMinutes|
225// |kMetricAttemptPayloadBytesDownloadedMiB|
226// |kMetricAttemptPayloadDownloadSpeedKBps|
227// |kMetricAttemptDownloadSource|
228// |kMetricAttemptResult|
229// |kMetricAttemptInternalErrorCode|
230// |kMetricAttemptDownloadErrorCode|
231//
232// The |kMetricAttemptInternalErrorCode| metric will only be reported
233// if |internal_error_code| is not |kErrorSuccess|.
234//
235// The |kMetricAttemptDownloadErrorCode| metric will only be
236// reported if |payload_download_error_code| is not |kUnset|.
237//
238// The values for the |kMetricAttemptTimeSinceLastAttemptMinutes| and
239// |kMetricAttemptTimeSinceLastAttemptUptimeMinutes| metrics are
240// automatically calculated and reported by maintaining persistent and
241// process-local state variables.
242void ReportUpdateAttemptMetrics(
243 SystemState *system_state,
244 int attempt_number,
245 PayloadType payload_type,
246 base::TimeDelta duration,
247 base::TimeDelta duration_uptime,
248 int64_t payload_size,
249 int64_t payload_bytes_downloaded,
250 int64_t payload_download_speed_bps,
251 DownloadSource download_source,
252 AttemptResult attempt_result,
253 ErrorCode internal_error_code,
David Zeuthenb281f072014-04-02 10:20:19 -0700254 DownloadErrorCode payload_download_error_code,
255 ConnectionType connection_type);
David Zeuthen33bae492014-02-25 16:16:18 -0800256
David Zeuthen4e1d1492014-04-25 13:12:27 -0700257// Reports the |kAbnormalTermination| for the |kMetricAttemptResult|
258// metric. No other metrics in the UpdateEngine.Attempt.* namespace
259// will be reported.
260void ReportAbnormallyTerminatedUpdateAttemptMetrics(SystemState *system_state);
261
David Zeuthen33bae492014-02-25 16:16:18 -0800262// Helper function to report the after the completion of a successful
263// update attempt. The following metrics are reported:
264//
265// |kMetricSuccessfulUpdateAttemptCount|
266// |kMetricSuccessfulUpdateUpdatesAbandonedCount|
267// |kMetricSuccessfulUpdatePayloadType|
268// |kMetricSuccessfulUpdatePayloadSizeMiB|
269// |kMetricSuccessfulUpdateBytesDownloadedMiBHttpsServer|
270// |kMetricSuccessfulUpdateBytesDownloadedMiBHttpServer|
271// |kMetricSuccessfulUpdateBytesDownloadedMiBHttpPeer|
272// |kMetricSuccessfulUpdateBytesDownloadedMiB|
273// |kMetricSuccessfulUpdateDownloadSourcesUsed|
274// |kMetricSuccessfulUpdateDownloadOverheadPercentage|
275// |kMetricSuccessfulUpdateTotalDurationMinutes|
276// |kMetricSuccessfulUpdateRebootCount|
277// |kMetricSuccessfulUpdateUrlSwitchCount|
278//
279// The values for the |kMetricSuccessfulUpdateDownloadSourcesUsed| are
280// |kMetricSuccessfulUpdateBytesDownloadedMiB| metrics automatically
281// calculated from examining the |num_bytes_downloaded| array.
282void ReportSuccessfulUpdateMetrics(
283 SystemState *system_state,
284 int attempt_count,
285 int updates_abandoned_count,
286 PayloadType payload_type,
287 int64_t payload_size,
288 int64_t num_bytes_downloaded[kNumDownloadSources],
289 int download_overhead_percentage,
290 base::TimeDelta total_duration,
291 int reboot_count,
292 int url_switch_count);
293
294} // namespace metrics
295
296} // namespace chromeos_update_engine
297
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700298#endif // UPDATE_ENGINE_METRICS_H_