| 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[]; | 
 | 73 | extern const char kMetricSuccessfulUpdateUpdatesAbandonedCount[]; | 
 | 74 | extern const char kMetricSuccessfulUpdateUrlSwitchCount[]; | 
 | 75 |  | 
 | 76 | // UpdateEngine.Rollback.* metric. | 
 | 77 | extern const char kMetricRollbackResult[]; | 
 | 78 |  | 
 | 79 | // UpdateEngine.CertificateCheck.* metrics. | 
 | 80 | extern const char kMetricCertificateCheckUpdateCheck[]; | 
 | 81 | extern const char kMetricCertificateCheckDownload[]; | 
 | 82 |  | 
 | 83 | // UpdateEngine.* metrics. | 
 | 84 | extern const char kMetricFailedUpdateCount[]; | 
 | 85 | extern const char kMetricInstallDateProvisioningSource[]; | 
 | 86 | extern const char kMetricTimeToRebootMinutes[]; | 
 | 87 |  | 
 | 88 | }  // namespace metrics | 
 | 89 |  | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 90 | class MetricsReporterOmaha : public MetricsReporterInterface { | 
 | 91 |  public: | 
| Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 92 |   MetricsReporterOmaha(); | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 93 |  | 
 | 94 |   ~MetricsReporterOmaha() override = default; | 
 | 95 |  | 
 | 96 |   void Initialize() override; | 
 | 97 |  | 
 | 98 |   void ReportRollbackMetrics(metrics::RollbackResult result) override; | 
 | 99 |  | 
 | 100 |   void ReportDailyMetrics(base::TimeDelta os_age) override; | 
 | 101 |  | 
 | 102 |   void ReportUpdateCheckMetrics( | 
 | 103 |       SystemState* system_state, | 
 | 104 |       metrics::CheckResult result, | 
 | 105 |       metrics::CheckReaction reaction, | 
 | 106 |       metrics::DownloadErrorCode download_error_code) override; | 
 | 107 |  | 
| Tianjie Xu | 1f93d09 | 2017-10-09 12:13:29 -0700 | [diff] [blame] | 108 |   void ReportUpdateAttemptMetrics(SystemState* system_state, | 
 | 109 |                                   int attempt_number, | 
 | 110 |                                   PayloadType payload_type, | 
 | 111 |                                   base::TimeDelta duration, | 
 | 112 |                                   base::TimeDelta duration_uptime, | 
 | 113 |                                   int64_t payload_size, | 
 | 114 |                                   metrics::AttemptResult attempt_result, | 
 | 115 |                                   ErrorCode internal_error_code) override; | 
 | 116 |  | 
 | 117 |   void ReportUpdateAttemptDownloadMetrics( | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 118 |       int64_t payload_bytes_downloaded, | 
 | 119 |       int64_t payload_download_speed_bps, | 
 | 120 |       DownloadSource download_source, | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 121 |       metrics::DownloadErrorCode payload_download_error_code, | 
 | 122 |       metrics::ConnectionType connection_type) override; | 
 | 123 |  | 
 | 124 |   void ReportAbnormallyTerminatedUpdateAttemptMetrics() override; | 
 | 125 |  | 
 | 126 |   void ReportSuccessfulUpdateMetrics( | 
 | 127 |       int attempt_count, | 
 | 128 |       int updates_abandoned_count, | 
 | 129 |       PayloadType payload_type, | 
 | 130 |       int64_t payload_size, | 
 | 131 |       int64_t num_bytes_downloaded[kNumDownloadSources], | 
 | 132 |       int download_overhead_percentage, | 
 | 133 |       base::TimeDelta total_duration, | 
 | 134 |       int reboot_count, | 
 | 135 |       int url_switch_count) override; | 
 | 136 |  | 
 | 137 |   void ReportCertificateCheckMetrics(ServerToCheck server_to_check, | 
 | 138 |                                      CertificateCheckResult result) override; | 
 | 139 |  | 
 | 140 |   void ReportFailedUpdateCount(int target_attempt) override; | 
 | 141 |  | 
 | 142 |   void ReportTimeToReboot(int time_to_reboot_minutes) override; | 
 | 143 |  | 
 | 144 |   void ReportInstallDateProvisioningSource(int source, int max) override; | 
 | 145 |  | 
 | 146 |  private: | 
| Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 147 |   friend class MetricsReporterOmahaTest; | 
 | 148 |  | 
 | 149 |   std::unique_ptr<MetricsLibraryInterface> metrics_lib_; | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 150 |  | 
 | 151 |   DISALLOW_COPY_AND_ASSIGN(MetricsReporterOmaha); | 
 | 152 | };  // class metrics | 
 | 153 |  | 
 | 154 | }  // namespace chromeos_update_engine | 
 | 155 |  | 
 | 156 | #endif  // UPDATE_ENGINE_METRICS_REPORTER_OMAHA_H_ |