blob: 5f24cbfea8ab027a45ad19e034d09d5eef8950e4 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2014 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//
David Zeuthen33bae492014-02-25 16:16:18 -080016
Tianjie Xu282aa1f2017-09-05 13:42:45 -070017#include "update_engine/metrics_reporter_omaha.h"
David Zeuthen33bae492014-02-25 16:16:18 -080018
Tianjie Xu98333a82017-09-22 21:29:29 -070019#include <memory>
David Zeuthen33bae492014-02-25 16:16:18 -080020#include <string>
21
22#include <base/logging.h>
Alex Deymoa2591792015-11-17 00:39:40 -030023#include <metrics/metrics_library.h>
David Zeuthen33bae492014-02-25 16:16:18 -080024
Alex Deymo39910dc2015-11-09 17:04:30 -080025#include "update_engine/common/clock_interface.h"
26#include "update_engine/common/constants.h"
27#include "update_engine/common/prefs_interface.h"
28#include "update_engine/common/utils.h"
Alex Deymoa2591792015-11-17 00:39:40 -030029#include "update_engine/metrics_utils.h"
David Zeuthen33bae492014-02-25 16:16:18 -080030#include "update_engine/system_state.h"
David Zeuthen33bae492014-02-25 16:16:18 -080031
32using std::string;
33
34namespace chromeos_update_engine {
35
Tianjie Xu98333a82017-09-22 21:29:29 -070036namespace metrics {
37
David Zeuthen33bae492014-02-25 16:16:18 -080038// UpdateEngine.Daily.* metrics.
Tianjie Xu98333a82017-09-22 21:29:29 -070039const char kMetricDailyOSAgeDays[] = "UpdateEngine.Daily.OSAgeDays";
David Zeuthen33bae492014-02-25 16:16:18 -080040
41// UpdateEngine.Check.* metrics.
Tianjie Xu98333a82017-09-22 21:29:29 -070042const char kMetricCheckDownloadErrorCode[] =
David Zeuthen33bae492014-02-25 16:16:18 -080043 "UpdateEngine.Check.DownloadErrorCode";
Tianjie Xu98333a82017-09-22 21:29:29 -070044const char kMetricCheckReaction[] = "UpdateEngine.Check.Reaction";
45const char kMetricCheckResult[] = "UpdateEngine.Check.Result";
46const char kMetricCheckTimeSinceLastCheckMinutes[] =
David Zeuthen33bae492014-02-25 16:16:18 -080047 "UpdateEngine.Check.TimeSinceLastCheckMinutes";
Tianjie Xu98333a82017-09-22 21:29:29 -070048const char kMetricCheckTimeSinceLastCheckUptimeMinutes[] =
David Zeuthen33bae492014-02-25 16:16:18 -080049 "UpdateEngine.Check.TimeSinceLastCheckUptimeMinutes";
50
51// UpdateEngine.Attempt.* metrics.
Tianjie Xu98333a82017-09-22 21:29:29 -070052const char kMetricAttemptNumber[] = "UpdateEngine.Attempt.Number";
53const char kMetricAttemptPayloadType[] = "UpdateEngine.Attempt.PayloadType";
54const char kMetricAttemptPayloadSizeMiB[] =
David Zeuthen33bae492014-02-25 16:16:18 -080055 "UpdateEngine.Attempt.PayloadSizeMiB";
Tianjie Xu98333a82017-09-22 21:29:29 -070056const char kMetricAttemptConnectionType[] =
David Zeuthenb281f072014-04-02 10:20:19 -070057 "UpdateEngine.Attempt.ConnectionType";
Tianjie Xu98333a82017-09-22 21:29:29 -070058const char kMetricAttemptDurationMinutes[] =
David Zeuthen33bae492014-02-25 16:16:18 -080059 "UpdateEngine.Attempt.DurationMinutes";
Tianjie Xu98333a82017-09-22 21:29:29 -070060const char kMetricAttemptDurationUptimeMinutes[] =
David Zeuthen33bae492014-02-25 16:16:18 -080061 "UpdateEngine.Attempt.DurationUptimeMinutes";
Tianjie Xu98333a82017-09-22 21:29:29 -070062const char kMetricAttemptTimeSinceLastAttemptMinutes[] =
David Zeuthen33bae492014-02-25 16:16:18 -080063 "UpdateEngine.Attempt.TimeSinceLastAttemptMinutes";
Tianjie Xu98333a82017-09-22 21:29:29 -070064const char kMetricAttemptTimeSinceLastAttemptUptimeMinutes[] =
David Zeuthen33bae492014-02-25 16:16:18 -080065 "UpdateEngine.Attempt.TimeSinceLastAttemptUptimeMinutes";
Tianjie Xu98333a82017-09-22 21:29:29 -070066const char kMetricAttemptPayloadBytesDownloadedMiB[] =
David Zeuthen33bae492014-02-25 16:16:18 -080067 "UpdateEngine.Attempt.PayloadBytesDownloadedMiB";
Tianjie Xu98333a82017-09-22 21:29:29 -070068const char kMetricAttemptPayloadDownloadSpeedKBps[] =
David Zeuthen33bae492014-02-25 16:16:18 -080069 "UpdateEngine.Attempt.PayloadDownloadSpeedKBps";
Tianjie Xu98333a82017-09-22 21:29:29 -070070const char kMetricAttemptDownloadSource[] =
David Zeuthen33bae492014-02-25 16:16:18 -080071 "UpdateEngine.Attempt.DownloadSource";
Tianjie Xu98333a82017-09-22 21:29:29 -070072const char kMetricAttemptResult[] = "UpdateEngine.Attempt.Result";
73const char kMetricAttemptInternalErrorCode[] =
David Zeuthen33bae492014-02-25 16:16:18 -080074 "UpdateEngine.Attempt.InternalErrorCode";
Tianjie Xu98333a82017-09-22 21:29:29 -070075const char kMetricAttemptDownloadErrorCode[] =
David Zeuthen33bae492014-02-25 16:16:18 -080076 "UpdateEngine.Attempt.DownloadErrorCode";
77
78// UpdateEngine.SuccessfulUpdate.* metrics.
Tianjie Xu98333a82017-09-22 21:29:29 -070079const char kMetricSuccessfulUpdateAttemptCount[] =
David Zeuthen33bae492014-02-25 16:16:18 -080080 "UpdateEngine.SuccessfulUpdate.AttemptCount";
Tianjie Xu98333a82017-09-22 21:29:29 -070081const char kMetricSuccessfulUpdateBytesDownloadedMiB[] =
David Zeuthen33bae492014-02-25 16:16:18 -080082 "UpdateEngine.SuccessfulUpdate.BytesDownloadedMiB";
Tianjie Xu98333a82017-09-22 21:29:29 -070083const char kMetricSuccessfulUpdateDownloadOverheadPercentage[] =
David Zeuthen33bae492014-02-25 16:16:18 -080084 "UpdateEngine.SuccessfulUpdate.DownloadOverheadPercentage";
Tianjie Xu98333a82017-09-22 21:29:29 -070085const char kMetricSuccessfulUpdateDownloadSourcesUsed[] =
David Zeuthen33bae492014-02-25 16:16:18 -080086 "UpdateEngine.SuccessfulUpdate.DownloadSourcesUsed";
Tianjie Xu98333a82017-09-22 21:29:29 -070087const char kMetricSuccessfulUpdatePayloadType[] =
David Zeuthen33bae492014-02-25 16:16:18 -080088 "UpdateEngine.SuccessfulUpdate.PayloadType";
Tianjie Xu98333a82017-09-22 21:29:29 -070089const char kMetricSuccessfulUpdatePayloadSizeMiB[] =
David Zeuthen33bae492014-02-25 16:16:18 -080090 "UpdateEngine.SuccessfulUpdate.PayloadSizeMiB";
Tianjie Xu98333a82017-09-22 21:29:29 -070091const char kMetricSuccessfulUpdateRebootCount[] =
David Zeuthen33bae492014-02-25 16:16:18 -080092 "UpdateEngine.SuccessfulUpdate.RebootCount";
Tianjie Xu98333a82017-09-22 21:29:29 -070093const char kMetricSuccessfulUpdateTotalDurationMinutes[] =
David Zeuthen33bae492014-02-25 16:16:18 -080094 "UpdateEngine.SuccessfulUpdate.TotalDurationMinutes";
Tianjie Xu98333a82017-09-22 21:29:29 -070095const char kMetricSuccessfulUpdateUpdatesAbandonedCount[] =
David Zeuthen33bae492014-02-25 16:16:18 -080096 "UpdateEngine.SuccessfulUpdate.UpdatesAbandonedCount";
Tianjie Xu98333a82017-09-22 21:29:29 -070097const char kMetricSuccessfulUpdateUrlSwitchCount[] =
David Zeuthen33bae492014-02-25 16:16:18 -080098 "UpdateEngine.SuccessfulUpdate.UrlSwitchCount";
99
David Zeuthen96197df2014-04-16 12:22:39 -0700100// UpdateEngine.Rollback.* metric.
Tianjie Xu98333a82017-09-22 21:29:29 -0700101const char kMetricRollbackResult[] = "UpdateEngine.Rollback.Result";
David Zeuthen96197df2014-04-16 12:22:39 -0700102
Alex Deymoc1c17b42015-11-23 03:53:15 -0300103// UpdateEngine.CertificateCheck.* metrics.
Tianjie Xu98333a82017-09-22 21:29:29 -0700104const char kMetricCertificateCheckUpdateCheck[] =
Alex Deymoc1c17b42015-11-23 03:53:15 -0300105 "UpdateEngine.CertificateCheck.UpdateCheck";
Tianjie Xu98333a82017-09-22 21:29:29 -0700106const char kMetricCertificateCheckDownload[] =
Alex Deymoc1c17b42015-11-23 03:53:15 -0300107 "UpdateEngine.CertificateCheck.Download";
108
David Zeuthen33bae492014-02-25 16:16:18 -0800109// UpdateEngine.* metrics.
Tianjie Xu98333a82017-09-22 21:29:29 -0700110const char kMetricFailedUpdateCount[] = "UpdateEngine.FailedUpdateCount";
111const char kMetricInstallDateProvisioningSource[] =
David Zeuthen33bae492014-02-25 16:16:18 -0800112 "UpdateEngine.InstallDateProvisioningSource";
Tianjie Xu98333a82017-09-22 21:29:29 -0700113const char kMetricTimeToRebootMinutes[] = "UpdateEngine.TimeToRebootMinutes";
114
115} // namespace metrics
116
117MetricsReporterOmaha::MetricsReporterOmaha()
118 : metrics_lib_(new MetricsLibrary()) {}
David Zeuthen33bae492014-02-25 16:16:18 -0800119
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700120void MetricsReporterOmaha::Initialize() {
Tianjie Xu98333a82017-09-22 21:29:29 -0700121 metrics_lib_->Init();
David Zeuthen33bae492014-02-25 16:16:18 -0800122}
123
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700124void MetricsReporterOmaha::ReportDailyMetrics(base::TimeDelta os_age) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700125 string metric = metrics::kMetricDailyOSAgeDays;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700126 LOG(INFO) << "Uploading " << utils::FormatTimeDelta(os_age) << " for metric "
127 << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700128 metrics_lib_->SendToUMA(metric,
129 static_cast<int>(os_age.InDays()),
130 0, // min: 0 days
131 6 * 30, // max: 6 months (approx)
132 50); // num_buckets
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700133}
134
135void MetricsReporterOmaha::ReportUpdateCheckMetrics(
136 SystemState* system_state,
137 metrics::CheckResult result,
138 metrics::CheckReaction reaction,
139 metrics::DownloadErrorCode download_error_code) {
David Zeuthen33bae492014-02-25 16:16:18 -0800140 string metric;
141 int value;
142 int max_value;
143
144 if (result != metrics::CheckResult::kUnset) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700145 metric = metrics::kMetricCheckResult;
David Zeuthen33bae492014-02-25 16:16:18 -0800146 value = static_cast<int>(result);
147 max_value = static_cast<int>(metrics::CheckResult::kNumConstants) - 1;
148 LOG(INFO) << "Sending " << value << " for metric " << metric << " (enum)";
Tianjie Xu98333a82017-09-22 21:29:29 -0700149 metrics_lib_->SendEnumToUMA(metric, value, max_value);
David Zeuthen33bae492014-02-25 16:16:18 -0800150 }
151 if (reaction != metrics::CheckReaction::kUnset) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700152 metric = metrics::kMetricCheckReaction;
David Zeuthen33bae492014-02-25 16:16:18 -0800153 value = static_cast<int>(reaction);
154 max_value = static_cast<int>(metrics::CheckReaction::kNumConstants) - 1;
155 LOG(INFO) << "Sending " << value << " for metric " << metric << " (enum)";
Tianjie Xu98333a82017-09-22 21:29:29 -0700156 metrics_lib_->SendEnumToUMA(metric, value, max_value);
David Zeuthen33bae492014-02-25 16:16:18 -0800157 }
158 if (download_error_code != metrics::DownloadErrorCode::kUnset) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700159 metric = metrics::kMetricCheckDownloadErrorCode;
David Zeuthen33bae492014-02-25 16:16:18 -0800160 value = static_cast<int>(download_error_code);
David Zeuthenc0dd0212014-04-04 14:49:49 -0700161 LOG(INFO) << "Sending " << value << " for metric " << metric << " (sparse)";
Tianjie Xu98333a82017-09-22 21:29:29 -0700162 metrics_lib_->SendSparseToUMA(metric, value);
David Zeuthen33bae492014-02-25 16:16:18 -0800163 }
164
165 base::TimeDelta time_since_last;
Alex Deymoa2591792015-11-17 00:39:40 -0300166 if (metrics_utils::WallclockDurationHelper(
167 system_state,
168 kPrefsMetricsCheckLastReportingTime,
169 &time_since_last)) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700170 metric = metrics::kMetricCheckTimeSinceLastCheckMinutes;
David Zeuthen33bae492014-02-25 16:16:18 -0800171 LOG(INFO) << "Sending " << utils::FormatTimeDelta(time_since_last)
172 << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700173 metrics_lib_->SendToUMA(metric,
174 time_since_last.InMinutes(),
175 0, // min: 0 min
176 30 * 24 * 60, // max: 30 days
177 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800178 }
179
180 base::TimeDelta uptime_since_last;
181 static int64_t uptime_since_last_storage = 0;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700182 if (metrics_utils::MonotonicDurationHelper(
183 system_state, &uptime_since_last_storage, &uptime_since_last)) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700184 metric = metrics::kMetricCheckTimeSinceLastCheckUptimeMinutes;
David Zeuthen33bae492014-02-25 16:16:18 -0800185 LOG(INFO) << "Sending " << utils::FormatTimeDelta(uptime_since_last)
186 << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700187 metrics_lib_->SendToUMA(metric,
188 uptime_since_last.InMinutes(),
189 0, // min: 0 min
190 30 * 24 * 60, // max: 30 days
191 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800192 }
193}
194
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700195void MetricsReporterOmaha::ReportAbnormallyTerminatedUpdateAttemptMetrics() {
Tianjie Xu98333a82017-09-22 21:29:29 -0700196 string metric = metrics::kMetricAttemptResult;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700197 metrics::AttemptResult attempt_result =
198 metrics::AttemptResult::kAbnormalTermination;
David Zeuthen4e1d1492014-04-25 13:12:27 -0700199
200 LOG(INFO) << "Uploading " << static_cast<int>(attempt_result)
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700201 << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700202 metrics_lib_->SendEnumToUMA(
David Zeuthen4e1d1492014-04-25 13:12:27 -0700203 metric,
204 static_cast<int>(attempt_result),
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700205 static_cast<int>(metrics::AttemptResult::kNumConstants));
David Zeuthen4e1d1492014-04-25 13:12:27 -0700206}
207
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700208void MetricsReporterOmaha::ReportUpdateAttemptMetrics(
209 SystemState* system_state,
David Zeuthen33bae492014-02-25 16:16:18 -0800210 int attempt_number,
211 PayloadType payload_type,
212 base::TimeDelta duration,
213 base::TimeDelta duration_uptime,
214 int64_t payload_size,
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700215 metrics::AttemptResult attempt_result,
Tianjie Xu1f93d092017-10-09 12:13:29 -0700216 ErrorCode internal_error_code) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700217 string metric = metrics::kMetricAttemptNumber;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700218 LOG(INFO) << "Uploading " << attempt_number << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700219 metrics_lib_->SendToUMA(metric,
220 attempt_number,
221 0, // min: 0 attempts
222 49, // max: 49 attempts
223 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800224
Tianjie Xu98333a82017-09-22 21:29:29 -0700225 metric = metrics::kMetricAttemptPayloadType;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700226 LOG(INFO) << "Uploading " << utils::ToString(payload_type) << " for metric "
227 << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700228 metrics_lib_->SendEnumToUMA(metric, payload_type, kNumPayloadTypes);
David Zeuthen33bae492014-02-25 16:16:18 -0800229
Tianjie Xu98333a82017-09-22 21:29:29 -0700230 metric = metrics::kMetricAttemptDurationMinutes;
David Zeuthen33bae492014-02-25 16:16:18 -0800231 LOG(INFO) << "Uploading " << utils::FormatTimeDelta(duration)
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700232 << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700233 metrics_lib_->SendToUMA(metric,
234 duration.InMinutes(),
235 0, // min: 0 min
236 10 * 24 * 60, // max: 10 days
237 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800238
Tianjie Xu98333a82017-09-22 21:29:29 -0700239 metric = metrics::kMetricAttemptDurationUptimeMinutes;
David Zeuthen33bae492014-02-25 16:16:18 -0800240 LOG(INFO) << "Uploading " << utils::FormatTimeDelta(duration_uptime)
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700241 << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700242 metrics_lib_->SendToUMA(metric,
243 duration_uptime.InMinutes(),
244 0, // min: 0 min
245 10 * 24 * 60, // max: 10 days
246 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800247
Tianjie Xu98333a82017-09-22 21:29:29 -0700248 metric = metrics::kMetricAttemptPayloadSizeMiB;
David Zeuthen33bae492014-02-25 16:16:18 -0800249 int64_t payload_size_mib = payload_size / kNumBytesInOneMiB;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700250 LOG(INFO) << "Uploading " << payload_size_mib << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700251 metrics_lib_->SendToUMA(metric,
252 payload_size_mib,
253 0, // min: 0 MiB
254 1024, // max: 1024 MiB = 1 GiB
255 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800256
David Zeuthen33bae492014-02-25 16:16:18 -0800257
David Zeuthen33bae492014-02-25 16:16:18 -0800258
Tianjie Xu98333a82017-09-22 21:29:29 -0700259 metric = metrics::kMetricAttemptResult;
David Zeuthen33bae492014-02-25 16:16:18 -0800260 LOG(INFO) << "Uploading " << static_cast<int>(attempt_result)
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700261 << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700262 metrics_lib_->SendEnumToUMA(
David Zeuthen33bae492014-02-25 16:16:18 -0800263 metric,
264 static_cast<int>(attempt_result),
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700265 static_cast<int>(metrics::AttemptResult::kNumConstants));
David Zeuthen33bae492014-02-25 16:16:18 -0800266
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700267 if (internal_error_code != ErrorCode::kSuccess) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700268 metric = metrics::kMetricAttemptInternalErrorCode;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700269 LOG(INFO) << "Uploading " << internal_error_code << " for metric "
270 << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700271 metrics_lib_->SendEnumToUMA(metric,
272 static_cast<int>(internal_error_code),
273 static_cast<int>(ErrorCode::kUmaReportedMax));
David Zeuthen33bae492014-02-25 16:16:18 -0800274 }
275
David Zeuthen33bae492014-02-25 16:16:18 -0800276 base::TimeDelta time_since_last;
Alex Deymoa2591792015-11-17 00:39:40 -0300277 if (metrics_utils::WallclockDurationHelper(
278 system_state,
279 kPrefsMetricsAttemptLastReportingTime,
280 &time_since_last)) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700281 metric = metrics::kMetricAttemptTimeSinceLastAttemptMinutes;
David Zeuthen33bae492014-02-25 16:16:18 -0800282 LOG(INFO) << "Sending " << utils::FormatTimeDelta(time_since_last)
283 << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700284 metrics_lib_->SendToUMA(metric,
285 time_since_last.InMinutes(),
286 0, // min: 0 min
287 30 * 24 * 60, // max: 30 days
288 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800289 }
290
291 static int64_t uptime_since_last_storage = 0;
292 base::TimeDelta uptime_since_last;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700293 if (metrics_utils::MonotonicDurationHelper(
294 system_state, &uptime_since_last_storage, &uptime_since_last)) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700295 metric = metrics::kMetricAttemptTimeSinceLastAttemptUptimeMinutes;
David Zeuthen33bae492014-02-25 16:16:18 -0800296 LOG(INFO) << "Sending " << utils::FormatTimeDelta(uptime_since_last)
297 << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700298 metrics_lib_->SendToUMA(metric,
299 uptime_since_last.InMinutes(),
300 0, // min: 0 min
301 30 * 24 * 60, // max: 30 days
302 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800303 }
Tianjie Xu1f93d092017-10-09 12:13:29 -0700304}
305
306void MetricsReporterOmaha::ReportUpdateAttemptDownloadMetrics(
307 int64_t payload_bytes_downloaded,
308 int64_t payload_download_speed_bps,
309 DownloadSource download_source,
310 metrics::DownloadErrorCode payload_download_error_code,
311 metrics::ConnectionType connection_type) {
312 string metric = metrics::kMetricAttemptPayloadBytesDownloadedMiB;
313 int64_t payload_bytes_downloaded_mib =
314 payload_bytes_downloaded / kNumBytesInOneMiB;
315 LOG(INFO) << "Uploading " << payload_bytes_downloaded_mib << " for metric "
316 << metric;
317 metrics_lib_->SendToUMA(metric,
318 payload_bytes_downloaded_mib,
319 0, // min: 0 MiB
320 1024, // max: 1024 MiB = 1 GiB
321 50); // num_buckets
322
323 metric = metrics::kMetricAttemptPayloadDownloadSpeedKBps;
324 int64_t payload_download_speed_kbps = payload_download_speed_bps / 1000;
325 LOG(INFO) << "Uploading " << payload_download_speed_kbps << " for metric "
326 << metric;
327 metrics_lib_->SendToUMA(metric,
328 payload_download_speed_kbps,
329 0, // min: 0 kB/s
330 10 * 1000, // max: 10000 kB/s = 10 MB/s
331 50); // num_buckets
332
333 metric = metrics::kMetricAttemptDownloadSource;
334 LOG(INFO) << "Uploading " << download_source << " for metric " << metric;
335 metrics_lib_->SendEnumToUMA(metric, download_source, kNumDownloadSources);
336
337 if (payload_download_error_code != metrics::DownloadErrorCode::kUnset) {
338 metric = metrics::kMetricAttemptDownloadErrorCode;
339 LOG(INFO) << "Uploading " << static_cast<int>(payload_download_error_code)
340 << " for metric " << metric << " (sparse)";
341 metrics_lib_->SendSparseToUMA(
342 metric, static_cast<int>(payload_download_error_code));
343 }
David Zeuthenb281f072014-04-02 10:20:19 -0700344
Tianjie Xu98333a82017-09-22 21:29:29 -0700345 metric = metrics::kMetricAttemptConnectionType;
David Zeuthenb281f072014-04-02 10:20:19 -0700346 LOG(INFO) << "Uploading " << static_cast<int>(connection_type)
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700347 << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700348 metrics_lib_->SendEnumToUMA(
David Zeuthenb281f072014-04-02 10:20:19 -0700349 metric,
350 static_cast<int>(connection_type),
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700351 static_cast<int>(metrics::ConnectionType::kNumConstants));
David Zeuthen33bae492014-02-25 16:16:18 -0800352}
353
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700354void MetricsReporterOmaha::ReportSuccessfulUpdateMetrics(
355 int attempt_count,
356 int updates_abandoned_count,
357 PayloadType payload_type,
358 int64_t payload_size,
359 int64_t num_bytes_downloaded[kNumDownloadSources],
360 int download_overhead_percentage,
361 base::TimeDelta total_duration,
362 int reboot_count,
363 int url_switch_count) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700364 string metric = metrics::kMetricSuccessfulUpdatePayloadSizeMiB;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700365 int64_t mbs = payload_size / kNumBytesInOneMiB;
David Zeuthen33bae492014-02-25 16:16:18 -0800366 LOG(INFO) << "Uploading " << mbs << " (MiBs) for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700367 metrics_lib_->SendToUMA(metric,
368 mbs,
369 0, // min: 0 MiB
370 1024, // max: 1024 MiB = 1 GiB
371 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800372
373 int64_t total_bytes = 0;
374 int download_sources_used = 0;
375 for (int i = 0; i < kNumDownloadSources + 1; i++) {
376 DownloadSource source = static_cast<DownloadSource>(i);
377
378 // Only consider this download source (and send byte counts) as
379 // having been used if we downloaded a non-trivial amount of bytes
Alex Vakulenko072359c2014-07-18 11:41:07 -0700380 // (e.g. at least 1 MiB) that contributed to the
David Zeuthen33bae492014-02-25 16:16:18 -0800381 // update. Otherwise we're going to end up with a lot of zero-byte
382 // events in the histogram.
383
Tianjie Xu98333a82017-09-22 21:29:29 -0700384 metric = metrics::kMetricSuccessfulUpdateBytesDownloadedMiB;
David Zeuthen33bae492014-02-25 16:16:18 -0800385 if (i < kNumDownloadSources) {
386 metric += utils::ToString(source);
387 mbs = num_bytes_downloaded[i] / kNumBytesInOneMiB;
388 total_bytes += num_bytes_downloaded[i];
389 if (mbs > 0)
390 download_sources_used |= (1 << i);
391 } else {
392 mbs = total_bytes / kNumBytesInOneMiB;
393 }
394
395 if (mbs > 0) {
396 LOG(INFO) << "Uploading " << mbs << " (MiBs) for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700397 metrics_lib_->SendToUMA(metric,
398 mbs,
399 0, // min: 0 MiB
400 1024, // max: 1024 MiB = 1 GiB
401 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800402 }
403 }
404
Tianjie Xu98333a82017-09-22 21:29:29 -0700405 metric = metrics::kMetricSuccessfulUpdateDownloadSourcesUsed;
David Zeuthen33bae492014-02-25 16:16:18 -0800406 LOG(INFO) << "Uploading 0x" << std::hex << download_sources_used
407 << " (bit flags) for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700408 metrics_lib_->SendToUMA(metric,
409 download_sources_used,
410 0, // min
411 (1 << kNumDownloadSources) - 1, // max
412 1 << kNumDownloadSources); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800413
Tianjie Xu98333a82017-09-22 21:29:29 -0700414 metric = metrics::kMetricSuccessfulUpdateDownloadOverheadPercentage;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700415 LOG(INFO) << "Uploading " << download_overhead_percentage << "% for metric "
416 << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700417 metrics_lib_->SendToUMA(metric,
418 download_overhead_percentage,
419 0, // min: 0% overhead
420 1000, // max: 1000% overhead
421 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800422
Tianjie Xu98333a82017-09-22 21:29:29 -0700423 metric = metrics::kMetricSuccessfulUpdateUrlSwitchCount;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700424 LOG(INFO) << "Uploading " << url_switch_count << " (count) for metric "
425 << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700426 metrics_lib_->SendToUMA(metric,
427 url_switch_count,
428 0, // min: 0 URL switches
429 49, // max: 49 URL switches
430 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800431
Tianjie Xu98333a82017-09-22 21:29:29 -0700432 metric = metrics::kMetricSuccessfulUpdateTotalDurationMinutes;
David Zeuthen33bae492014-02-25 16:16:18 -0800433 LOG(INFO) << "Uploading " << utils::FormatTimeDelta(total_duration)
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700434 << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700435 metrics_lib_->SendToUMA(metric,
436 static_cast<int>(total_duration.InMinutes()),
437 0, // min: 0 min
438 365 * 24 * 60, // max: 365 days ~= 1 year
439 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800440
Tianjie Xu98333a82017-09-22 21:29:29 -0700441 metric = metrics::kMetricSuccessfulUpdateRebootCount;
David Zeuthen33bae492014-02-25 16:16:18 -0800442 LOG(INFO) << "Uploading reboot count of " << reboot_count << " for metric "
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700443 << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700444 metrics_lib_->SendToUMA(metric,
445 reboot_count,
446 0, // min: 0 reboots
447 49, // max: 49 reboots
448 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800449
Tianjie Xu98333a82017-09-22 21:29:29 -0700450 metric = metrics::kMetricSuccessfulUpdatePayloadType;
451 metrics_lib_->SendEnumToUMA(metric, payload_type, kNumPayloadTypes);
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700452 LOG(INFO) << "Uploading " << utils::ToString(payload_type) << " for metric "
453 << metric;
David Zeuthen33bae492014-02-25 16:16:18 -0800454
Tianjie Xu98333a82017-09-22 21:29:29 -0700455 metric = metrics::kMetricSuccessfulUpdateAttemptCount;
456 metrics_lib_->SendToUMA(metric,
457 attempt_count,
458 1, // min: 1 attempt
459 50, // max: 50 attempts
460 50); // num_buckets
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700461 LOG(INFO) << "Uploading " << attempt_count << " for metric " << metric;
David Zeuthen33bae492014-02-25 16:16:18 -0800462
Tianjie Xu98333a82017-09-22 21:29:29 -0700463 metric = metrics::kMetricSuccessfulUpdateUpdatesAbandonedCount;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700464 LOG(INFO) << "Uploading " << updates_abandoned_count << " (count) for metric "
465 << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700466 metrics_lib_->SendToUMA(metric,
467 updates_abandoned_count,
468 0, // min: 0 counts
469 49, // max: 49 counts
470 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800471}
472
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700473void MetricsReporterOmaha::ReportRollbackMetrics(
474 metrics::RollbackResult result) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700475 string metric = metrics::kMetricRollbackResult;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700476 int value = static_cast<int>(result);
David Zeuthen96197df2014-04-16 12:22:39 -0700477 LOG(INFO) << "Sending " << value << " for metric " << metric << " (enum)";
Tianjie Xu98333a82017-09-22 21:29:29 -0700478 metrics_lib_->SendEnumToUMA(
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700479 metric, value, static_cast<int>(metrics::RollbackResult::kNumConstants));
David Zeuthen96197df2014-04-16 12:22:39 -0700480}
481
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700482void MetricsReporterOmaha::ReportCertificateCheckMetrics(
483 ServerToCheck server_to_check, CertificateCheckResult result) {
Alex Deymoc1c17b42015-11-23 03:53:15 -0300484 string metric;
485 switch (server_to_check) {
486 case ServerToCheck::kUpdate:
Tianjie Xu98333a82017-09-22 21:29:29 -0700487 metric = metrics::kMetricCertificateCheckUpdateCheck;
Alex Deymoc1c17b42015-11-23 03:53:15 -0300488 break;
489 case ServerToCheck::kDownload:
Tianjie Xu98333a82017-09-22 21:29:29 -0700490 metric = metrics::kMetricCertificateCheckDownload;
Alex Deymoc1c17b42015-11-23 03:53:15 -0300491 break;
Alex Deymo33e91e72015-12-01 18:26:08 -0300492 case ServerToCheck::kNone:
493 return;
Alex Deymoc1c17b42015-11-23 03:53:15 -0300494 }
495 LOG(INFO) << "Uploading " << static_cast<int>(result) << " for metric "
496 << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700497 metrics_lib_->SendEnumToUMA(
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700498 metric,
499 static_cast<int>(result),
Alex Deymoc1c17b42015-11-23 03:53:15 -0300500 static_cast<int>(CertificateCheckResult::kNumConstants));
501}
502
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700503void MetricsReporterOmaha::ReportFailedUpdateCount(int target_attempt) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700504 string metric = metrics::kMetricFailedUpdateCount;
505 metrics_lib_->SendToUMA(metric,
506 target_attempt,
507 1, // min value
508 50, // max value
509 kNumDefaultUmaBuckets);
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700510
511 LOG(INFO) << "Uploading " << target_attempt << " (count) for metric "
512 << metric;
513}
514
515void MetricsReporterOmaha::ReportTimeToReboot(int time_to_reboot_minutes) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700516 string metric = metrics::kMetricTimeToRebootMinutes;
517 metrics_lib_->SendToUMA(metric,
518 time_to_reboot_minutes,
519 0, // min: 0 minute
520 30 * 24 * 60, // max: 1 month (approx)
521 kNumDefaultUmaBuckets);
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700522
523 LOG(INFO) << "Uploading " << time_to_reboot_minutes << " for metric "
524 << metric;
525}
526
527void MetricsReporterOmaha::ReportInstallDateProvisioningSource(int source,
528 int max) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700529 metrics_lib_->SendEnumToUMA(metrics::kMetricInstallDateProvisioningSource,
530 source, // Sample.
531 max);
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700532}
David Zeuthen33bae492014-02-25 16:16:18 -0800533
534} // namespace chromeos_update_engine