blob: df3e4d4f8fd04573d0239d4b532d9c4711a2a5e5 [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";
Sen Jiang8712e962018-05-08 12:12:28 -070095const char kMetricSuccessfulUpdateTotalDurationUptimeMinutes[] =
96 "UpdateEngine.SuccessfulUpdate.TotalDurationUptimeMinutes";
Tianjie Xu98333a82017-09-22 21:29:29 -070097const char kMetricSuccessfulUpdateUpdatesAbandonedCount[] =
David Zeuthen33bae492014-02-25 16:16:18 -080098 "UpdateEngine.SuccessfulUpdate.UpdatesAbandonedCount";
Tianjie Xu98333a82017-09-22 21:29:29 -070099const char kMetricSuccessfulUpdateUrlSwitchCount[] =
David Zeuthen33bae492014-02-25 16:16:18 -0800100 "UpdateEngine.SuccessfulUpdate.UrlSwitchCount";
101
David Zeuthen96197df2014-04-16 12:22:39 -0700102// UpdateEngine.Rollback.* metric.
Tianjie Xu98333a82017-09-22 21:29:29 -0700103const char kMetricRollbackResult[] = "UpdateEngine.Rollback.Result";
David Zeuthen96197df2014-04-16 12:22:39 -0700104
Alex Deymoc1c17b42015-11-23 03:53:15 -0300105// UpdateEngine.CertificateCheck.* metrics.
Tianjie Xu98333a82017-09-22 21:29:29 -0700106const char kMetricCertificateCheckUpdateCheck[] =
Alex Deymoc1c17b42015-11-23 03:53:15 -0300107 "UpdateEngine.CertificateCheck.UpdateCheck";
Tianjie Xu98333a82017-09-22 21:29:29 -0700108const char kMetricCertificateCheckDownload[] =
Alex Deymoc1c17b42015-11-23 03:53:15 -0300109 "UpdateEngine.CertificateCheck.Download";
110
David Zeuthen33bae492014-02-25 16:16:18 -0800111// UpdateEngine.* metrics.
Tianjie Xu98333a82017-09-22 21:29:29 -0700112const char kMetricFailedUpdateCount[] = "UpdateEngine.FailedUpdateCount";
113const char kMetricInstallDateProvisioningSource[] =
David Zeuthen33bae492014-02-25 16:16:18 -0800114 "UpdateEngine.InstallDateProvisioningSource";
Tianjie Xu98333a82017-09-22 21:29:29 -0700115const char kMetricTimeToRebootMinutes[] = "UpdateEngine.TimeToRebootMinutes";
116
Tianjie Xud4c5deb2017-10-24 11:17:03 -0700117std::unique_ptr<MetricsReporterInterface> CreateMetricsReporter() {
118 return std::make_unique<MetricsReporterOmaha>();
119}
120
Tianjie Xu98333a82017-09-22 21:29:29 -0700121} // namespace metrics
122
123MetricsReporterOmaha::MetricsReporterOmaha()
124 : metrics_lib_(new MetricsLibrary()) {}
David Zeuthen33bae492014-02-25 16:16:18 -0800125
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700126void MetricsReporterOmaha::Initialize() {
Tianjie Xu98333a82017-09-22 21:29:29 -0700127 metrics_lib_->Init();
David Zeuthen33bae492014-02-25 16:16:18 -0800128}
129
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700130void MetricsReporterOmaha::ReportDailyMetrics(base::TimeDelta os_age) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700131 string metric = metrics::kMetricDailyOSAgeDays;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700132 LOG(INFO) << "Uploading " << utils::FormatTimeDelta(os_age) << " for metric "
133 << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700134 metrics_lib_->SendToUMA(metric,
135 static_cast<int>(os_age.InDays()),
136 0, // min: 0 days
137 6 * 30, // max: 6 months (approx)
138 50); // num_buckets
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700139}
140
141void MetricsReporterOmaha::ReportUpdateCheckMetrics(
142 SystemState* system_state,
143 metrics::CheckResult result,
144 metrics::CheckReaction reaction,
145 metrics::DownloadErrorCode download_error_code) {
David Zeuthen33bae492014-02-25 16:16:18 -0800146 string metric;
147 int value;
148 int max_value;
149
150 if (result != metrics::CheckResult::kUnset) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700151 metric = metrics::kMetricCheckResult;
David Zeuthen33bae492014-02-25 16:16:18 -0800152 value = static_cast<int>(result);
153 max_value = static_cast<int>(metrics::CheckResult::kNumConstants) - 1;
154 LOG(INFO) << "Sending " << value << " for metric " << metric << " (enum)";
Tianjie Xu98333a82017-09-22 21:29:29 -0700155 metrics_lib_->SendEnumToUMA(metric, value, max_value);
David Zeuthen33bae492014-02-25 16:16:18 -0800156 }
157 if (reaction != metrics::CheckReaction::kUnset) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700158 metric = metrics::kMetricCheckReaction;
David Zeuthen33bae492014-02-25 16:16:18 -0800159 value = static_cast<int>(reaction);
160 max_value = static_cast<int>(metrics::CheckReaction::kNumConstants) - 1;
161 LOG(INFO) << "Sending " << value << " for metric " << metric << " (enum)";
Tianjie Xu98333a82017-09-22 21:29:29 -0700162 metrics_lib_->SendEnumToUMA(metric, value, max_value);
David Zeuthen33bae492014-02-25 16:16:18 -0800163 }
164 if (download_error_code != metrics::DownloadErrorCode::kUnset) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700165 metric = metrics::kMetricCheckDownloadErrorCode;
David Zeuthen33bae492014-02-25 16:16:18 -0800166 value = static_cast<int>(download_error_code);
David Zeuthenc0dd0212014-04-04 14:49:49 -0700167 LOG(INFO) << "Sending " << value << " for metric " << metric << " (sparse)";
Tianjie Xu98333a82017-09-22 21:29:29 -0700168 metrics_lib_->SendSparseToUMA(metric, value);
David Zeuthen33bae492014-02-25 16:16:18 -0800169 }
170
171 base::TimeDelta time_since_last;
Alex Deymoa2591792015-11-17 00:39:40 -0300172 if (metrics_utils::WallclockDurationHelper(
173 system_state,
174 kPrefsMetricsCheckLastReportingTime,
175 &time_since_last)) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700176 metric = metrics::kMetricCheckTimeSinceLastCheckMinutes;
David Zeuthen33bae492014-02-25 16:16:18 -0800177 LOG(INFO) << "Sending " << utils::FormatTimeDelta(time_since_last)
178 << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700179 metrics_lib_->SendToUMA(metric,
180 time_since_last.InMinutes(),
181 0, // min: 0 min
182 30 * 24 * 60, // max: 30 days
183 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800184 }
185
186 base::TimeDelta uptime_since_last;
187 static int64_t uptime_since_last_storage = 0;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700188 if (metrics_utils::MonotonicDurationHelper(
189 system_state, &uptime_since_last_storage, &uptime_since_last)) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700190 metric = metrics::kMetricCheckTimeSinceLastCheckUptimeMinutes;
David Zeuthen33bae492014-02-25 16:16:18 -0800191 LOG(INFO) << "Sending " << utils::FormatTimeDelta(uptime_since_last)
192 << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700193 metrics_lib_->SendToUMA(metric,
194 uptime_since_last.InMinutes(),
195 0, // min: 0 min
196 30 * 24 * 60, // max: 30 days
197 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800198 }
199}
200
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700201void MetricsReporterOmaha::ReportAbnormallyTerminatedUpdateAttemptMetrics() {
Tianjie Xu98333a82017-09-22 21:29:29 -0700202 string metric = metrics::kMetricAttemptResult;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700203 metrics::AttemptResult attempt_result =
204 metrics::AttemptResult::kAbnormalTermination;
David Zeuthen4e1d1492014-04-25 13:12:27 -0700205
206 LOG(INFO) << "Uploading " << static_cast<int>(attempt_result)
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700207 << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700208 metrics_lib_->SendEnumToUMA(
David Zeuthen4e1d1492014-04-25 13:12:27 -0700209 metric,
210 static_cast<int>(attempt_result),
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700211 static_cast<int>(metrics::AttemptResult::kNumConstants));
David Zeuthen4e1d1492014-04-25 13:12:27 -0700212}
213
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700214void MetricsReporterOmaha::ReportUpdateAttemptMetrics(
215 SystemState* system_state,
David Zeuthen33bae492014-02-25 16:16:18 -0800216 int attempt_number,
217 PayloadType payload_type,
218 base::TimeDelta duration,
219 base::TimeDelta duration_uptime,
220 int64_t payload_size,
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700221 metrics::AttemptResult attempt_result,
Tianjie Xu1f93d092017-10-09 12:13:29 -0700222 ErrorCode internal_error_code) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700223 string metric = metrics::kMetricAttemptNumber;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700224 LOG(INFO) << "Uploading " << attempt_number << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700225 metrics_lib_->SendToUMA(metric,
226 attempt_number,
227 0, // min: 0 attempts
228 49, // max: 49 attempts
229 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800230
Tianjie Xu98333a82017-09-22 21:29:29 -0700231 metric = metrics::kMetricAttemptPayloadType;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700232 LOG(INFO) << "Uploading " << utils::ToString(payload_type) << " for metric "
233 << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700234 metrics_lib_->SendEnumToUMA(metric, payload_type, kNumPayloadTypes);
David Zeuthen33bae492014-02-25 16:16:18 -0800235
Tianjie Xu98333a82017-09-22 21:29:29 -0700236 metric = metrics::kMetricAttemptDurationMinutes;
David Zeuthen33bae492014-02-25 16:16:18 -0800237 LOG(INFO) << "Uploading " << utils::FormatTimeDelta(duration)
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700238 << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700239 metrics_lib_->SendToUMA(metric,
240 duration.InMinutes(),
241 0, // min: 0 min
242 10 * 24 * 60, // max: 10 days
243 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800244
Tianjie Xu98333a82017-09-22 21:29:29 -0700245 metric = metrics::kMetricAttemptDurationUptimeMinutes;
David Zeuthen33bae492014-02-25 16:16:18 -0800246 LOG(INFO) << "Uploading " << utils::FormatTimeDelta(duration_uptime)
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700247 << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700248 metrics_lib_->SendToUMA(metric,
249 duration_uptime.InMinutes(),
250 0, // min: 0 min
251 10 * 24 * 60, // max: 10 days
252 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800253
Tianjie Xu98333a82017-09-22 21:29:29 -0700254 metric = metrics::kMetricAttemptPayloadSizeMiB;
David Zeuthen33bae492014-02-25 16:16:18 -0800255 int64_t payload_size_mib = payload_size / kNumBytesInOneMiB;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700256 LOG(INFO) << "Uploading " << payload_size_mib << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700257 metrics_lib_->SendToUMA(metric,
258 payload_size_mib,
259 0, // min: 0 MiB
260 1024, // max: 1024 MiB = 1 GiB
261 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800262
David Zeuthen33bae492014-02-25 16:16:18 -0800263
David Zeuthen33bae492014-02-25 16:16:18 -0800264
Tianjie Xu98333a82017-09-22 21:29:29 -0700265 metric = metrics::kMetricAttemptResult;
David Zeuthen33bae492014-02-25 16:16:18 -0800266 LOG(INFO) << "Uploading " << static_cast<int>(attempt_result)
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700267 << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700268 metrics_lib_->SendEnumToUMA(
David Zeuthen33bae492014-02-25 16:16:18 -0800269 metric,
270 static_cast<int>(attempt_result),
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700271 static_cast<int>(metrics::AttemptResult::kNumConstants));
David Zeuthen33bae492014-02-25 16:16:18 -0800272
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700273 if (internal_error_code != ErrorCode::kSuccess) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700274 metric = metrics::kMetricAttemptInternalErrorCode;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700275 LOG(INFO) << "Uploading " << internal_error_code << " for metric "
276 << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700277 metrics_lib_->SendEnumToUMA(metric,
278 static_cast<int>(internal_error_code),
279 static_cast<int>(ErrorCode::kUmaReportedMax));
David Zeuthen33bae492014-02-25 16:16:18 -0800280 }
281
David Zeuthen33bae492014-02-25 16:16:18 -0800282 base::TimeDelta time_since_last;
Alex Deymoa2591792015-11-17 00:39:40 -0300283 if (metrics_utils::WallclockDurationHelper(
284 system_state,
285 kPrefsMetricsAttemptLastReportingTime,
286 &time_since_last)) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700287 metric = metrics::kMetricAttemptTimeSinceLastAttemptMinutes;
David Zeuthen33bae492014-02-25 16:16:18 -0800288 LOG(INFO) << "Sending " << utils::FormatTimeDelta(time_since_last)
289 << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700290 metrics_lib_->SendToUMA(metric,
291 time_since_last.InMinutes(),
292 0, // min: 0 min
293 30 * 24 * 60, // max: 30 days
294 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800295 }
296
297 static int64_t uptime_since_last_storage = 0;
298 base::TimeDelta uptime_since_last;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700299 if (metrics_utils::MonotonicDurationHelper(
300 system_state, &uptime_since_last_storage, &uptime_since_last)) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700301 metric = metrics::kMetricAttemptTimeSinceLastAttemptUptimeMinutes;
David Zeuthen33bae492014-02-25 16:16:18 -0800302 LOG(INFO) << "Sending " << utils::FormatTimeDelta(uptime_since_last)
303 << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700304 metrics_lib_->SendToUMA(metric,
305 uptime_since_last.InMinutes(),
306 0, // min: 0 min
307 30 * 24 * 60, // max: 30 days
308 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800309 }
Tianjie Xu1f93d092017-10-09 12:13:29 -0700310}
311
312void MetricsReporterOmaha::ReportUpdateAttemptDownloadMetrics(
313 int64_t payload_bytes_downloaded,
314 int64_t payload_download_speed_bps,
315 DownloadSource download_source,
316 metrics::DownloadErrorCode payload_download_error_code,
317 metrics::ConnectionType connection_type) {
318 string metric = metrics::kMetricAttemptPayloadBytesDownloadedMiB;
319 int64_t payload_bytes_downloaded_mib =
320 payload_bytes_downloaded / kNumBytesInOneMiB;
321 LOG(INFO) << "Uploading " << payload_bytes_downloaded_mib << " for metric "
322 << metric;
323 metrics_lib_->SendToUMA(metric,
324 payload_bytes_downloaded_mib,
325 0, // min: 0 MiB
326 1024, // max: 1024 MiB = 1 GiB
327 50); // num_buckets
328
329 metric = metrics::kMetricAttemptPayloadDownloadSpeedKBps;
330 int64_t payload_download_speed_kbps = payload_download_speed_bps / 1000;
331 LOG(INFO) << "Uploading " << payload_download_speed_kbps << " for metric "
332 << metric;
333 metrics_lib_->SendToUMA(metric,
334 payload_download_speed_kbps,
335 0, // min: 0 kB/s
336 10 * 1000, // max: 10000 kB/s = 10 MB/s
337 50); // num_buckets
338
339 metric = metrics::kMetricAttemptDownloadSource;
340 LOG(INFO) << "Uploading " << download_source << " for metric " << metric;
341 metrics_lib_->SendEnumToUMA(metric, download_source, kNumDownloadSources);
342
343 if (payload_download_error_code != metrics::DownloadErrorCode::kUnset) {
344 metric = metrics::kMetricAttemptDownloadErrorCode;
345 LOG(INFO) << "Uploading " << static_cast<int>(payload_download_error_code)
346 << " for metric " << metric << " (sparse)";
347 metrics_lib_->SendSparseToUMA(
348 metric, static_cast<int>(payload_download_error_code));
349 }
David Zeuthenb281f072014-04-02 10:20:19 -0700350
Tianjie Xu98333a82017-09-22 21:29:29 -0700351 metric = metrics::kMetricAttemptConnectionType;
David Zeuthenb281f072014-04-02 10:20:19 -0700352 LOG(INFO) << "Uploading " << static_cast<int>(connection_type)
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700353 << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700354 metrics_lib_->SendEnumToUMA(
David Zeuthenb281f072014-04-02 10:20:19 -0700355 metric,
356 static_cast<int>(connection_type),
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700357 static_cast<int>(metrics::ConnectionType::kNumConstants));
David Zeuthen33bae492014-02-25 16:16:18 -0800358}
359
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700360void MetricsReporterOmaha::ReportSuccessfulUpdateMetrics(
361 int attempt_count,
362 int updates_abandoned_count,
363 PayloadType payload_type,
364 int64_t payload_size,
365 int64_t num_bytes_downloaded[kNumDownloadSources],
366 int download_overhead_percentage,
367 base::TimeDelta total_duration,
Sen Jiang8712e962018-05-08 12:12:28 -0700368 base::TimeDelta total_duration_uptime,
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700369 int reboot_count,
370 int url_switch_count) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700371 string metric = metrics::kMetricSuccessfulUpdatePayloadSizeMiB;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700372 int64_t mbs = payload_size / kNumBytesInOneMiB;
David Zeuthen33bae492014-02-25 16:16:18 -0800373 LOG(INFO) << "Uploading " << mbs << " (MiBs) for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700374 metrics_lib_->SendToUMA(metric,
375 mbs,
376 0, // min: 0 MiB
377 1024, // max: 1024 MiB = 1 GiB
378 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800379
380 int64_t total_bytes = 0;
381 int download_sources_used = 0;
382 for (int i = 0; i < kNumDownloadSources + 1; i++) {
383 DownloadSource source = static_cast<DownloadSource>(i);
384
385 // Only consider this download source (and send byte counts) as
386 // having been used if we downloaded a non-trivial amount of bytes
Alex Vakulenko072359c2014-07-18 11:41:07 -0700387 // (e.g. at least 1 MiB) that contributed to the
David Zeuthen33bae492014-02-25 16:16:18 -0800388 // update. Otherwise we're going to end up with a lot of zero-byte
389 // events in the histogram.
390
Tianjie Xu98333a82017-09-22 21:29:29 -0700391 metric = metrics::kMetricSuccessfulUpdateBytesDownloadedMiB;
David Zeuthen33bae492014-02-25 16:16:18 -0800392 if (i < kNumDownloadSources) {
393 metric += utils::ToString(source);
394 mbs = num_bytes_downloaded[i] / kNumBytesInOneMiB;
395 total_bytes += num_bytes_downloaded[i];
396 if (mbs > 0)
397 download_sources_used |= (1 << i);
398 } else {
399 mbs = total_bytes / kNumBytesInOneMiB;
400 }
401
402 if (mbs > 0) {
403 LOG(INFO) << "Uploading " << mbs << " (MiBs) for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700404 metrics_lib_->SendToUMA(metric,
405 mbs,
406 0, // min: 0 MiB
407 1024, // max: 1024 MiB = 1 GiB
408 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800409 }
410 }
411
Tianjie Xu98333a82017-09-22 21:29:29 -0700412 metric = metrics::kMetricSuccessfulUpdateDownloadSourcesUsed;
David Zeuthen33bae492014-02-25 16:16:18 -0800413 LOG(INFO) << "Uploading 0x" << std::hex << download_sources_used
414 << " (bit flags) for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700415 metrics_lib_->SendToUMA(metric,
416 download_sources_used,
417 0, // min
418 (1 << kNumDownloadSources) - 1, // max
419 1 << kNumDownloadSources); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800420
Tianjie Xu98333a82017-09-22 21:29:29 -0700421 metric = metrics::kMetricSuccessfulUpdateDownloadOverheadPercentage;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700422 LOG(INFO) << "Uploading " << download_overhead_percentage << "% for metric "
423 << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700424 metrics_lib_->SendToUMA(metric,
425 download_overhead_percentage,
426 0, // min: 0% overhead
427 1000, // max: 1000% overhead
428 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800429
Tianjie Xu98333a82017-09-22 21:29:29 -0700430 metric = metrics::kMetricSuccessfulUpdateUrlSwitchCount;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700431 LOG(INFO) << "Uploading " << url_switch_count << " (count) for metric "
432 << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700433 metrics_lib_->SendToUMA(metric,
434 url_switch_count,
435 0, // min: 0 URL switches
436 49, // max: 49 URL switches
437 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800438
Tianjie Xu98333a82017-09-22 21:29:29 -0700439 metric = metrics::kMetricSuccessfulUpdateTotalDurationMinutes;
David Zeuthen33bae492014-02-25 16:16:18 -0800440 LOG(INFO) << "Uploading " << utils::FormatTimeDelta(total_duration)
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700441 << " for metric " << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700442 metrics_lib_->SendToUMA(metric,
443 static_cast<int>(total_duration.InMinutes()),
444 0, // min: 0 min
445 365 * 24 * 60, // max: 365 days ~= 1 year
446 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800447
Sen Jiang8712e962018-05-08 12:12:28 -0700448 metric = metrics::kMetricSuccessfulUpdateTotalDurationUptimeMinutes;
449 LOG(INFO) << "Uploading " << utils::FormatTimeDelta(total_duration_uptime)
450 << " for metric " << metric;
451 metrics_lib_->SendToUMA(metric,
452 static_cast<int>(total_duration_uptime.InMinutes()),
453 0, // min: 0 min
454 30 * 24 * 60, // max: 30 days
455 50); // num_buckets
456
Tianjie Xu98333a82017-09-22 21:29:29 -0700457 metric = metrics::kMetricSuccessfulUpdateRebootCount;
David Zeuthen33bae492014-02-25 16:16:18 -0800458 LOG(INFO) << "Uploading reboot count of " << reboot_count << " for metric "
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700459 << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700460 metrics_lib_->SendToUMA(metric,
461 reboot_count,
462 0, // min: 0 reboots
463 49, // max: 49 reboots
464 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800465
Tianjie Xu98333a82017-09-22 21:29:29 -0700466 metric = metrics::kMetricSuccessfulUpdatePayloadType;
467 metrics_lib_->SendEnumToUMA(metric, payload_type, kNumPayloadTypes);
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700468 LOG(INFO) << "Uploading " << utils::ToString(payload_type) << " for metric "
469 << metric;
David Zeuthen33bae492014-02-25 16:16:18 -0800470
Tianjie Xu98333a82017-09-22 21:29:29 -0700471 metric = metrics::kMetricSuccessfulUpdateAttemptCount;
472 metrics_lib_->SendToUMA(metric,
473 attempt_count,
474 1, // min: 1 attempt
475 50, // max: 50 attempts
476 50); // num_buckets
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700477 LOG(INFO) << "Uploading " << attempt_count << " for metric " << metric;
David Zeuthen33bae492014-02-25 16:16:18 -0800478
Tianjie Xu98333a82017-09-22 21:29:29 -0700479 metric = metrics::kMetricSuccessfulUpdateUpdatesAbandonedCount;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700480 LOG(INFO) << "Uploading " << updates_abandoned_count << " (count) for metric "
481 << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700482 metrics_lib_->SendToUMA(metric,
483 updates_abandoned_count,
484 0, // min: 0 counts
485 49, // max: 49 counts
486 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800487}
488
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700489void MetricsReporterOmaha::ReportRollbackMetrics(
490 metrics::RollbackResult result) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700491 string metric = metrics::kMetricRollbackResult;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700492 int value = static_cast<int>(result);
David Zeuthen96197df2014-04-16 12:22:39 -0700493 LOG(INFO) << "Sending " << value << " for metric " << metric << " (enum)";
Tianjie Xu98333a82017-09-22 21:29:29 -0700494 metrics_lib_->SendEnumToUMA(
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700495 metric, value, static_cast<int>(metrics::RollbackResult::kNumConstants));
David Zeuthen96197df2014-04-16 12:22:39 -0700496}
497
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700498void MetricsReporterOmaha::ReportCertificateCheckMetrics(
499 ServerToCheck server_to_check, CertificateCheckResult result) {
Alex Deymoc1c17b42015-11-23 03:53:15 -0300500 string metric;
501 switch (server_to_check) {
502 case ServerToCheck::kUpdate:
Tianjie Xu98333a82017-09-22 21:29:29 -0700503 metric = metrics::kMetricCertificateCheckUpdateCheck;
Alex Deymoc1c17b42015-11-23 03:53:15 -0300504 break;
505 case ServerToCheck::kDownload:
Tianjie Xu98333a82017-09-22 21:29:29 -0700506 metric = metrics::kMetricCertificateCheckDownload;
Alex Deymoc1c17b42015-11-23 03:53:15 -0300507 break;
Alex Deymo33e91e72015-12-01 18:26:08 -0300508 case ServerToCheck::kNone:
509 return;
Alex Deymoc1c17b42015-11-23 03:53:15 -0300510 }
511 LOG(INFO) << "Uploading " << static_cast<int>(result) << " for metric "
512 << metric;
Tianjie Xu98333a82017-09-22 21:29:29 -0700513 metrics_lib_->SendEnumToUMA(
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700514 metric,
515 static_cast<int>(result),
Alex Deymoc1c17b42015-11-23 03:53:15 -0300516 static_cast<int>(CertificateCheckResult::kNumConstants));
517}
518
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700519void MetricsReporterOmaha::ReportFailedUpdateCount(int target_attempt) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700520 string metric = metrics::kMetricFailedUpdateCount;
521 metrics_lib_->SendToUMA(metric,
522 target_attempt,
523 1, // min value
524 50, // max value
525 kNumDefaultUmaBuckets);
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700526
527 LOG(INFO) << "Uploading " << target_attempt << " (count) for metric "
528 << metric;
529}
530
531void MetricsReporterOmaha::ReportTimeToReboot(int time_to_reboot_minutes) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700532 string metric = metrics::kMetricTimeToRebootMinutes;
533 metrics_lib_->SendToUMA(metric,
534 time_to_reboot_minutes,
535 0, // min: 0 minute
536 30 * 24 * 60, // max: 1 month (approx)
537 kNumDefaultUmaBuckets);
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700538
539 LOG(INFO) << "Uploading " << time_to_reboot_minutes << " for metric "
540 << metric;
541}
542
543void MetricsReporterOmaha::ReportInstallDateProvisioningSource(int source,
544 int max) {
Tianjie Xu98333a82017-09-22 21:29:29 -0700545 metrics_lib_->SendEnumToUMA(metrics::kMetricInstallDateProvisioningSource,
546 source, // Sample.
547 max);
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700548}
David Zeuthen33bae492014-02-25 16:16:18 -0800549
550} // namespace chromeos_update_engine