blob: 869c4db6a7e10b55fabbdff39e0401af28aeeb14 [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);
29 LOG(INFO) << "uploading " << value << "to histogram for metric " << metrics;
30}
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[] =
40 "ota_update_engine_attempt_count";
41constexpr char kMetricsUpdateEngineAttemptResult[] =
42 "ota_update_engine_attempt_result";
43constexpr char kMetricsUpdateEngineAttemptDurationInMinutes[] =
44 "ota_update_engine_attempt_duration_in_minutes";
45constexpr char kMetricsUpdateEngineAttemptDurationUptimeInMinutes[] =
46 "ota_update_engine_attempt_duration_uptime_in_minutes";
47constexpr 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";
53
54constexpr char kMetricsUpdateEngineSuccessfulUpdateAttemptCount[] =
55 "ota_update_engine_successful_update_attempt_count";
56constexpr char kMetricsUpdateEngineSuccessfulUpdateTotalDurationInMinutes[] =
57 "ota_update_engine_successful_update_total_duration_in_minutes";
58constexpr char kMetricsUpdateEngineSuccessfulUpdatePayloadSizeMiB[] =
59 "ota_update_engine_successful_update_payload_size_mib";
60constexpr char kMetricsUpdateEngineSuccessfulUpdatePayloadType[] =
61 "ota_update_engine_successful_update_payload_type";
62constexpr char kMetricsUpdateEngineSuccessfulUpdateRebootCount[] =
63 "ota_update_engine_successful_update_reboot_count";
Tianjie Xud4c5deb2017-10-24 11:17:03 -070064
65std::unique_ptr<MetricsReporterInterface> CreateMetricsReporter() {
66 return std::make_unique<MetricsReporterAndroid>();
67}
68
Tianjie Xu1b661142017-09-28 14:03:42 -070069} // namespace metrics
70
71void MetricsReporterAndroid::ReportUpdateAttemptMetrics(
72 SystemState* /* system_state */,
Tianjie Xu52c678c2017-10-18 15:52:27 -070073 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 Xu1f93d092017-10-09 12:13:29 -070079 ErrorCode error_code) {
Tianjie Xu52c678c2017-10-18 15:52:27 -070080 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 Xu52c678c2017-10-18 15:52:27 -070096}
97
98void 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 Xu52c678c2017-10-18 15:52:27 -0700108 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 Xu52c678c2017-10-18 15:52:27 -0700122}
123
124void MetricsReporterAndroid::ReportAbnormallyTerminatedUpdateAttemptMetrics() {
Tianjie Xu52c678c2017-10-18 15:52:27 -0700125 int attempt_result =
126 static_cast<int>(metrics::AttemptResult::kAbnormalTermination);
127 LogHistogram(metrics::kMetricsUpdateEngineAttemptResult, attempt_result);
Tianjie Xu1b661142017-09-28 14:03:42 -0700128}
129
130}; // namespace chromeos_update_engine