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