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