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