David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1 | // 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 Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 5 | #ifndef UPDATE_ENGINE_METRICS_H_ |
| 6 | #define UPDATE_ENGINE_METRICS_H_ |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 7 | |
| 8 | #include <base/time/time.h> |
| 9 | |
| 10 | #include "update_engine/constants.h" |
| 11 | #include "update_engine/error_code.h" |
| 12 | |
| 13 | namespace chromeos_update_engine { |
| 14 | |
| 15 | class SystemState; |
| 16 | |
| 17 | namespace metrics { |
| 18 | |
| 19 | // UpdateEngine.Daily.* metrics. |
| 20 | extern const char kMetricDailyOSAgeDays[]; |
| 21 | |
| 22 | // UpdateEngine.Check.* metrics. |
| 23 | extern const char kMetricCheckDownloadErrorCode[]; |
| 24 | extern const char kMetricCheckReaction[]; |
| 25 | extern const char kMetricCheckResult[]; |
| 26 | extern const char kMetricCheckTimeSinceLastCheckMinutes[]; |
| 27 | extern const char kMetricCheckTimeSinceLastCheckUptimeMinutes[]; |
| 28 | |
| 29 | // UpdateEngine.Attempt.* metrics. |
| 30 | extern const char kMetricAttemptNumber[]; |
| 31 | extern const char kMetricAttemptPayloadType[]; |
| 32 | extern const char kMetricAttemptPayloadSizeMiB[]; |
David Zeuthen | b281f07 | 2014-04-02 10:20:19 -0700 | [diff] [blame] | 33 | extern const char kMetricAttemptConnectionType[]; |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 34 | extern const char kMetricAttemptDurationMinutes[]; |
| 35 | extern const char kMetricAttemptDurationUptimeMinutes[]; |
| 36 | extern const char kMetricAttemptTimeSinceLastAttemptSeconds[]; |
| 37 | extern const char kMetricAttemptTimeSinceLastAttemptUptimeSeconds[]; |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 38 | extern const char kMetricAttemptPayloadBytesDownloaded[]; |
| 39 | extern const char kMetricAttemptPayloadDownloadSpeedKBps[]; |
| 40 | extern const char kMetricAttemptDownloadSource[]; |
| 41 | extern const char kMetricAttemptResult[]; |
| 42 | extern const char kMetricAttemptInternalErrorCode[]; |
| 43 | extern const char kMetricAttemptDownloadErrorCode[]; |
| 44 | |
| 45 | // UpdateEngine.SuccessfulUpdate.* metrics. |
| 46 | extern const char kMetricSuccessfulUpdateAttemptCount[]; |
| 47 | extern const char kMetricSuccessfulUpdateBytesDownloadedMiB[]; |
| 48 | extern const char kMetricSuccessfulUpdateDownloadOverheadPercentage[]; |
| 49 | extern const char kMetricSuccessfulUpdateDownloadSourcesUsed[]; |
| 50 | extern const char kMetricSuccessfulUpdatePayloadType[]; |
| 51 | extern const char kMetricSuccessfulUpdatePayloadSizeMiB[]; |
| 52 | extern const char kMetricSuccessfulUpdateTotalDurationMinutes[]; |
| 53 | extern const char kMetricSuccessfulUpdateRebootCount[]; |
| 54 | extern const char kMetricSuccessfulUpdateUpdatesAbandonedCount[]; |
| 55 | extern const char kMetricSuccessfulUpdateUrlSwitchCount[]; |
| 56 | |
David Zeuthen | 96197df | 2014-04-16 12:22:39 -0700 | [diff] [blame] | 57 | // UpdateEngine.Rollback.* metric. |
| 58 | extern const char kMetricRollbackResult[]; |
| 59 | |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 60 | // UpdateEngine.* metrics. |
| 61 | extern const char kMetricFailedUpdateCount[]; |
| 62 | extern const char kMetricInstallDateProvisioningSource[]; |
| 63 | extern const char kMetricTimeToRebootMinutes[]; |
| 64 | |
| 65 | // The possible outcomes when checking for updates. |
| 66 | // |
| 67 | // This is used in the UpdateEngine.Check.Result histogram. |
| 68 | enum 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. |
| 82 | enum 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. |
| 96 | enum 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. |
| 127 | enum 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 Zeuthen | b281f07 | 2014-04-02 10:20:19 -0700 | [diff] [blame] | 145 | // Possible ways the device is connected to the Internet. |
| 146 | // |
| 147 | // This is used in the UpdateEngine.Attempt.ConnectionType histogram. |
| 148 | enum 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 Zeuthen | 96197df | 2014-04-16 12:22:39 -0700 | [diff] [blame] | 162 | // Possible ways a rollback can end. |
| 163 | // |
| 164 | // This is used in the UpdateEngine.Rollback histogram. |
| 165 | enum 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| |
| 176 | void ReportRollbackMetrics(SystemState *system_state, |
| 177 | RollbackResult result); |
| 178 | |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 179 | // Helper function to report metrics reported once a day. The |
| 180 | // following metrics are reported: |
| 181 | // |
| 182 | // |kMetricDailyOSAgeDays| |
| 183 | void 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. |
| 209 | void 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. |
| 242 | void 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 Zeuthen | b281f07 | 2014-04-02 10:20:19 -0700 | [diff] [blame] | 254 | DownloadErrorCode payload_download_error_code, |
| 255 | ConnectionType connection_type); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 256 | |
David Zeuthen | 4e1d149 | 2014-04-25 13:12:27 -0700 | [diff] [blame] | 257 | // Reports the |kAbnormalTermination| for the |kMetricAttemptResult| |
| 258 | // metric. No other metrics in the UpdateEngine.Attempt.* namespace |
| 259 | // will be reported. |
| 260 | void ReportAbnormallyTerminatedUpdateAttemptMetrics(SystemState *system_state); |
| 261 | |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 262 | // 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. |
| 282 | void 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 Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 298 | #endif // UPDATE_ENGINE_METRICS_H_ |