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); |
| 29 | LOG(INFO) << "uploading " << value << "to histogram for metric " << metrics; |
| 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[] = |
| 40 | "ota_update_engine_attempt_count"; |
| 41 | constexpr char kMetricsUpdateEngineAttemptResult[] = |
| 42 | "ota_update_engine_attempt_result"; |
| 43 | constexpr char kMetricsUpdateEngineAttemptDurationInMinutes[] = |
| 44 | "ota_update_engine_attempt_duration_in_minutes"; |
| 45 | constexpr char kMetricsUpdateEngineAttemptDurationUptimeInMinutes[] = |
| 46 | "ota_update_engine_attempt_duration_uptime_in_minutes"; |
| 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"; |
| 53 | |
| 54 | constexpr char kMetricsUpdateEngineSuccessfulUpdateAttemptCount[] = |
| 55 | "ota_update_engine_successful_update_attempt_count"; |
| 56 | constexpr char kMetricsUpdateEngineSuccessfulUpdateTotalDurationInMinutes[] = |
| 57 | "ota_update_engine_successful_update_total_duration_in_minutes"; |
| 58 | constexpr char kMetricsUpdateEngineSuccessfulUpdatePayloadSizeMiB[] = |
| 59 | "ota_update_engine_successful_update_payload_size_mib"; |
| 60 | constexpr char kMetricsUpdateEngineSuccessfulUpdatePayloadType[] = |
| 61 | "ota_update_engine_successful_update_payload_type"; |
| 62 | constexpr char kMetricsUpdateEngineSuccessfulUpdateRebootCount[] = |
| 63 | "ota_update_engine_successful_update_reboot_count"; |
Tianjie Xu | d4c5deb | 2017-10-24 11:17:03 -0700 | [diff] [blame^] | 64 | |
| 65 | std::unique_ptr<MetricsReporterInterface> CreateMetricsReporter() { |
| 66 | return std::make_unique<MetricsReporterAndroid>(); |
| 67 | } |
| 68 | |
Tianjie Xu | 1b66114 | 2017-09-28 14:03:42 -0700 | [diff] [blame] | 69 | } // namespace metrics |
| 70 | |
| 71 | void MetricsReporterAndroid::ReportUpdateAttemptMetrics( |
| 72 | SystemState* /* system_state */, |
Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 73 | int attempt_number, |
| 74 | PayloadType payload_type, |
| 75 | base::TimeDelta duration, |
| 76 | base::TimeDelta duration_uptime, |
| 77 | int64_t payload_size, |
| 78 | metrics::AttemptResult attempt_result, |
Tianjie Xu | 1f93d09 | 2017-10-09 12:13:29 -0700 | [diff] [blame] | 79 | ErrorCode error_code) { |
Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 80 | LogHistogram(metrics::kMetricsUpdateEngineAttemptNumber, attempt_number); |
| 81 | LogHistogram(metrics::kMetricsUpdateEngineAttemptPayloadType, |
| 82 | static_cast<int>(payload_type)); |
| 83 | LogHistogram(metrics::kMetricsUpdateEngineAttemptDurationInMinutes, |
| 84 | duration.InMinutes()); |
| 85 | LogHistogram(metrics::kMetricsUpdateEngineAttemptDurationUptimeInMinutes, |
| 86 | duration_uptime.InMinutes()); |
| 87 | |
| 88 | int64_t payload_size_mib = payload_size / kNumBytesInOneMiB; |
| 89 | LogHistogram(metrics::kMetricsUpdateEngineAttemptPayloadSizeMiB, |
| 90 | payload_size_mib); |
| 91 | |
| 92 | LogHistogram(metrics::kMetricsUpdateEngineAttemptResult, |
| 93 | static_cast<int>(attempt_result)); |
| 94 | LogHistogram(metrics::kMetricsUpdateEngineAttemptErrorCode, |
| 95 | static_cast<int>(error_code)); |
Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | void MetricsReporterAndroid::ReportSuccessfulUpdateMetrics( |
| 99 | int attempt_count, |
| 100 | int /* updates_abandoned_count */, |
| 101 | PayloadType payload_type, |
| 102 | int64_t payload_size, |
| 103 | int64_t* /* num_bytes_downloaded */, |
| 104 | int /* download_overhead_percentage */, |
| 105 | base::TimeDelta total_duration, |
| 106 | int reboot_count, |
| 107 | int /* url_switch_count */) { |
Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 108 | LogHistogram(metrics::kMetricsUpdateEngineSuccessfulUpdateAttemptCount, |
| 109 | attempt_count); |
| 110 | LogHistogram(metrics::kMetricsUpdateEngineSuccessfulUpdatePayloadType, |
| 111 | static_cast<int>(payload_type)); |
| 112 | |
| 113 | int64_t payload_size_mib = payload_size / kNumBytesInOneMiB; |
| 114 | LogHistogram(metrics::kMetricsUpdateEngineSuccessfulUpdatePayloadSizeMiB, |
| 115 | payload_size_mib); |
| 116 | |
| 117 | LogHistogram( |
| 118 | metrics::kMetricsUpdateEngineSuccessfulUpdateTotalDurationInMinutes, |
| 119 | total_duration.InMinutes()); |
| 120 | LogHistogram(metrics::kMetricsUpdateEngineSuccessfulUpdateRebootCount, |
| 121 | reboot_count); |
Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | void MetricsReporterAndroid::ReportAbnormallyTerminatedUpdateAttemptMetrics() { |
Tianjie Xu | 52c678c | 2017-10-18 15:52:27 -0700 | [diff] [blame] | 125 | int attempt_result = |
| 126 | static_cast<int>(metrics::AttemptResult::kAbnormalTermination); |
| 127 | LogHistogram(metrics::kMetricsUpdateEngineAttemptResult, attempt_result); |
Tianjie Xu | 1b66114 | 2017-09-28 14:03:42 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | }; // namespace chromeos_update_engine |