| Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // | 
|  | 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 Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 16 |  | 
| Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_METRICS_H_ | 
|  | 18 | #define UPDATE_ENGINE_METRICS_H_ | 
| David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 19 |  | 
|  | 20 | #include <base/time/time.h> | 
|  | 21 |  | 
| Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 22 | #include "update_engine/common/certificate_checker.h" | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 23 | #include "update_engine/common/constants.h" | 
|  | 24 | #include "update_engine/common/error_code.h" | 
| David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 25 |  | 
|  | 26 | namespace chromeos_update_engine { | 
|  | 27 |  | 
|  | 28 | class SystemState; | 
|  | 29 |  | 
|  | 30 | namespace metrics { | 
|  | 31 |  | 
|  | 32 | // UpdateEngine.Daily.* metrics. | 
|  | 33 | extern const char kMetricDailyOSAgeDays[]; | 
|  | 34 |  | 
|  | 35 | // UpdateEngine.Check.* metrics. | 
|  | 36 | extern const char kMetricCheckDownloadErrorCode[]; | 
|  | 37 | extern const char kMetricCheckReaction[]; | 
|  | 38 | extern const char kMetricCheckResult[]; | 
|  | 39 | extern const char kMetricCheckTimeSinceLastCheckMinutes[]; | 
|  | 40 | extern const char kMetricCheckTimeSinceLastCheckUptimeMinutes[]; | 
|  | 41 |  | 
|  | 42 | // UpdateEngine.Attempt.* metrics. | 
|  | 43 | extern const char kMetricAttemptNumber[]; | 
|  | 44 | extern const char kMetricAttemptPayloadType[]; | 
|  | 45 | extern const char kMetricAttemptPayloadSizeMiB[]; | 
| David Zeuthen | b281f07 | 2014-04-02 10:20:19 -0700 | [diff] [blame] | 46 | extern const char kMetricAttemptConnectionType[]; | 
| David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 47 | extern const char kMetricAttemptDurationMinutes[]; | 
|  | 48 | extern const char kMetricAttemptDurationUptimeMinutes[]; | 
|  | 49 | extern const char kMetricAttemptTimeSinceLastAttemptSeconds[]; | 
|  | 50 | extern const char kMetricAttemptTimeSinceLastAttemptUptimeSeconds[]; | 
| David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 51 | extern const char kMetricAttemptPayloadBytesDownloaded[]; | 
|  | 52 | extern const char kMetricAttemptPayloadDownloadSpeedKBps[]; | 
|  | 53 | extern const char kMetricAttemptDownloadSource[]; | 
|  | 54 | extern const char kMetricAttemptResult[]; | 
|  | 55 | extern const char kMetricAttemptInternalErrorCode[]; | 
|  | 56 | extern const char kMetricAttemptDownloadErrorCode[]; | 
|  | 57 |  | 
|  | 58 | // UpdateEngine.SuccessfulUpdate.* metrics. | 
|  | 59 | extern const char kMetricSuccessfulUpdateAttemptCount[]; | 
|  | 60 | extern const char kMetricSuccessfulUpdateBytesDownloadedMiB[]; | 
|  | 61 | extern const char kMetricSuccessfulUpdateDownloadOverheadPercentage[]; | 
|  | 62 | extern const char kMetricSuccessfulUpdateDownloadSourcesUsed[]; | 
|  | 63 | extern const char kMetricSuccessfulUpdatePayloadType[]; | 
|  | 64 | extern const char kMetricSuccessfulUpdatePayloadSizeMiB[]; | 
|  | 65 | extern const char kMetricSuccessfulUpdateTotalDurationMinutes[]; | 
|  | 66 | extern const char kMetricSuccessfulUpdateRebootCount[]; | 
|  | 67 | extern const char kMetricSuccessfulUpdateUpdatesAbandonedCount[]; | 
|  | 68 | extern const char kMetricSuccessfulUpdateUrlSwitchCount[]; | 
|  | 69 |  | 
| David Zeuthen | 96197df | 2014-04-16 12:22:39 -0700 | [diff] [blame] | 70 | // UpdateEngine.Rollback.* metric. | 
|  | 71 | extern const char kMetricRollbackResult[]; | 
|  | 72 |  | 
| David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 73 | // UpdateEngine.* metrics. | 
|  | 74 | extern const char kMetricFailedUpdateCount[]; | 
|  | 75 | extern const char kMetricInstallDateProvisioningSource[]; | 
|  | 76 | extern const char kMetricTimeToRebootMinutes[]; | 
|  | 77 |  | 
|  | 78 | // The possible outcomes when checking for updates. | 
|  | 79 | // | 
|  | 80 | // This is used in the UpdateEngine.Check.Result histogram. | 
|  | 81 | enum 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. | 
|  | 95 | enum 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. | 
|  | 109 | enum 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. | 
|  | 140 | enum 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 Zeuthen | b281f07 | 2014-04-02 10:20:19 -0700 | [diff] [blame] | 158 | // Possible ways the device is connected to the Internet. | 
|  | 159 | // | 
|  | 160 | // This is used in the UpdateEngine.Attempt.ConnectionType histogram. | 
|  | 161 | enum 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 Zeuthen | 96197df | 2014-04-16 12:22:39 -0700 | [diff] [blame] | 175 | // Possible ways a rollback can end. | 
|  | 176 | // | 
|  | 177 | // This is used in the UpdateEngine.Rollback histogram. | 
|  | 178 | enum 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| | 
|  | 189 | void ReportRollbackMetrics(SystemState *system_state, | 
|  | 190 | RollbackResult result); | 
|  | 191 |  | 
| David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 192 | // Helper function to report metrics reported once a day. The | 
|  | 193 | // following metrics are reported: | 
|  | 194 | // | 
|  | 195 | //  |kMetricDailyOSAgeDays| | 
|  | 196 | void 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. | 
|  | 222 | void 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. | 
|  | 255 | void 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 Zeuthen | b281f07 | 2014-04-02 10:20:19 -0700 | [diff] [blame] | 267 | DownloadErrorCode payload_download_error_code, | 
|  | 268 | ConnectionType connection_type); | 
| David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 269 |  | 
| David Zeuthen | 4e1d149 | 2014-04-25 13:12:27 -0700 | [diff] [blame] | 270 | // Reports the |kAbnormalTermination| for the |kMetricAttemptResult| | 
|  | 271 | // metric. No other metrics in the UpdateEngine.Attempt.* namespace | 
|  | 272 | // will be reported. | 
|  | 273 | void ReportAbnormallyTerminatedUpdateAttemptMetrics(SystemState *system_state); | 
|  | 274 |  | 
| David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 275 | // 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. | 
|  | 295 | void 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 Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 307 | // 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| | 
|  | 312 | void ReportCertificateCheckMetrics(SystemState* system_state, | 
|  | 313 | ServerToCheck server_to_check, | 
|  | 314 | CertificateCheckResult result); | 
|  | 315 |  | 
| David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 316 | }  // namespace metrics | 
|  | 317 |  | 
|  | 318 | }  // namespace chromeos_update_engine | 
|  | 319 |  | 
| Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 320 | #endif  // UPDATE_ENGINE_METRICS_H_ |