| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 1 | // | 
|  | 2 | // Copyright (C) 2017 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 | // | 
|  | 16 |  | 
|  | 17 | #ifndef UPDATE_ENGINE_METRICS_REPORTER_OMAHA_H_ | 
|  | 18 | #define UPDATE_ENGINE_METRICS_REPORTER_OMAHA_H_ | 
|  | 19 |  | 
| Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 20 | #include <memory> | 
|  | 21 |  | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 22 | #include <base/time/time.h> | 
|  | 23 | #include <metrics/metrics_library.h> | 
|  | 24 |  | 
|  | 25 | #include "update_engine/certificate_checker.h" | 
|  | 26 | #include "update_engine/common/constants.h" | 
|  | 27 | #include "update_engine/common/error_code.h" | 
|  | 28 | #include "update_engine/metrics_constants.h" | 
|  | 29 | #include "update_engine/metrics_reporter_interface.h" | 
|  | 30 | #include "update_engine/system_state.h" | 
|  | 31 |  | 
|  | 32 | namespace chromeos_update_engine { | 
|  | 33 |  | 
|  | 34 | class SystemState; | 
|  | 35 |  | 
| Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 36 | namespace metrics { | 
|  | 37 |  | 
|  | 38 | // UpdateEngine.Daily.* metrics. | 
|  | 39 | extern const char kMetricDailyOSAgeDays[]; | 
|  | 40 |  | 
|  | 41 | // UpdateEngine.Check.* metrics. | 
|  | 42 | extern const char kMetricCheckDownloadErrorCode[]; | 
|  | 43 | extern const char kMetricCheckReaction[]; | 
|  | 44 | extern const char kMetricCheckResult[]; | 
|  | 45 | extern const char kMetricCheckTimeSinceLastCheckMinutes[]; | 
|  | 46 | extern const char kMetricCheckTimeSinceLastCheckUptimeMinutes[]; | 
|  | 47 |  | 
|  | 48 | // UpdateEngine.Attempt.* metrics. | 
|  | 49 | extern const char kMetricAttemptNumber[]; | 
|  | 50 | extern const char kMetricAttemptPayloadType[]; | 
|  | 51 | extern const char kMetricAttemptPayloadSizeMiB[]; | 
|  | 52 | extern const char kMetricAttemptConnectionType[]; | 
|  | 53 | extern const char kMetricAttemptDurationMinutes[]; | 
|  | 54 | extern const char kMetricAttemptDurationUptimeMinutes[]; | 
|  | 55 | extern const char kMetricAttemptTimeSinceLastAttemptMinutes[]; | 
|  | 56 | extern const char kMetricAttemptTimeSinceLastAttemptUptimeMinutes[]; | 
|  | 57 | extern const char kMetricAttemptPayloadBytesDownloadedMiB[]; | 
|  | 58 | extern const char kMetricAttemptPayloadDownloadSpeedKBps[]; | 
|  | 59 | extern const char kMetricAttemptDownloadSource[]; | 
|  | 60 | extern const char kMetricAttemptResult[]; | 
|  | 61 | extern const char kMetricAttemptInternalErrorCode[]; | 
|  | 62 | extern const char kMetricAttemptDownloadErrorCode[]; | 
|  | 63 |  | 
|  | 64 | // UpdateEngine.SuccessfulUpdate.* metrics. | 
|  | 65 | extern const char kMetricSuccessfulUpdateAttemptCount[]; | 
|  | 66 | extern const char kMetricSuccessfulUpdateBytesDownloadedMiB[]; | 
|  | 67 | extern const char kMetricSuccessfulUpdateDownloadOverheadPercentage[]; | 
|  | 68 | extern const char kMetricSuccessfulUpdateDownloadSourcesUsed[]; | 
|  | 69 | extern const char kMetricSuccessfulUpdatePayloadType[]; | 
|  | 70 | extern const char kMetricSuccessfulUpdatePayloadSizeMiB[]; | 
|  | 71 | extern const char kMetricSuccessfulUpdateRebootCount[]; | 
|  | 72 | extern const char kMetricSuccessfulUpdateTotalDurationMinutes[]; | 
| Sen Jiang | 8712e96 | 2018-05-08 12:12:28 -0700 | [diff] [blame] | 73 | extern const char kMetricSuccessfulUpdateTotalDurationUptimeMinutes[]; | 
| Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 74 | extern const char kMetricSuccessfulUpdateUpdatesAbandonedCount[]; | 
|  | 75 | extern const char kMetricSuccessfulUpdateUrlSwitchCount[]; | 
|  | 76 |  | 
|  | 77 | // UpdateEngine.Rollback.* metric. | 
|  | 78 | extern const char kMetricRollbackResult[]; | 
|  | 79 |  | 
|  | 80 | // UpdateEngine.CertificateCheck.* metrics. | 
|  | 81 | extern const char kMetricCertificateCheckUpdateCheck[]; | 
|  | 82 | extern const char kMetricCertificateCheckDownload[]; | 
|  | 83 |  | 
|  | 84 | // UpdateEngine.* metrics. | 
|  | 85 | extern const char kMetricFailedUpdateCount[]; | 
|  | 86 | extern const char kMetricInstallDateProvisioningSource[]; | 
|  | 87 | extern const char kMetricTimeToRebootMinutes[]; | 
|  | 88 |  | 
|  | 89 | }  // namespace metrics | 
|  | 90 |  | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 91 | class MetricsReporterOmaha : public MetricsReporterInterface { | 
|  | 92 | public: | 
| Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 93 | MetricsReporterOmaha(); | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 94 |  | 
|  | 95 | ~MetricsReporterOmaha() override = default; | 
|  | 96 |  | 
|  | 97 | void Initialize() override; | 
|  | 98 |  | 
|  | 99 | void ReportRollbackMetrics(metrics::RollbackResult result) override; | 
|  | 100 |  | 
|  | 101 | void ReportDailyMetrics(base::TimeDelta os_age) override; | 
|  | 102 |  | 
|  | 103 | void ReportUpdateCheckMetrics( | 
|  | 104 | SystemState* system_state, | 
|  | 105 | metrics::CheckResult result, | 
|  | 106 | metrics::CheckReaction reaction, | 
|  | 107 | metrics::DownloadErrorCode download_error_code) override; | 
|  | 108 |  | 
| Tianjie Xu | 1f93d09 | 2017-10-09 12:13:29 -0700 | [diff] [blame] | 109 | void ReportUpdateAttemptMetrics(SystemState* system_state, | 
|  | 110 | int attempt_number, | 
|  | 111 | PayloadType payload_type, | 
|  | 112 | base::TimeDelta duration, | 
|  | 113 | base::TimeDelta duration_uptime, | 
|  | 114 | int64_t payload_size, | 
|  | 115 | metrics::AttemptResult attempt_result, | 
|  | 116 | ErrorCode internal_error_code) override; | 
|  | 117 |  | 
|  | 118 | void ReportUpdateAttemptDownloadMetrics( | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 119 | int64_t payload_bytes_downloaded, | 
|  | 120 | int64_t payload_download_speed_bps, | 
|  | 121 | DownloadSource download_source, | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 122 | metrics::DownloadErrorCode payload_download_error_code, | 
|  | 123 | metrics::ConnectionType connection_type) override; | 
|  | 124 |  | 
|  | 125 | void ReportAbnormallyTerminatedUpdateAttemptMetrics() override; | 
|  | 126 |  | 
|  | 127 | void ReportSuccessfulUpdateMetrics( | 
|  | 128 | int attempt_count, | 
|  | 129 | int updates_abandoned_count, | 
|  | 130 | PayloadType payload_type, | 
|  | 131 | int64_t payload_size, | 
|  | 132 | int64_t num_bytes_downloaded[kNumDownloadSources], | 
|  | 133 | int download_overhead_percentage, | 
|  | 134 | base::TimeDelta total_duration, | 
| Sen Jiang | 8712e96 | 2018-05-08 12:12:28 -0700 | [diff] [blame] | 135 | base::TimeDelta total_duration_uptime, | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 136 | int reboot_count, | 
|  | 137 | int url_switch_count) override; | 
|  | 138 |  | 
|  | 139 | void ReportCertificateCheckMetrics(ServerToCheck server_to_check, | 
|  | 140 | CertificateCheckResult result) override; | 
|  | 141 |  | 
|  | 142 | void ReportFailedUpdateCount(int target_attempt) override; | 
|  | 143 |  | 
|  | 144 | void ReportTimeToReboot(int time_to_reboot_minutes) override; | 
|  | 145 |  | 
|  | 146 | void ReportInstallDateProvisioningSource(int source, int max) override; | 
|  | 147 |  | 
|  | 148 | private: | 
| Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 149 | friend class MetricsReporterOmahaTest; | 
|  | 150 |  | 
|  | 151 | std::unique_ptr<MetricsLibraryInterface> metrics_lib_; | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 152 |  | 
|  | 153 | DISALLOW_COPY_AND_ASSIGN(MetricsReporterOmaha); | 
|  | 154 | };  // class metrics | 
|  | 155 |  | 
|  | 156 | }  // namespace chromeos_update_engine | 
|  | 157 |  | 
|  | 158 | #endif  // UPDATE_ENGINE_METRICS_REPORTER_OMAHA_H_ |