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