| Tianjie Xu | 1b66114 | 2017-09-28 14:03:42 -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 | #include "update_engine/metrics_reporter_android.h" | 
|  | 18 |  | 
| Tianjie Xu | d4c5deb | 2017-10-24 11:17:03 -0700 | [diff] [blame] | 19 | #include <memory> | 
| Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 20 | #include <string> | 
|  | 21 |  | 
| Tianjie Xu | 1b66114 | 2017-09-28 14:03:42 -0700 | [diff] [blame] | 22 | #include <metricslogger/metrics_logger.h> | 
| Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 23 |  | 
|  | 24 | #include "update_engine/common/constants.h" | 
| Tianjie Xu | 1b66114 | 2017-09-28 14:03:42 -0700 | [diff] [blame] | 25 |  | 
| Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 26 | namespace { | 
| Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 27 | void LogHistogram(const std::string& metrics, int value) { | 
|  | 28 | android::metricslogger::LogHistogram(metrics, value); | 
| Tianjie Xu | 8cbf696 | 2017-11-14 16:09:30 -0800 | [diff] [blame] | 29 | LOG(INFO) << "uploading " << value << " to histogram for metric " << metrics; | 
| Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 30 | } | 
| Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 31 | }  // namespace | 
|  | 32 |  | 
| Tianjie Xu | 1b66114 | 2017-09-28 14:03:42 -0700 | [diff] [blame] | 33 | namespace chromeos_update_engine { | 
|  | 34 |  | 
|  | 35 | namespace metrics { | 
|  | 36 |  | 
| Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 37 | // The histograms are defined in: | 
|  | 38 | // depot/google3/analysis/uma/configs/clearcut/TRON/histograms.xml | 
|  | 39 | constexpr char kMetricsUpdateEngineAttemptNumber[] = | 
| Tianjie Xu | 8cbf696 | 2017-11-14 16:09:30 -0800 | [diff] [blame] | 40 | "ota_update_engine_attempt_number"; | 
| Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 41 | constexpr char kMetricsUpdateEngineAttemptResult[] = | 
|  | 42 | "ota_update_engine_attempt_result"; | 
|  | 43 | constexpr char kMetricsUpdateEngineAttemptDurationInMinutes[] = | 
| Tianjie Xu | 82d9910 | 2017-11-02 22:26:19 -0700 | [diff] [blame] | 44 | "ota_update_engine_attempt_duration_boottime_in_minutes"; | 
| Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 45 | constexpr char kMetricsUpdateEngineAttemptDurationUptimeInMinutes[] = | 
| Tianjie Xu | 82d9910 | 2017-11-02 22:26:19 -0700 | [diff] [blame] | 46 | "ota_update_engine_attempt_duration_monotonic_in_minutes"; | 
| Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 47 | constexpr char kMetricsUpdateEngineAttemptErrorCode[] = | 
|  | 48 | "ota_update_engine_attempt_error_code"; | 
|  | 49 | constexpr char kMetricsUpdateEngineAttemptPayloadSizeMiB[] = | 
|  | 50 | "ota_update_engine_attempt_payload_size_mib"; | 
|  | 51 | constexpr char kMetricsUpdateEngineAttemptPayloadType[] = | 
|  | 52 | "ota_update_engine_attempt_payload_type"; | 
| Tianjie Xu | 82d9910 | 2017-11-02 22:26:19 -0700 | [diff] [blame] | 53 | constexpr char kMetricsUpdateEngineAttemptCurrentBytesDownloadedMiB[] = | 
|  | 54 | "ota_update_engine_attempt_current_bytes_downloaded_mib"; | 
| Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 55 |  | 
|  | 56 | constexpr char kMetricsUpdateEngineSuccessfulUpdateAttemptCount[] = | 
|  | 57 | "ota_update_engine_successful_update_attempt_count"; | 
|  | 58 | constexpr char kMetricsUpdateEngineSuccessfulUpdateTotalDurationInMinutes[] = | 
|  | 59 | "ota_update_engine_successful_update_total_duration_in_minutes"; | 
|  | 60 | constexpr char kMetricsUpdateEngineSuccessfulUpdatePayloadSizeMiB[] = | 
|  | 61 | "ota_update_engine_successful_update_payload_size_mib"; | 
|  | 62 | constexpr char kMetricsUpdateEngineSuccessfulUpdatePayloadType[] = | 
|  | 63 | "ota_update_engine_successful_update_payload_type"; | 
|  | 64 | constexpr char kMetricsUpdateEngineSuccessfulUpdateRebootCount[] = | 
|  | 65 | "ota_update_engine_successful_update_reboot_count"; | 
| Tianjie Xu | 82d9910 | 2017-11-02 22:26:19 -0700 | [diff] [blame] | 66 | constexpr char kMetricsUpdateEngineSuccessfulUpdateTotalBytesDownloadedMiB[] = | 
|  | 67 | "ota_update_engine_successful_update_total_bytes_downloaded_mib"; | 
|  | 68 | constexpr char | 
|  | 69 | kMetricsUpdateEngineSuccessfulUpdateDownloadOverheadPercentage[] = | 
|  | 70 | "ota_update_engine_successful_update_download_overhead_percentage"; | 
| Tianjie Xu | d4c5deb | 2017-10-24 11:17:03 -0700 | [diff] [blame] | 71 |  | 
|  | 72 | std::unique_ptr<MetricsReporterInterface> CreateMetricsReporter() { | 
|  | 73 | return std::make_unique<MetricsReporterAndroid>(); | 
|  | 74 | } | 
|  | 75 |  | 
| Tianjie Xu | 1b66114 | 2017-09-28 14:03:42 -0700 | [diff] [blame] | 76 | }  // namespace metrics | 
|  | 77 |  | 
|  | 78 | void MetricsReporterAndroid::ReportUpdateAttemptMetrics( | 
|  | 79 | SystemState* /* system_state */, | 
| Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 80 | int attempt_number, | 
|  | 81 | PayloadType payload_type, | 
|  | 82 | base::TimeDelta duration, | 
|  | 83 | base::TimeDelta duration_uptime, | 
|  | 84 | int64_t payload_size, | 
|  | 85 | metrics::AttemptResult attempt_result, | 
| Tianjie Xu | 1f93d09 | 2017-10-09 12:13:29 -0700 | [diff] [blame] | 86 | ErrorCode error_code) { | 
| Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 87 | LogHistogram(metrics::kMetricsUpdateEngineAttemptNumber, attempt_number); | 
|  | 88 | LogHistogram(metrics::kMetricsUpdateEngineAttemptPayloadType, | 
|  | 89 | static_cast<int>(payload_type)); | 
|  | 90 | LogHistogram(metrics::kMetricsUpdateEngineAttemptDurationInMinutes, | 
|  | 91 | duration.InMinutes()); | 
|  | 92 | LogHistogram(metrics::kMetricsUpdateEngineAttemptDurationUptimeInMinutes, | 
|  | 93 | duration_uptime.InMinutes()); | 
|  | 94 |  | 
|  | 95 | int64_t payload_size_mib = payload_size / kNumBytesInOneMiB; | 
|  | 96 | LogHistogram(metrics::kMetricsUpdateEngineAttemptPayloadSizeMiB, | 
|  | 97 | payload_size_mib); | 
|  | 98 |  | 
|  | 99 | LogHistogram(metrics::kMetricsUpdateEngineAttemptResult, | 
|  | 100 | static_cast<int>(attempt_result)); | 
|  | 101 | LogHistogram(metrics::kMetricsUpdateEngineAttemptErrorCode, | 
|  | 102 | static_cast<int>(error_code)); | 
| Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 103 | } | 
|  | 104 |  | 
| Tianjie Xu | 82d9910 | 2017-11-02 22:26:19 -0700 | [diff] [blame] | 105 | void MetricsReporterAndroid::ReportUpdateAttemptDownloadMetrics( | 
|  | 106 | int64_t payload_bytes_downloaded, | 
|  | 107 | int64_t /* payload_download_speed_bps */, | 
|  | 108 | DownloadSource /* download_source */, | 
|  | 109 | metrics::DownloadErrorCode /* payload_download_error_code */, | 
|  | 110 | metrics::ConnectionType /* connection_type */) { | 
|  | 111 | LogHistogram(metrics::kMetricsUpdateEngineAttemptCurrentBytesDownloadedMiB, | 
|  | 112 | payload_bytes_downloaded); | 
|  | 113 | } | 
|  | 114 |  | 
| Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 115 | void MetricsReporterAndroid::ReportSuccessfulUpdateMetrics( | 
|  | 116 | int attempt_count, | 
|  | 117 | int /* updates_abandoned_count */, | 
|  | 118 | PayloadType payload_type, | 
|  | 119 | int64_t payload_size, | 
| Tianjie Xu | 82d9910 | 2017-11-02 22:26:19 -0700 | [diff] [blame] | 120 | int64_t num_bytes_downloaded[kNumDownloadSources], | 
|  | 121 | int download_overhead_percentage, | 
| Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 122 | base::TimeDelta total_duration, | 
|  | 123 | int reboot_count, | 
|  | 124 | int /* url_switch_count */) { | 
| Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 125 | LogHistogram(metrics::kMetricsUpdateEngineSuccessfulUpdateAttemptCount, | 
|  | 126 | attempt_count); | 
|  | 127 | LogHistogram(metrics::kMetricsUpdateEngineSuccessfulUpdatePayloadType, | 
|  | 128 | static_cast<int>(payload_type)); | 
|  | 129 |  | 
|  | 130 | int64_t payload_size_mib = payload_size / kNumBytesInOneMiB; | 
|  | 131 | LogHistogram(metrics::kMetricsUpdateEngineSuccessfulUpdatePayloadSizeMiB, | 
|  | 132 | payload_size_mib); | 
|  | 133 |  | 
| Tianjie Xu | 82d9910 | 2017-11-02 22:26:19 -0700 | [diff] [blame] | 134 | int64_t total_bytes_downloaded = 0; | 
|  | 135 | for (size_t i = 0; i < kNumDownloadSources; i++) { | 
|  | 136 | total_bytes_downloaded += num_bytes_downloaded[i] / kNumBytesInOneMiB; | 
|  | 137 | } | 
|  | 138 | LogHistogram( | 
|  | 139 | metrics::kMetricsUpdateEngineSuccessfulUpdateTotalBytesDownloadedMiB, | 
|  | 140 | total_bytes_downloaded); | 
|  | 141 | LogHistogram( | 
|  | 142 | metrics::kMetricsUpdateEngineSuccessfulUpdateDownloadOverheadPercentage, | 
|  | 143 | download_overhead_percentage); | 
|  | 144 |  | 
| Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 145 | LogHistogram( | 
|  | 146 | metrics::kMetricsUpdateEngineSuccessfulUpdateTotalDurationInMinutes, | 
|  | 147 | total_duration.InMinutes()); | 
|  | 148 | LogHistogram(metrics::kMetricsUpdateEngineSuccessfulUpdateRebootCount, | 
|  | 149 | reboot_count); | 
| Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 150 | } | 
|  | 151 |  | 
|  | 152 | void MetricsReporterAndroid::ReportAbnormallyTerminatedUpdateAttemptMetrics() { | 
| Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 153 | int attempt_result = | 
|  | 154 | static_cast<int>(metrics::AttemptResult::kAbnormalTermination); | 
|  | 155 | LogHistogram(metrics::kMetricsUpdateEngineAttemptResult, attempt_result); | 
| Tianjie Xu | 1b66114 | 2017-09-28 14:03:42 -0700 | [diff] [blame] | 156 | } | 
|  | 157 |  | 
|  | 158 | };  // namespace chromeos_update_engine |