blob: fcbe7e4e0562dde09f0f726edc18047c1e34b6fc [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
19#include <string>
20
21#include <base/logging.h>
Alex Deymoa2591792015-11-17 00:39:40 -030022#include <metrics/metrics_library.h>
David Zeuthen33bae492014-02-25 16:16:18 -080023
Alex Deymo39910dc2015-11-09 17:04:30 -080024#include "update_engine/common/clock_interface.h"
25#include "update_engine/common/constants.h"
26#include "update_engine/common/prefs_interface.h"
27#include "update_engine/common/utils.h"
Alex Deymoa2591792015-11-17 00:39:40 -030028#include "update_engine/metrics_utils.h"
David Zeuthen33bae492014-02-25 16:16:18 -080029#include "update_engine/system_state.h"
David Zeuthen33bae492014-02-25 16:16:18 -080030
31using std::string;
32
33namespace chromeos_update_engine {
34
David Zeuthen33bae492014-02-25 16:16:18 -080035// UpdateEngine.Daily.* metrics.
Tianjie Xu282aa1f2017-09-05 13:42:45 -070036constexpr char kMetricDailyOSAgeDays[] = "UpdateEngine.Daily.OSAgeDays";
David Zeuthen33bae492014-02-25 16:16:18 -080037
38// UpdateEngine.Check.* metrics.
Tianjie Xu282aa1f2017-09-05 13:42:45 -070039constexpr char kMetricCheckDownloadErrorCode[] =
David Zeuthen33bae492014-02-25 16:16:18 -080040 "UpdateEngine.Check.DownloadErrorCode";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070041constexpr char kMetricCheckReaction[] = "UpdateEngine.Check.Reaction";
42constexpr char kMetricCheckResult[] = "UpdateEngine.Check.Result";
43constexpr char kMetricCheckTimeSinceLastCheckMinutes[] =
David Zeuthen33bae492014-02-25 16:16:18 -080044 "UpdateEngine.Check.TimeSinceLastCheckMinutes";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070045constexpr char kMetricCheckTimeSinceLastCheckUptimeMinutes[] =
David Zeuthen33bae492014-02-25 16:16:18 -080046 "UpdateEngine.Check.TimeSinceLastCheckUptimeMinutes";
47
48// UpdateEngine.Attempt.* metrics.
Tianjie Xu282aa1f2017-09-05 13:42:45 -070049constexpr char kMetricAttemptNumber[] = "UpdateEngine.Attempt.Number";
50constexpr char kMetricAttemptPayloadType[] = "UpdateEngine.Attempt.PayloadType";
51constexpr char kMetricAttemptPayloadSizeMiB[] =
David Zeuthen33bae492014-02-25 16:16:18 -080052 "UpdateEngine.Attempt.PayloadSizeMiB";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070053constexpr char kMetricAttemptConnectionType[] =
David Zeuthenb281f072014-04-02 10:20:19 -070054 "UpdateEngine.Attempt.ConnectionType";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070055constexpr char kMetricAttemptDurationMinutes[] =
David Zeuthen33bae492014-02-25 16:16:18 -080056 "UpdateEngine.Attempt.DurationMinutes";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070057constexpr char kMetricAttemptDurationUptimeMinutes[] =
David Zeuthen33bae492014-02-25 16:16:18 -080058 "UpdateEngine.Attempt.DurationUptimeMinutes";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070059constexpr char kMetricAttemptTimeSinceLastAttemptMinutes[] =
David Zeuthen33bae492014-02-25 16:16:18 -080060 "UpdateEngine.Attempt.TimeSinceLastAttemptMinutes";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070061constexpr char kMetricAttemptTimeSinceLastAttemptUptimeMinutes[] =
David Zeuthen33bae492014-02-25 16:16:18 -080062 "UpdateEngine.Attempt.TimeSinceLastAttemptUptimeMinutes";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070063constexpr char kMetricAttemptPayloadBytesDownloadedMiB[] =
David Zeuthen33bae492014-02-25 16:16:18 -080064 "UpdateEngine.Attempt.PayloadBytesDownloadedMiB";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070065constexpr char kMetricAttemptPayloadDownloadSpeedKBps[] =
David Zeuthen33bae492014-02-25 16:16:18 -080066 "UpdateEngine.Attempt.PayloadDownloadSpeedKBps";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070067constexpr char kMetricAttemptDownloadSource[] =
David Zeuthen33bae492014-02-25 16:16:18 -080068 "UpdateEngine.Attempt.DownloadSource";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070069constexpr char kMetricAttemptResult[] = "UpdateEngine.Attempt.Result";
70constexpr char kMetricAttemptInternalErrorCode[] =
David Zeuthen33bae492014-02-25 16:16:18 -080071 "UpdateEngine.Attempt.InternalErrorCode";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070072constexpr char kMetricAttemptDownloadErrorCode[] =
David Zeuthen33bae492014-02-25 16:16:18 -080073 "UpdateEngine.Attempt.DownloadErrorCode";
74
75// UpdateEngine.SuccessfulUpdate.* metrics.
Tianjie Xu282aa1f2017-09-05 13:42:45 -070076constexpr char kMetricSuccessfulUpdateAttemptCount[] =
David Zeuthen33bae492014-02-25 16:16:18 -080077 "UpdateEngine.SuccessfulUpdate.AttemptCount";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070078constexpr char kMetricSuccessfulUpdateBytesDownloadedMiB[] =
David Zeuthen33bae492014-02-25 16:16:18 -080079 "UpdateEngine.SuccessfulUpdate.BytesDownloadedMiB";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070080constexpr char kMetricSuccessfulUpdateDownloadOverheadPercentage[] =
David Zeuthen33bae492014-02-25 16:16:18 -080081 "UpdateEngine.SuccessfulUpdate.DownloadOverheadPercentage";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070082constexpr char kMetricSuccessfulUpdateDownloadSourcesUsed[] =
David Zeuthen33bae492014-02-25 16:16:18 -080083 "UpdateEngine.SuccessfulUpdate.DownloadSourcesUsed";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070084constexpr char kMetricSuccessfulUpdatePayloadType[] =
David Zeuthen33bae492014-02-25 16:16:18 -080085 "UpdateEngine.SuccessfulUpdate.PayloadType";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070086constexpr char kMetricSuccessfulUpdatePayloadSizeMiB[] =
David Zeuthen33bae492014-02-25 16:16:18 -080087 "UpdateEngine.SuccessfulUpdate.PayloadSizeMiB";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070088constexpr char kMetricSuccessfulUpdateRebootCount[] =
David Zeuthen33bae492014-02-25 16:16:18 -080089 "UpdateEngine.SuccessfulUpdate.RebootCount";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070090constexpr char kMetricSuccessfulUpdateTotalDurationMinutes[] =
David Zeuthen33bae492014-02-25 16:16:18 -080091 "UpdateEngine.SuccessfulUpdate.TotalDurationMinutes";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070092constexpr char kMetricSuccessfulUpdateUpdatesAbandonedCount[] =
David Zeuthen33bae492014-02-25 16:16:18 -080093 "UpdateEngine.SuccessfulUpdate.UpdatesAbandonedCount";
Tianjie Xu282aa1f2017-09-05 13:42:45 -070094constexpr char kMetricSuccessfulUpdateUrlSwitchCount[] =
David Zeuthen33bae492014-02-25 16:16:18 -080095 "UpdateEngine.SuccessfulUpdate.UrlSwitchCount";
96
David Zeuthen96197df2014-04-16 12:22:39 -070097// UpdateEngine.Rollback.* metric.
Tianjie Xu282aa1f2017-09-05 13:42:45 -070098constexpr char kMetricRollbackResult[] = "UpdateEngine.Rollback.Result";
David Zeuthen96197df2014-04-16 12:22:39 -070099
Alex Deymoc1c17b42015-11-23 03:53:15 -0300100// UpdateEngine.CertificateCheck.* metrics.
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700101constexpr char kMetricCertificateCheckUpdateCheck[] =
Alex Deymoc1c17b42015-11-23 03:53:15 -0300102 "UpdateEngine.CertificateCheck.UpdateCheck";
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700103constexpr char kMetricCertificateCheckDownload[] =
Alex Deymoc1c17b42015-11-23 03:53:15 -0300104 "UpdateEngine.CertificateCheck.Download";
105
David Zeuthen33bae492014-02-25 16:16:18 -0800106// UpdateEngine.* metrics.
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700107constexpr char kMetricFailedUpdateCount[] = "UpdateEngine.FailedUpdateCount";
108constexpr char kMetricInstallDateProvisioningSource[] =
David Zeuthen33bae492014-02-25 16:16:18 -0800109 "UpdateEngine.InstallDateProvisioningSource";
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700110constexpr char kMetricTimeToRebootMinutes[] =
David Zeuthen33bae492014-02-25 16:16:18 -0800111 "UpdateEngine.TimeToRebootMinutes";
112
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700113void MetricsReporterOmaha::Initialize() {
114 metrics_lib_.Init();
David Zeuthen33bae492014-02-25 16:16:18 -0800115}
116
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700117void MetricsReporterOmaha::ReportDailyMetrics(base::TimeDelta os_age) {
118 string metric = kMetricDailyOSAgeDays;
119 LOG(INFO) << "Uploading " << utils::FormatTimeDelta(os_age) << " for metric "
120 << metric;
121 metrics_lib_.SendToUMA(metric,
122 static_cast<int>(os_age.InDays()),
123 0, // min: 0 days
124 6 * 30, // max: 6 months (approx)
125 50); // num_buckets
126}
127
128void MetricsReporterOmaha::ReportUpdateCheckMetrics(
129 SystemState* system_state,
130 metrics::CheckResult result,
131 metrics::CheckReaction reaction,
132 metrics::DownloadErrorCode download_error_code) {
David Zeuthen33bae492014-02-25 16:16:18 -0800133 string metric;
134 int value;
135 int max_value;
136
137 if (result != metrics::CheckResult::kUnset) {
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700138 metric = kMetricCheckResult;
David Zeuthen33bae492014-02-25 16:16:18 -0800139 value = static_cast<int>(result);
140 max_value = static_cast<int>(metrics::CheckResult::kNumConstants) - 1;
141 LOG(INFO) << "Sending " << value << " for metric " << metric << " (enum)";
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700142 metrics_lib_.SendEnumToUMA(metric, value, max_value);
David Zeuthen33bae492014-02-25 16:16:18 -0800143 }
144 if (reaction != metrics::CheckReaction::kUnset) {
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700145 metric = kMetricCheckReaction;
David Zeuthen33bae492014-02-25 16:16:18 -0800146 value = static_cast<int>(reaction);
147 max_value = static_cast<int>(metrics::CheckReaction::kNumConstants) - 1;
148 LOG(INFO) << "Sending " << value << " for metric " << metric << " (enum)";
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700149 metrics_lib_.SendEnumToUMA(metric, value, max_value);
David Zeuthen33bae492014-02-25 16:16:18 -0800150 }
151 if (download_error_code != metrics::DownloadErrorCode::kUnset) {
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700152 metric = kMetricCheckDownloadErrorCode;
David Zeuthen33bae492014-02-25 16:16:18 -0800153 value = static_cast<int>(download_error_code);
David Zeuthenc0dd0212014-04-04 14:49:49 -0700154 LOG(INFO) << "Sending " << value << " for metric " << metric << " (sparse)";
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700155 metrics_lib_.SendSparseToUMA(metric, value);
David Zeuthen33bae492014-02-25 16:16:18 -0800156 }
157
158 base::TimeDelta time_since_last;
Alex Deymoa2591792015-11-17 00:39:40 -0300159 if (metrics_utils::WallclockDurationHelper(
160 system_state,
161 kPrefsMetricsCheckLastReportingTime,
162 &time_since_last)) {
David Zeuthen33bae492014-02-25 16:16:18 -0800163 metric = kMetricCheckTimeSinceLastCheckMinutes;
164 LOG(INFO) << "Sending " << utils::FormatTimeDelta(time_since_last)
165 << " for metric " << metric;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700166 metrics_lib_.SendToUMA(metric,
167 time_since_last.InMinutes(),
168 0, // min: 0 min
169 30 * 24 * 60, // max: 30 days
170 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800171 }
172
173 base::TimeDelta uptime_since_last;
174 static int64_t uptime_since_last_storage = 0;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700175 if (metrics_utils::MonotonicDurationHelper(
176 system_state, &uptime_since_last_storage, &uptime_since_last)) {
David Zeuthen33bae492014-02-25 16:16:18 -0800177 metric = kMetricCheckTimeSinceLastCheckUptimeMinutes;
178 LOG(INFO) << "Sending " << utils::FormatTimeDelta(uptime_since_last)
179 << " for metric " << metric;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700180 metrics_lib_.SendToUMA(metric,
181 uptime_since_last.InMinutes(),
182 0, // min: 0 min
183 30 * 24 * 60, // max: 30 days
184 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800185 }
186}
187
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700188void MetricsReporterOmaha::ReportAbnormallyTerminatedUpdateAttemptMetrics() {
189 string metric = kMetricAttemptResult;
190 metrics::AttemptResult attempt_result =
191 metrics::AttemptResult::kAbnormalTermination;
David Zeuthen4e1d1492014-04-25 13:12:27 -0700192
193 LOG(INFO) << "Uploading " << static_cast<int>(attempt_result)
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700194 << " for metric " << metric;
195 metrics_lib_.SendEnumToUMA(
David Zeuthen4e1d1492014-04-25 13:12:27 -0700196 metric,
197 static_cast<int>(attempt_result),
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700198 static_cast<int>(metrics::AttemptResult::kNumConstants));
David Zeuthen4e1d1492014-04-25 13:12:27 -0700199}
200
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700201void MetricsReporterOmaha::ReportUpdateAttemptMetrics(
202 SystemState* system_state,
David Zeuthen33bae492014-02-25 16:16:18 -0800203 int attempt_number,
204 PayloadType payload_type,
205 base::TimeDelta duration,
206 base::TimeDelta duration_uptime,
207 int64_t payload_size,
208 int64_t payload_bytes_downloaded,
209 int64_t payload_download_speed_bps,
210 DownloadSource download_source,
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700211 metrics::AttemptResult attempt_result,
David Zeuthen33bae492014-02-25 16:16:18 -0800212 ErrorCode internal_error_code,
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700213 metrics::DownloadErrorCode payload_download_error_code,
214 metrics::ConnectionType connection_type) {
215 string metric = kMetricAttemptNumber;
216 LOG(INFO) << "Uploading " << attempt_number << " for metric " << metric;
217 metrics_lib_.SendToUMA(metric,
218 attempt_number,
219 0, // min: 0 attempts
220 49, // max: 49 attempts
221 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800222
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700223 metric = kMetricAttemptPayloadType;
224 LOG(INFO) << "Uploading " << utils::ToString(payload_type) << " for metric "
225 << metric;
226 metrics_lib_.SendEnumToUMA(metric, payload_type, kNumPayloadTypes);
David Zeuthen33bae492014-02-25 16:16:18 -0800227
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700228 metric = kMetricAttemptDurationMinutes;
David Zeuthen33bae492014-02-25 16:16:18 -0800229 LOG(INFO) << "Uploading " << utils::FormatTimeDelta(duration)
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700230 << " for metric " << metric;
231 metrics_lib_.SendToUMA(metric,
232 duration.InMinutes(),
233 0, // min: 0 min
234 10 * 24 * 60, // max: 10 days
235 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800236
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700237 metric = kMetricAttemptDurationUptimeMinutes;
David Zeuthen33bae492014-02-25 16:16:18 -0800238 LOG(INFO) << "Uploading " << utils::FormatTimeDelta(duration_uptime)
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700239 << " for metric " << metric;
240 metrics_lib_.SendToUMA(metric,
241 duration_uptime.InMinutes(),
242 0, // min: 0 min
243 10 * 24 * 60, // max: 10 days
244 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800245
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700246 metric = kMetricAttemptPayloadSizeMiB;
David Zeuthen33bae492014-02-25 16:16:18 -0800247 int64_t payload_size_mib = payload_size / kNumBytesInOneMiB;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700248 LOG(INFO) << "Uploading " << payload_size_mib << " for metric " << metric;
249 metrics_lib_.SendToUMA(metric,
250 payload_size_mib,
251 0, // min: 0 MiB
252 1024, // max: 1024 MiB = 1 GiB
253 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800254
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700255 metric = kMetricAttemptPayloadBytesDownloadedMiB;
David Zeuthen33bae492014-02-25 16:16:18 -0800256 int64_t payload_bytes_downloaded_mib =
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700257 payload_bytes_downloaded / kNumBytesInOneMiB;
258 LOG(INFO) << "Uploading " << payload_bytes_downloaded_mib << " for metric "
259 << metric;
260 metrics_lib_.SendToUMA(metric,
261 payload_bytes_downloaded_mib,
262 0, // min: 0 MiB
263 1024, // max: 1024 MiB = 1 GiB
264 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800265
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700266 metric = kMetricAttemptPayloadDownloadSpeedKBps;
David Zeuthen33bae492014-02-25 16:16:18 -0800267 int64_t payload_download_speed_kbps = payload_download_speed_bps / 1000;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700268 LOG(INFO) << "Uploading " << payload_download_speed_kbps << " for metric "
269 << metric;
270 metrics_lib_.SendToUMA(metric,
271 payload_download_speed_kbps,
272 0, // min: 0 kB/s
273 10 * 1000, // max: 10000 kB/s = 10 MB/s
274 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800275
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700276 metric = kMetricAttemptDownloadSource;
277 LOG(INFO) << "Uploading " << download_source << " for metric " << metric;
278 metrics_lib_.SendEnumToUMA(metric, download_source, kNumDownloadSources);
David Zeuthen33bae492014-02-25 16:16:18 -0800279
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700280 metric = kMetricAttemptResult;
David Zeuthen33bae492014-02-25 16:16:18 -0800281 LOG(INFO) << "Uploading " << static_cast<int>(attempt_result)
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700282 << " for metric " << metric;
283 metrics_lib_.SendEnumToUMA(
David Zeuthen33bae492014-02-25 16:16:18 -0800284 metric,
285 static_cast<int>(attempt_result),
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700286 static_cast<int>(metrics::AttemptResult::kNumConstants));
David Zeuthen33bae492014-02-25 16:16:18 -0800287
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700288 if (internal_error_code != ErrorCode::kSuccess) {
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700289 metric = kMetricAttemptInternalErrorCode;
290 LOG(INFO) << "Uploading " << internal_error_code << " for metric "
291 << metric;
292 metrics_lib_.SendEnumToUMA(metric,
293 static_cast<int>(internal_error_code),
294 static_cast<int>(ErrorCode::kUmaReportedMax));
David Zeuthen33bae492014-02-25 16:16:18 -0800295 }
296
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700297 if (payload_download_error_code != metrics::DownloadErrorCode::kUnset) {
298 metric = kMetricAttemptDownloadErrorCode;
David Zeuthen33bae492014-02-25 16:16:18 -0800299 LOG(INFO) << "Uploading " << static_cast<int>(payload_download_error_code)
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700300 << " for metric " << metric << " (sparse)";
301 metrics_lib_.SendSparseToUMA(metric,
302 static_cast<int>(payload_download_error_code));
David Zeuthen33bae492014-02-25 16:16:18 -0800303 }
304
305 base::TimeDelta time_since_last;
Alex Deymoa2591792015-11-17 00:39:40 -0300306 if (metrics_utils::WallclockDurationHelper(
307 system_state,
308 kPrefsMetricsAttemptLastReportingTime,
309 &time_since_last)) {
David Zeuthen33bae492014-02-25 16:16:18 -0800310 metric = kMetricAttemptTimeSinceLastAttemptMinutes;
311 LOG(INFO) << "Sending " << utils::FormatTimeDelta(time_since_last)
312 << " for metric " << metric;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700313 metrics_lib_.SendToUMA(metric,
314 time_since_last.InMinutes(),
315 0, // min: 0 min
316 30 * 24 * 60, // max: 30 days
317 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800318 }
319
320 static int64_t uptime_since_last_storage = 0;
321 base::TimeDelta uptime_since_last;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700322 if (metrics_utils::MonotonicDurationHelper(
323 system_state, &uptime_since_last_storage, &uptime_since_last)) {
David Zeuthen33bae492014-02-25 16:16:18 -0800324 metric = kMetricAttemptTimeSinceLastAttemptUptimeMinutes;
325 LOG(INFO) << "Sending " << utils::FormatTimeDelta(uptime_since_last)
326 << " for metric " << metric;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700327 metrics_lib_.SendToUMA(metric,
328 uptime_since_last.InMinutes(),
329 0, // min: 0 min
330 30 * 24 * 60, // max: 30 days
331 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800332 }
David Zeuthenb281f072014-04-02 10:20:19 -0700333
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700334 metric = kMetricAttemptConnectionType;
David Zeuthenb281f072014-04-02 10:20:19 -0700335 LOG(INFO) << "Uploading " << static_cast<int>(connection_type)
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700336 << " for metric " << metric;
337 metrics_lib_.SendEnumToUMA(
David Zeuthenb281f072014-04-02 10:20:19 -0700338 metric,
339 static_cast<int>(connection_type),
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700340 static_cast<int>(metrics::ConnectionType::kNumConstants));
David Zeuthen33bae492014-02-25 16:16:18 -0800341}
342
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700343void MetricsReporterOmaha::ReportSuccessfulUpdateMetrics(
344 int attempt_count,
345 int updates_abandoned_count,
346 PayloadType payload_type,
347 int64_t payload_size,
348 int64_t num_bytes_downloaded[kNumDownloadSources],
349 int download_overhead_percentage,
350 base::TimeDelta total_duration,
351 int reboot_count,
352 int url_switch_count) {
353 string metric = kMetricSuccessfulUpdatePayloadSizeMiB;
354 int64_t mbs = payload_size / kNumBytesInOneMiB;
David Zeuthen33bae492014-02-25 16:16:18 -0800355 LOG(INFO) << "Uploading " << mbs << " (MiBs) for metric " << metric;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700356 metrics_lib_.SendToUMA(metric,
357 mbs,
358 0, // min: 0 MiB
359 1024, // max: 1024 MiB = 1 GiB
360 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800361
362 int64_t total_bytes = 0;
363 int download_sources_used = 0;
364 for (int i = 0; i < kNumDownloadSources + 1; i++) {
365 DownloadSource source = static_cast<DownloadSource>(i);
366
367 // Only consider this download source (and send byte counts) as
368 // having been used if we downloaded a non-trivial amount of bytes
Alex Vakulenko072359c2014-07-18 11:41:07 -0700369 // (e.g. at least 1 MiB) that contributed to the
David Zeuthen33bae492014-02-25 16:16:18 -0800370 // update. Otherwise we're going to end up with a lot of zero-byte
371 // events in the histogram.
372
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700373 metric = kMetricSuccessfulUpdateBytesDownloadedMiB;
David Zeuthen33bae492014-02-25 16:16:18 -0800374 if (i < kNumDownloadSources) {
375 metric += utils::ToString(source);
376 mbs = num_bytes_downloaded[i] / kNumBytesInOneMiB;
377 total_bytes += num_bytes_downloaded[i];
378 if (mbs > 0)
379 download_sources_used |= (1 << i);
380 } else {
381 mbs = total_bytes / kNumBytesInOneMiB;
382 }
383
384 if (mbs > 0) {
385 LOG(INFO) << "Uploading " << mbs << " (MiBs) for metric " << metric;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700386 metrics_lib_.SendToUMA(metric,
387 mbs,
388 0, // min: 0 MiB
389 1024, // max: 1024 MiB = 1 GiB
390 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800391 }
392 }
393
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700394 metric = kMetricSuccessfulUpdateDownloadSourcesUsed;
David Zeuthen33bae492014-02-25 16:16:18 -0800395 LOG(INFO) << "Uploading 0x" << std::hex << download_sources_used
396 << " (bit flags) for metric " << metric;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700397 metrics_lib_.SendToUMA(metric,
398 download_sources_used,
399 0, // min
400 (1 << kNumDownloadSources) - 1, // max
401 1 << kNumDownloadSources); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800402
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700403 metric = kMetricSuccessfulUpdateDownloadOverheadPercentage;
404 LOG(INFO) << "Uploading " << download_overhead_percentage << "% for metric "
405 << metric;
406 metrics_lib_.SendToUMA(metric,
407 download_overhead_percentage,
408 0, // min: 0% overhead
409 1000, // max: 1000% overhead
410 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800411
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700412 metric = kMetricSuccessfulUpdateUrlSwitchCount;
413 LOG(INFO) << "Uploading " << url_switch_count << " (count) for metric "
414 << metric;
415 metrics_lib_.SendToUMA(metric,
416 url_switch_count,
417 0, // min: 0 URL switches
418 49, // max: 49 URL switches
419 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800420
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700421 metric = kMetricSuccessfulUpdateTotalDurationMinutes;
David Zeuthen33bae492014-02-25 16:16:18 -0800422 LOG(INFO) << "Uploading " << utils::FormatTimeDelta(total_duration)
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700423 << " for metric " << metric;
424 metrics_lib_.SendToUMA(metric,
425 static_cast<int>(total_duration.InMinutes()),
426 0, // min: 0 min
427 365 * 24 * 60, // max: 365 days ~= 1 year
428 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800429
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700430 metric = kMetricSuccessfulUpdateRebootCount;
David Zeuthen33bae492014-02-25 16:16:18 -0800431 LOG(INFO) << "Uploading reboot count of " << reboot_count << " for metric "
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700432 << metric;
433 metrics_lib_.SendToUMA(metric,
434 reboot_count,
435 0, // min: 0 reboots
436 49, // max: 49 reboots
437 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800438
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700439 metric = kMetricSuccessfulUpdatePayloadType;
440 metrics_lib_.SendEnumToUMA(metric, payload_type, kNumPayloadTypes);
441 LOG(INFO) << "Uploading " << utils::ToString(payload_type) << " for metric "
442 << metric;
David Zeuthen33bae492014-02-25 16:16:18 -0800443
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700444 metric = kMetricSuccessfulUpdateAttemptCount;
445 metrics_lib_.SendToUMA(metric,
446 attempt_count,
447 1, // min: 1 attempt
448 50, // max: 50 attempts
449 50); // num_buckets
450 LOG(INFO) << "Uploading " << attempt_count << " for metric " << metric;
David Zeuthen33bae492014-02-25 16:16:18 -0800451
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700452 metric = kMetricSuccessfulUpdateUpdatesAbandonedCount;
453 LOG(INFO) << "Uploading " << updates_abandoned_count << " (count) for metric "
454 << metric;
455 metrics_lib_.SendToUMA(metric,
456 updates_abandoned_count,
457 0, // min: 0 counts
458 49, // max: 49 counts
459 50); // num_buckets
David Zeuthen33bae492014-02-25 16:16:18 -0800460}
461
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700462void MetricsReporterOmaha::ReportRollbackMetrics(
463 metrics::RollbackResult result) {
464 string metric = kMetricRollbackResult;
465 int value = static_cast<int>(result);
David Zeuthen96197df2014-04-16 12:22:39 -0700466 LOG(INFO) << "Sending " << value << " for metric " << metric << " (enum)";
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700467 metrics_lib_.SendEnumToUMA(
468 metric, value, static_cast<int>(metrics::RollbackResult::kNumConstants));
David Zeuthen96197df2014-04-16 12:22:39 -0700469}
470
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700471void MetricsReporterOmaha::ReportCertificateCheckMetrics(
472 ServerToCheck server_to_check, CertificateCheckResult result) {
Alex Deymoc1c17b42015-11-23 03:53:15 -0300473 string metric;
474 switch (server_to_check) {
475 case ServerToCheck::kUpdate:
476 metric = kMetricCertificateCheckUpdateCheck;
477 break;
478 case ServerToCheck::kDownload:
479 metric = kMetricCertificateCheckDownload;
480 break;
Alex Deymo33e91e72015-12-01 18:26:08 -0300481 case ServerToCheck::kNone:
482 return;
Alex Deymoc1c17b42015-11-23 03:53:15 -0300483 }
484 LOG(INFO) << "Uploading " << static_cast<int>(result) << " for metric "
485 << metric;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700486 metrics_lib_.SendEnumToUMA(
487 metric,
488 static_cast<int>(result),
Alex Deymoc1c17b42015-11-23 03:53:15 -0300489 static_cast<int>(CertificateCheckResult::kNumConstants));
490}
491
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700492void MetricsReporterOmaha::ReportFailedUpdateCount(int target_attempt) {
493 string metric = kMetricFailedUpdateCount;
494 metrics_lib_.SendToUMA(metric,
495 target_attempt,
496 1, // min value
497 50, // max value
498 kNumDefaultUmaBuckets);
499
500 LOG(INFO) << "Uploading " << target_attempt << " (count) for metric "
501 << metric;
502}
503
504void MetricsReporterOmaha::ReportTimeToReboot(int time_to_reboot_minutes) {
505 string metric = kMetricTimeToRebootMinutes;
506 metrics_lib_.SendToUMA(metric,
507 time_to_reboot_minutes,
508 0, // min: 0 minute
509 30 * 24 * 60, // max: 1 month (approx)
510 kNumDefaultUmaBuckets);
511
512 LOG(INFO) << "Uploading " << time_to_reboot_minutes << " for metric "
513 << metric;
514}
515
516void MetricsReporterOmaha::ReportInstallDateProvisioningSource(int source,
517 int max) {
518 metrics_lib_.SendEnumToUMA(kMetricInstallDateProvisioningSource,
519 source, // Sample.
520 max);
521}
David Zeuthen33bae492014-02-25 16:16:18 -0800522
523} // namespace chromeos_update_engine