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