blob: 9165f0d5f17914c23d94ebd3b94876bdcad4f7ac [file] [log] [blame]
Tianjie Xu1b661142017-09-28 14:03:42 -07001//
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 Xud4c5deb2017-10-24 11:17:03 -070019#include <memory>
Tianjie Xu52c678c2017-10-18 15:52:27 -070020#include <string>
21
Tianjie Xu1b661142017-09-28 14:03:42 -070022#include <metricslogger/metrics_logger.h>
Tianjie Xu52c678c2017-10-18 15:52:27 -070023
24#include "update_engine/common/constants.h"
Tianjie Xu1b661142017-09-28 14:03:42 -070025
Tianjie Xu52c678c2017-10-18 15:52:27 -070026namespace {
Tianjie Xu52c678c2017-10-18 15:52:27 -070027void LogHistogram(const std::string& metrics, int value) {
28 android::metricslogger::LogHistogram(metrics, value);
Tianjie Xu8cbf6962017-11-14 16:09:30 -080029 LOG(INFO) << "uploading " << value << " to histogram for metric " << metrics;
Tianjie Xu52c678c2017-10-18 15:52:27 -070030}
Tianjie Xu52c678c2017-10-18 15:52:27 -070031} // namespace
32
Tianjie Xu1b661142017-09-28 14:03:42 -070033namespace chromeos_update_engine {
34
35namespace metrics {
36
Tianjie Xu52c678c2017-10-18 15:52:27 -070037// The histograms are defined in:
38// depot/google3/analysis/uma/configs/clearcut/TRON/histograms.xml
39constexpr char kMetricsUpdateEngineAttemptNumber[] =
Tianjie Xu8cbf6962017-11-14 16:09:30 -080040 "ota_update_engine_attempt_number";
Tianjie Xu52c678c2017-10-18 15:52:27 -070041constexpr char kMetricsUpdateEngineAttemptResult[] =
42 "ota_update_engine_attempt_result";
43constexpr char kMetricsUpdateEngineAttemptDurationInMinutes[] =
Tianjie Xu2a0ea632018-08-06 12:59:23 -070044 "ota_update_engine_attempt_fixed_duration_boottime_in_minutes";
Tianjie Xu52c678c2017-10-18 15:52:27 -070045constexpr char kMetricsUpdateEngineAttemptDurationUptimeInMinutes[] =
Tianjie Xu82d99102017-11-02 22:26:19 -070046 "ota_update_engine_attempt_duration_monotonic_in_minutes";
Tianjie Xu52c678c2017-10-18 15:52:27 -070047constexpr char kMetricsUpdateEngineAttemptErrorCode[] =
48 "ota_update_engine_attempt_error_code";
49constexpr char kMetricsUpdateEngineAttemptPayloadSizeMiB[] =
50 "ota_update_engine_attempt_payload_size_mib";
51constexpr char kMetricsUpdateEngineAttemptPayloadType[] =
52 "ota_update_engine_attempt_payload_type";
Tianjie Xu82d99102017-11-02 22:26:19 -070053constexpr char kMetricsUpdateEngineAttemptCurrentBytesDownloadedMiB[] =
Tianjie Xu2a0ea632018-08-06 12:59:23 -070054 "ota_update_engine_attempt_fixed_current_bytes_downloaded_mib";
Tianjie Xu52c678c2017-10-18 15:52:27 -070055
56constexpr char kMetricsUpdateEngineSuccessfulUpdateAttemptCount[] =
57 "ota_update_engine_successful_update_attempt_count";
58constexpr char kMetricsUpdateEngineSuccessfulUpdateTotalDurationInMinutes[] =
Tianjie Xu2a0ea632018-08-06 12:59:23 -070059 "ota_update_engine_successful_update_fixed_total_duration_in_minutes";
Tianjie Xu52c678c2017-10-18 15:52:27 -070060constexpr char kMetricsUpdateEngineSuccessfulUpdatePayloadSizeMiB[] =
61 "ota_update_engine_successful_update_payload_size_mib";
62constexpr char kMetricsUpdateEngineSuccessfulUpdatePayloadType[] =
63 "ota_update_engine_successful_update_payload_type";
64constexpr char kMetricsUpdateEngineSuccessfulUpdateRebootCount[] =
65 "ota_update_engine_successful_update_reboot_count";
Tianjie Xu82d99102017-11-02 22:26:19 -070066constexpr char kMetricsUpdateEngineSuccessfulUpdateTotalBytesDownloadedMiB[] =
67 "ota_update_engine_successful_update_total_bytes_downloaded_mib";
68constexpr char
69 kMetricsUpdateEngineSuccessfulUpdateDownloadOverheadPercentage[] =
70 "ota_update_engine_successful_update_download_overhead_percentage";
Tianjie Xud4c5deb2017-10-24 11:17:03 -070071
72std::unique_ptr<MetricsReporterInterface> CreateMetricsReporter() {
73 return std::make_unique<MetricsReporterAndroid>();
74}
75
Tianjie Xu1b661142017-09-28 14:03:42 -070076} // namespace metrics
77
78void MetricsReporterAndroid::ReportUpdateAttemptMetrics(
79 SystemState* /* system_state */,
Tianjie Xu52c678c2017-10-18 15:52:27 -070080 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 Xu1f93d092017-10-09 12:13:29 -070086 ErrorCode error_code) {
Tianjie Xu52c678c2017-10-18 15:52:27 -070087 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 Xu52c678c2017-10-18 15:52:27 -0700103}
104
Tianjie Xu82d99102017-11-02 22:26:19 -0700105void 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,
Tianjie Xu2a0ea632018-08-06 12:59:23 -0700112 payload_bytes_downloaded / kNumBytesInOneMiB);
Tianjie Xu82d99102017-11-02 22:26:19 -0700113}
114
Tianjie Xu52c678c2017-10-18 15:52:27 -0700115void MetricsReporterAndroid::ReportSuccessfulUpdateMetrics(
116 int attempt_count,
117 int /* updates_abandoned_count */,
118 PayloadType payload_type,
119 int64_t payload_size,
Tianjie Xu82d99102017-11-02 22:26:19 -0700120 int64_t num_bytes_downloaded[kNumDownloadSources],
121 int download_overhead_percentage,
Tianjie Xu52c678c2017-10-18 15:52:27 -0700122 base::TimeDelta total_duration,
Sen Jiang8712e962018-05-08 12:12:28 -0700123 base::TimeDelta /* total_duration_uptime */,
Tianjie Xu52c678c2017-10-18 15:52:27 -0700124 int reboot_count,
125 int /* url_switch_count */) {
Tianjie Xu52c678c2017-10-18 15:52:27 -0700126 LogHistogram(metrics::kMetricsUpdateEngineSuccessfulUpdateAttemptCount,
127 attempt_count);
128 LogHistogram(metrics::kMetricsUpdateEngineSuccessfulUpdatePayloadType,
129 static_cast<int>(payload_type));
130
131 int64_t payload_size_mib = payload_size / kNumBytesInOneMiB;
132 LogHistogram(metrics::kMetricsUpdateEngineSuccessfulUpdatePayloadSizeMiB,
133 payload_size_mib);
134
Tianjie Xu82d99102017-11-02 22:26:19 -0700135 int64_t total_bytes_downloaded = 0;
136 for (size_t i = 0; i < kNumDownloadSources; i++) {
137 total_bytes_downloaded += num_bytes_downloaded[i] / kNumBytesInOneMiB;
138 }
139 LogHistogram(
140 metrics::kMetricsUpdateEngineSuccessfulUpdateTotalBytesDownloadedMiB,
141 total_bytes_downloaded);
142 LogHistogram(
143 metrics::kMetricsUpdateEngineSuccessfulUpdateDownloadOverheadPercentage,
144 download_overhead_percentage);
145
Tianjie Xu52c678c2017-10-18 15:52:27 -0700146 LogHistogram(
147 metrics::kMetricsUpdateEngineSuccessfulUpdateTotalDurationInMinutes,
148 total_duration.InMinutes());
149 LogHistogram(metrics::kMetricsUpdateEngineSuccessfulUpdateRebootCount,
150 reboot_count);
Tianjie Xu52c678c2017-10-18 15:52:27 -0700151}
152
153void MetricsReporterAndroid::ReportAbnormallyTerminatedUpdateAttemptMetrics() {
Tianjie Xu52c678c2017-10-18 15:52:27 -0700154 int attempt_result =
155 static_cast<int>(metrics::AttemptResult::kAbnormalTermination);
156 LogHistogram(metrics::kMetricsUpdateEngineAttemptResult, attempt_result);
Tianjie Xu1b661142017-09-28 14:03:42 -0700157}
158
159}; // namespace chromeos_update_engine