Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 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 Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 16 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 17 | #include "update_engine/cros/metrics_reporter_omaha.h" |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 18 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 19 | #include <memory> |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 20 | |
| 21 | #include <base/logging.h> |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 22 | #include <base/strings/string_number_conversions.h> |
Alex Deymo | a259179 | 2015-11-17 00:39:40 -0300 | [diff] [blame] | 23 | #include <metrics/metrics_library.h> |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 24 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 25 | #include "update_engine/common/clock_interface.h" |
| 26 | #include "update_engine/common/constants.h" |
| 27 | #include "update_engine/common/prefs_interface.h" |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 28 | #include "update_engine/common/system_state.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 29 | #include "update_engine/common/utils.h" |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 30 | #include "update_engine/cros/omaha_request_params.h" |
Alex Deymo | a259179 | 2015-11-17 00:39:40 -0300 | [diff] [blame] | 31 | #include "update_engine/metrics_utils.h" |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 32 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 33 | using base::Time; |
| 34 | using base::TimeDelta; |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 35 | using std::string; |
| 36 | |
| 37 | namespace chromeos_update_engine { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 38 | namespace metrics { |
| 39 | |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 40 | // UpdateEngine.Daily.* metrics. |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 41 | const char kMetricDailyOSAgeDays[] = "UpdateEngine.Daily.OSAgeDays"; |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 42 | |
| 43 | // UpdateEngine.Check.* metrics. |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 44 | const char kMetricCheckDownloadErrorCode[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 45 | "UpdateEngine.Check.DownloadErrorCode"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 46 | const char kMetricCheckReaction[] = "UpdateEngine.Check.Reaction"; |
| 47 | const char kMetricCheckResult[] = "UpdateEngine.Check.Result"; |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 48 | const char kMetricCheckTargetVersion[] = "UpdateEngine.Check.TargetVersion"; |
| 49 | const char kMetricCheckRollbackTargetVersion[] = |
| 50 | "UpdateEngine.Check.RollbackTargetVersion"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 51 | const char kMetricCheckTimeSinceLastCheckMinutes[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 52 | "UpdateEngine.Check.TimeSinceLastCheckMinutes"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 53 | const char kMetricCheckTimeSinceLastCheckUptimeMinutes[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 54 | "UpdateEngine.Check.TimeSinceLastCheckUptimeMinutes"; |
| 55 | |
| 56 | // UpdateEngine.Attempt.* metrics. |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 57 | const char kMetricAttemptNumber[] = "UpdateEngine.Attempt.Number"; |
| 58 | const char kMetricAttemptPayloadType[] = "UpdateEngine.Attempt.PayloadType"; |
| 59 | const char kMetricAttemptPayloadSizeMiB[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 60 | "UpdateEngine.Attempt.PayloadSizeMiB"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 61 | const char kMetricAttemptConnectionType[] = |
David Zeuthen | b281f07 | 2014-04-02 10:20:19 -0700 | [diff] [blame] | 62 | "UpdateEngine.Attempt.ConnectionType"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 63 | const char kMetricAttemptDurationMinutes[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 64 | "UpdateEngine.Attempt.DurationMinutes"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 65 | const char kMetricAttemptDurationUptimeMinutes[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 66 | "UpdateEngine.Attempt.DurationUptimeMinutes"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 67 | const char kMetricAttemptTimeSinceLastAttemptMinutes[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 68 | "UpdateEngine.Attempt.TimeSinceLastAttemptMinutes"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 69 | const char kMetricAttemptTimeSinceLastAttemptUptimeMinutes[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 70 | "UpdateEngine.Attempt.TimeSinceLastAttemptUptimeMinutes"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 71 | const char kMetricAttemptPayloadBytesDownloadedMiB[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 72 | "UpdateEngine.Attempt.PayloadBytesDownloadedMiB"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 73 | const char kMetricAttemptPayloadDownloadSpeedKBps[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 74 | "UpdateEngine.Attempt.PayloadDownloadSpeedKBps"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 75 | const char kMetricAttemptDownloadSource[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 76 | "UpdateEngine.Attempt.DownloadSource"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 77 | const char kMetricAttemptResult[] = "UpdateEngine.Attempt.Result"; |
| 78 | const char kMetricAttemptInternalErrorCode[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 79 | "UpdateEngine.Attempt.InternalErrorCode"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 80 | const char kMetricAttemptDownloadErrorCode[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 81 | "UpdateEngine.Attempt.DownloadErrorCode"; |
| 82 | |
| 83 | // UpdateEngine.SuccessfulUpdate.* metrics. |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 84 | const char kMetricSuccessfulUpdateAttemptCount[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 85 | "UpdateEngine.SuccessfulUpdate.AttemptCount"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 86 | const char kMetricSuccessfulUpdateBytesDownloadedMiB[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 87 | "UpdateEngine.SuccessfulUpdate.BytesDownloadedMiB"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 88 | const char kMetricSuccessfulUpdateDownloadOverheadPercentage[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 89 | "UpdateEngine.SuccessfulUpdate.DownloadOverheadPercentage"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 90 | const char kMetricSuccessfulUpdateDownloadSourcesUsed[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 91 | "UpdateEngine.SuccessfulUpdate.DownloadSourcesUsed"; |
May Lippert | 60aa3ca | 2018-08-15 16:55:29 -0700 | [diff] [blame] | 92 | const char kMetricSuccessfulUpdateDurationFromSeenDays[] = |
| 93 | "UpdateEngine.SuccessfulUpdate.DurationFromSeenDays.NoTimeRestriction"; |
| 94 | const char kMetricSuccessfulUpdateDurationFromSeenTimeRestrictedDays[] = |
| 95 | "UpdateEngine.SuccessfulUpdate.DurationFromSeenDays.TimeRestricted"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 96 | const char kMetricSuccessfulUpdatePayloadType[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 97 | "UpdateEngine.SuccessfulUpdate.PayloadType"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 98 | const char kMetricSuccessfulUpdatePayloadSizeMiB[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 99 | "UpdateEngine.SuccessfulUpdate.PayloadSizeMiB"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 100 | const char kMetricSuccessfulUpdateRebootCount[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 101 | "UpdateEngine.SuccessfulUpdate.RebootCount"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 102 | const char kMetricSuccessfulUpdateTotalDurationMinutes[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 103 | "UpdateEngine.SuccessfulUpdate.TotalDurationMinutes"; |
Sen Jiang | 8712e96 | 2018-05-08 12:12:28 -0700 | [diff] [blame] | 104 | const char kMetricSuccessfulUpdateTotalDurationUptimeMinutes[] = |
| 105 | "UpdateEngine.SuccessfulUpdate.TotalDurationUptimeMinutes"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 106 | const char kMetricSuccessfulUpdateUpdatesAbandonedCount[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 107 | "UpdateEngine.SuccessfulUpdate.UpdatesAbandonedCount"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 108 | const char kMetricSuccessfulUpdateUrlSwitchCount[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 109 | "UpdateEngine.SuccessfulUpdate.UrlSwitchCount"; |
| 110 | |
David Zeuthen | 96197df | 2014-04-16 12:22:39 -0700 | [diff] [blame] | 111 | // UpdateEngine.Rollback.* metric. |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 112 | const char kMetricRollbackResult[] = "UpdateEngine.Rollback.Result"; |
David Zeuthen | 96197df | 2014-04-16 12:22:39 -0700 | [diff] [blame] | 113 | |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 114 | // UpdateEngine.EnterpriseRollback.* metrics. |
| 115 | const char kMetricEnterpriseRollbackFailure[] = |
| 116 | "UpdateEngine.EnterpriseRollback.Failure"; |
| 117 | const char kMetricEnterpriseRollbackSuccess[] = |
| 118 | "UpdateEngine.EnterpriseRollback.Success"; |
| 119 | |
Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 120 | // UpdateEngine.CertificateCheck.* metrics. |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 121 | const char kMetricCertificateCheckUpdateCheck[] = |
Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 122 | "UpdateEngine.CertificateCheck.UpdateCheck"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 123 | const char kMetricCertificateCheckDownload[] = |
Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 124 | "UpdateEngine.CertificateCheck.Download"; |
| 125 | |
Marton Hunyady | ffbfdfb | 2018-05-30 13:03:29 +0200 | [diff] [blame] | 126 | // UpdateEngine.KernelKey.* metrics. |
| 127 | const char kMetricKernelMinVersion[] = "UpdateEngine.KernelKey.MinVersion"; |
| 128 | const char kMetricKernelMaxRollforwardVersion[] = |
| 129 | "UpdateEngine.KernelKey.MaxRollforwardVersion"; |
| 130 | const char kMetricKernelMaxRollforwardSetSuccess[] = |
| 131 | "UpdateEngine.KernelKey.MaxRollforwardSetSuccess"; |
| 132 | |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 133 | // UpdateEngine.* metrics. |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 134 | const char kMetricFailedUpdateCount[] = "UpdateEngine.FailedUpdateCount"; |
| 135 | const char kMetricInstallDateProvisioningSource[] = |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 136 | "UpdateEngine.InstallDateProvisioningSource"; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 137 | const char kMetricTimeToRebootMinutes[] = "UpdateEngine.TimeToRebootMinutes"; |
| 138 | |
Tianjie Xu | d4c5deb | 2017-10-24 11:17:03 -0700 | [diff] [blame] | 139 | std::unique_ptr<MetricsReporterInterface> CreateMetricsReporter() { |
| 140 | return std::make_unique<MetricsReporterOmaha>(); |
| 141 | } |
| 142 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 143 | } // namespace metrics |
| 144 | |
| 145 | MetricsReporterOmaha::MetricsReporterOmaha() |
| 146 | : metrics_lib_(new MetricsLibrary()) {} |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 147 | |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 148 | void MetricsReporterOmaha::ReportDailyMetrics(base::TimeDelta os_age) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 149 | string metric = metrics::kMetricDailyOSAgeDays; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 150 | metrics_lib_->SendToUMA(metric, |
| 151 | static_cast<int>(os_age.InDays()), |
| 152 | 0, // min: 0 days |
| 153 | 6 * 30, // max: 6 months (approx) |
| 154 | 50); // num_buckets |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | void MetricsReporterOmaha::ReportUpdateCheckMetrics( |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 158 | metrics::CheckResult result, |
| 159 | metrics::CheckReaction reaction, |
| 160 | metrics::DownloadErrorCode download_error_code) { |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 161 | string metric; |
| 162 | int value; |
| 163 | int max_value; |
| 164 | |
| 165 | if (result != metrics::CheckResult::kUnset) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 166 | metric = metrics::kMetricCheckResult; |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 167 | value = static_cast<int>(result); |
| 168 | max_value = static_cast<int>(metrics::CheckResult::kNumConstants) - 1; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 169 | metrics_lib_->SendEnumToUMA(metric, value, max_value); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 170 | } |
| 171 | if (reaction != metrics::CheckReaction::kUnset) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 172 | metric = metrics::kMetricCheckReaction; |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 173 | value = static_cast<int>(reaction); |
| 174 | max_value = static_cast<int>(metrics::CheckReaction::kNumConstants) - 1; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 175 | metrics_lib_->SendEnumToUMA(metric, value, max_value); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 176 | } |
| 177 | if (download_error_code != metrics::DownloadErrorCode::kUnset) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 178 | metric = metrics::kMetricCheckDownloadErrorCode; |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 179 | value = static_cast<int>(download_error_code); |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 180 | metrics_lib_->SendSparseToUMA(metric, value); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | base::TimeDelta time_since_last; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame^] | 184 | if (WallclockDurationHelper(kPrefsMetricsCheckLastReportingTime, |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 185 | &time_since_last)) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 186 | metric = metrics::kMetricCheckTimeSinceLastCheckMinutes; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 187 | metrics_lib_->SendToUMA(metric, |
| 188 | time_since_last.InMinutes(), |
| 189 | 0, // min: 0 min |
| 190 | 30 * 24 * 60, // max: 30 days |
| 191 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | base::TimeDelta uptime_since_last; |
| 195 | static int64_t uptime_since_last_storage = 0; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame^] | 196 | if (MonotonicDurationHelper(&uptime_since_last_storage, &uptime_since_last)) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 197 | metric = metrics::kMetricCheckTimeSinceLastCheckUptimeMinutes; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 198 | metrics_lib_->SendToUMA(metric, |
| 199 | uptime_since_last.InMinutes(), |
| 200 | 0, // min: 0 min |
| 201 | 30 * 24 * 60, // max: 30 days |
| 202 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 203 | } |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 204 | |
| 205 | // First section of target version specified for the update. |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame^] | 206 | if (SystemState::Get()->request_params()) { |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 207 | string target_version = |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame^] | 208 | SystemState::Get()->request_params()->target_version_prefix(); |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 209 | value = utils::VersionPrefix(target_version); |
| 210 | if (value != 0) { |
| 211 | metric = metrics::kMetricCheckTargetVersion; |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 212 | metrics_lib_->SendSparseToUMA(metric, value); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame^] | 213 | if (SystemState::Get()->request_params()->rollback_allowed()) { |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 214 | metric = metrics::kMetricCheckRollbackTargetVersion; |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 215 | metrics_lib_->SendSparseToUMA(metric, value); |
| 216 | } |
| 217 | } |
| 218 | } |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 219 | } |
| 220 | |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 221 | void MetricsReporterOmaha::ReportAbnormallyTerminatedUpdateAttemptMetrics() { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 222 | string metric = metrics::kMetricAttemptResult; |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 223 | metrics::AttemptResult attempt_result = |
| 224 | metrics::AttemptResult::kAbnormalTermination; |
David Zeuthen | 4e1d149 | 2014-04-25 13:12:27 -0700 | [diff] [blame] | 225 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 226 | metrics_lib_->SendEnumToUMA( |
David Zeuthen | 4e1d149 | 2014-04-25 13:12:27 -0700 | [diff] [blame] | 227 | metric, |
| 228 | static_cast<int>(attempt_result), |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 229 | static_cast<int>(metrics::AttemptResult::kNumConstants)); |
David Zeuthen | 4e1d149 | 2014-04-25 13:12:27 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 232 | void MetricsReporterOmaha::ReportUpdateAttemptMetrics( |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 233 | int attempt_number, |
| 234 | PayloadType payload_type, |
| 235 | base::TimeDelta duration, |
| 236 | base::TimeDelta duration_uptime, |
| 237 | int64_t payload_size, |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 238 | metrics::AttemptResult attempt_result, |
Tianjie Xu | 1f93d09 | 2017-10-09 12:13:29 -0700 | [diff] [blame] | 239 | ErrorCode internal_error_code) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 240 | string metric = metrics::kMetricAttemptNumber; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 241 | metrics_lib_->SendToUMA(metric, |
| 242 | attempt_number, |
| 243 | 0, // min: 0 attempts |
| 244 | 49, // max: 49 attempts |
| 245 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 246 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 247 | metric = metrics::kMetricAttemptPayloadType; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 248 | metrics_lib_->SendEnumToUMA(metric, payload_type, kNumPayloadTypes); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 249 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 250 | metric = metrics::kMetricAttemptDurationMinutes; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 251 | metrics_lib_->SendToUMA(metric, |
| 252 | duration.InMinutes(), |
| 253 | 0, // min: 0 min |
| 254 | 10 * 24 * 60, // max: 10 days |
| 255 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 256 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 257 | metric = metrics::kMetricAttemptDurationUptimeMinutes; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 258 | metrics_lib_->SendToUMA(metric, |
| 259 | duration_uptime.InMinutes(), |
| 260 | 0, // min: 0 min |
| 261 | 10 * 24 * 60, // max: 10 days |
| 262 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 263 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 264 | metric = metrics::kMetricAttemptPayloadSizeMiB; |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 265 | int64_t payload_size_mib = payload_size / kNumBytesInOneMiB; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 266 | metrics_lib_->SendToUMA(metric, |
| 267 | payload_size_mib, |
| 268 | 0, // min: 0 MiB |
| 269 | 1024, // max: 1024 MiB = 1 GiB |
| 270 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 271 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 272 | metric = metrics::kMetricAttemptResult; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 273 | metrics_lib_->SendEnumToUMA( |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 274 | metric, |
| 275 | static_cast<int>(attempt_result), |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 276 | static_cast<int>(metrics::AttemptResult::kNumConstants)); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 277 | |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 278 | if (internal_error_code != ErrorCode::kSuccess) { |
Amin Hassani | 80f4d4c | 2018-05-16 13:34:00 -0700 | [diff] [blame] | 279 | ReportInternalErrorCode(internal_error_code); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 280 | } |
| 281 | |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 282 | base::TimeDelta time_since_last; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame^] | 283 | if (WallclockDurationHelper(kPrefsMetricsAttemptLastReportingTime, |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 284 | &time_since_last)) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 285 | metric = metrics::kMetricAttemptTimeSinceLastAttemptMinutes; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 286 | metrics_lib_->SendToUMA(metric, |
| 287 | time_since_last.InMinutes(), |
| 288 | 0, // min: 0 min |
| 289 | 30 * 24 * 60, // max: 30 days |
| 290 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | static int64_t uptime_since_last_storage = 0; |
| 294 | base::TimeDelta uptime_since_last; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame^] | 295 | if (MonotonicDurationHelper(&uptime_since_last_storage, &uptime_since_last)) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 296 | metric = metrics::kMetricAttemptTimeSinceLastAttemptUptimeMinutes; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 297 | metrics_lib_->SendToUMA(metric, |
| 298 | uptime_since_last.InMinutes(), |
| 299 | 0, // min: 0 min |
| 300 | 30 * 24 * 60, // max: 30 days |
| 301 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 302 | } |
Tianjie Xu | 1f93d09 | 2017-10-09 12:13:29 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | void MetricsReporterOmaha::ReportUpdateAttemptDownloadMetrics( |
| 306 | int64_t payload_bytes_downloaded, |
| 307 | int64_t payload_download_speed_bps, |
| 308 | DownloadSource download_source, |
| 309 | metrics::DownloadErrorCode payload_download_error_code, |
| 310 | metrics::ConnectionType connection_type) { |
| 311 | string metric = metrics::kMetricAttemptPayloadBytesDownloadedMiB; |
| 312 | int64_t payload_bytes_downloaded_mib = |
| 313 | payload_bytes_downloaded / kNumBytesInOneMiB; |
Tianjie Xu | 1f93d09 | 2017-10-09 12:13:29 -0700 | [diff] [blame] | 314 | metrics_lib_->SendToUMA(metric, |
| 315 | payload_bytes_downloaded_mib, |
| 316 | 0, // min: 0 MiB |
| 317 | 1024, // max: 1024 MiB = 1 GiB |
| 318 | 50); // num_buckets |
| 319 | |
| 320 | metric = metrics::kMetricAttemptPayloadDownloadSpeedKBps; |
| 321 | int64_t payload_download_speed_kbps = payload_download_speed_bps / 1000; |
Tianjie Xu | 1f93d09 | 2017-10-09 12:13:29 -0700 | [diff] [blame] | 322 | metrics_lib_->SendToUMA(metric, |
| 323 | payload_download_speed_kbps, |
| 324 | 0, // min: 0 kB/s |
| 325 | 10 * 1000, // max: 10000 kB/s = 10 MB/s |
| 326 | 50); // num_buckets |
| 327 | |
| 328 | metric = metrics::kMetricAttemptDownloadSource; |
Tianjie Xu | 1f93d09 | 2017-10-09 12:13:29 -0700 | [diff] [blame] | 329 | metrics_lib_->SendEnumToUMA(metric, download_source, kNumDownloadSources); |
| 330 | |
| 331 | if (payload_download_error_code != metrics::DownloadErrorCode::kUnset) { |
| 332 | metric = metrics::kMetricAttemptDownloadErrorCode; |
Tianjie Xu | 1f93d09 | 2017-10-09 12:13:29 -0700 | [diff] [blame] | 333 | metrics_lib_->SendSparseToUMA( |
| 334 | metric, static_cast<int>(payload_download_error_code)); |
| 335 | } |
David Zeuthen | b281f07 | 2014-04-02 10:20:19 -0700 | [diff] [blame] | 336 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 337 | metric = metrics::kMetricAttemptConnectionType; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 338 | metrics_lib_->SendEnumToUMA( |
David Zeuthen | b281f07 | 2014-04-02 10:20:19 -0700 | [diff] [blame] | 339 | metric, |
| 340 | static_cast<int>(connection_type), |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 341 | static_cast<int>(metrics::ConnectionType::kNumConstants)); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 342 | } |
| 343 | |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 344 | void MetricsReporterOmaha::ReportSuccessfulUpdateMetrics( |
| 345 | int attempt_count, |
| 346 | int updates_abandoned_count, |
| 347 | PayloadType payload_type, |
| 348 | int64_t payload_size, |
| 349 | int64_t num_bytes_downloaded[kNumDownloadSources], |
| 350 | int download_overhead_percentage, |
| 351 | base::TimeDelta total_duration, |
Sen Jiang | 8712e96 | 2018-05-08 12:12:28 -0700 | [diff] [blame] | 352 | base::TimeDelta total_duration_uptime, |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 353 | int reboot_count, |
| 354 | int url_switch_count) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 355 | string metric = metrics::kMetricSuccessfulUpdatePayloadSizeMiB; |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 356 | int64_t mbs = payload_size / kNumBytesInOneMiB; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 357 | metrics_lib_->SendToUMA(metric, |
| 358 | mbs, |
| 359 | 0, // min: 0 MiB |
| 360 | 1024, // max: 1024 MiB = 1 GiB |
| 361 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 362 | |
| 363 | int64_t total_bytes = 0; |
| 364 | int download_sources_used = 0; |
| 365 | for (int i = 0; i < kNumDownloadSources + 1; i++) { |
| 366 | DownloadSource source = static_cast<DownloadSource>(i); |
| 367 | |
| 368 | // Only consider this download source (and send byte counts) as |
| 369 | // having been used if we downloaded a non-trivial amount of bytes |
Alex Vakulenko | 072359c | 2014-07-18 11:41:07 -0700 | [diff] [blame] | 370 | // (e.g. at least 1 MiB) that contributed to the |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 371 | // update. Otherwise we're going to end up with a lot of zero-byte |
| 372 | // events in the histogram. |
| 373 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 374 | metric = metrics::kMetricSuccessfulUpdateBytesDownloadedMiB; |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 375 | if (i < kNumDownloadSources) { |
| 376 | metric += utils::ToString(source); |
| 377 | mbs = num_bytes_downloaded[i] / kNumBytesInOneMiB; |
| 378 | total_bytes += num_bytes_downloaded[i]; |
| 379 | if (mbs > 0) |
| 380 | download_sources_used |= (1 << i); |
| 381 | } else { |
| 382 | mbs = total_bytes / kNumBytesInOneMiB; |
| 383 | } |
| 384 | |
| 385 | if (mbs > 0) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 386 | metrics_lib_->SendToUMA(metric, |
| 387 | mbs, |
| 388 | 0, // min: 0 MiB |
| 389 | 1024, // max: 1024 MiB = 1 GiB |
| 390 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 394 | metric = metrics::kMetricSuccessfulUpdateDownloadSourcesUsed; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 395 | metrics_lib_->SendToUMA(metric, |
| 396 | download_sources_used, |
| 397 | 0, // min |
| 398 | (1 << kNumDownloadSources) - 1, // max |
| 399 | 1 << kNumDownloadSources); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 400 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 401 | metric = metrics::kMetricSuccessfulUpdateDownloadOverheadPercentage; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 402 | metrics_lib_->SendToUMA(metric, |
| 403 | download_overhead_percentage, |
| 404 | 0, // min: 0% overhead |
| 405 | 1000, // max: 1000% overhead |
| 406 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 407 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 408 | metric = metrics::kMetricSuccessfulUpdateUrlSwitchCount; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 409 | metrics_lib_->SendToUMA(metric, |
| 410 | url_switch_count, |
| 411 | 0, // min: 0 URL switches |
| 412 | 49, // max: 49 URL switches |
| 413 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 414 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 415 | metric = metrics::kMetricSuccessfulUpdateTotalDurationMinutes; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 416 | metrics_lib_->SendToUMA(metric, |
| 417 | static_cast<int>(total_duration.InMinutes()), |
| 418 | 0, // min: 0 min |
| 419 | 365 * 24 * 60, // max: 365 days ~= 1 year |
| 420 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 421 | |
Sen Jiang | 8712e96 | 2018-05-08 12:12:28 -0700 | [diff] [blame] | 422 | metric = metrics::kMetricSuccessfulUpdateTotalDurationUptimeMinutes; |
Sen Jiang | 8712e96 | 2018-05-08 12:12:28 -0700 | [diff] [blame] | 423 | metrics_lib_->SendToUMA(metric, |
| 424 | static_cast<int>(total_duration_uptime.InMinutes()), |
| 425 | 0, // min: 0 min |
| 426 | 30 * 24 * 60, // max: 30 days |
| 427 | 50); // num_buckets |
| 428 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 429 | metric = metrics::kMetricSuccessfulUpdateRebootCount; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 430 | metrics_lib_->SendToUMA(metric, |
| 431 | reboot_count, |
| 432 | 0, // min: 0 reboots |
| 433 | 49, // max: 49 reboots |
| 434 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 435 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 436 | metric = metrics::kMetricSuccessfulUpdatePayloadType; |
| 437 | metrics_lib_->SendEnumToUMA(metric, payload_type, kNumPayloadTypes); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 438 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 439 | metric = metrics::kMetricSuccessfulUpdateAttemptCount; |
| 440 | metrics_lib_->SendToUMA(metric, |
| 441 | attempt_count, |
| 442 | 1, // min: 1 attempt |
| 443 | 50, // max: 50 attempts |
| 444 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 445 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 446 | metric = metrics::kMetricSuccessfulUpdateUpdatesAbandonedCount; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 447 | metrics_lib_->SendToUMA(metric, |
| 448 | updates_abandoned_count, |
| 449 | 0, // min: 0 counts |
| 450 | 49, // max: 49 counts |
| 451 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 452 | } |
| 453 | |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 454 | void MetricsReporterOmaha::ReportRollbackMetrics( |
| 455 | metrics::RollbackResult result) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 456 | string metric = metrics::kMetricRollbackResult; |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 457 | int value = static_cast<int>(result); |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 458 | metrics_lib_->SendEnumToUMA( |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 459 | metric, value, static_cast<int>(metrics::RollbackResult::kNumConstants)); |
David Zeuthen | 96197df | 2014-04-16 12:22:39 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 462 | void MetricsReporterOmaha::ReportEnterpriseRollbackMetrics( |
| 463 | bool success, const string& rollback_version) { |
| 464 | int value = utils::VersionPrefix(rollback_version); |
| 465 | string metric = metrics::kMetricEnterpriseRollbackSuccess; |
| 466 | if (!success) |
| 467 | metric = metrics::kMetricEnterpriseRollbackFailure; |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 468 | metrics_lib_->SendSparseToUMA(metric, value); |
| 469 | } |
| 470 | |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 471 | void MetricsReporterOmaha::ReportCertificateCheckMetrics( |
| 472 | ServerToCheck server_to_check, CertificateCheckResult result) { |
Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 473 | string metric; |
| 474 | switch (server_to_check) { |
| 475 | case ServerToCheck::kUpdate: |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 476 | metric = metrics::kMetricCertificateCheckUpdateCheck; |
Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 477 | break; |
| 478 | case ServerToCheck::kDownload: |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 479 | metric = metrics::kMetricCertificateCheckDownload; |
Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 480 | break; |
Alex Deymo | 33e91e7 | 2015-12-01 18:26:08 -0300 | [diff] [blame] | 481 | case ServerToCheck::kNone: |
| 482 | return; |
Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 483 | } |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 484 | metrics_lib_->SendEnumToUMA( |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 485 | metric, |
| 486 | static_cast<int>(result), |
Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 487 | static_cast<int>(CertificateCheckResult::kNumConstants)); |
| 488 | } |
| 489 | |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 490 | void MetricsReporterOmaha::ReportFailedUpdateCount(int target_attempt) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 491 | string metric = metrics::kMetricFailedUpdateCount; |
| 492 | metrics_lib_->SendToUMA(metric, |
| 493 | target_attempt, |
| 494 | 1, // min value |
| 495 | 50, // max value |
| 496 | kNumDefaultUmaBuckets); |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | void MetricsReporterOmaha::ReportTimeToReboot(int time_to_reboot_minutes) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 500 | string metric = metrics::kMetricTimeToRebootMinutes; |
| 501 | metrics_lib_->SendToUMA(metric, |
| 502 | time_to_reboot_minutes, |
| 503 | 0, // min: 0 minute |
| 504 | 30 * 24 * 60, // max: 1 month (approx) |
| 505 | kNumDefaultUmaBuckets); |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | void MetricsReporterOmaha::ReportInstallDateProvisioningSource(int source, |
| 509 | int max) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 510 | metrics_lib_->SendEnumToUMA(metrics::kMetricInstallDateProvisioningSource, |
| 511 | source, // Sample. |
| 512 | max); |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 513 | } |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 514 | |
Amin Hassani | 80f4d4c | 2018-05-16 13:34:00 -0700 | [diff] [blame] | 515 | void MetricsReporterOmaha::ReportInternalErrorCode(ErrorCode error_code) { |
| 516 | auto metric = metrics::kMetricAttemptInternalErrorCode; |
Amin Hassani | 80f4d4c | 2018-05-16 13:34:00 -0700 | [diff] [blame] | 517 | metrics_lib_->SendEnumToUMA(metric, |
| 518 | static_cast<int>(error_code), |
| 519 | static_cast<int>(ErrorCode::kUmaReportedMax)); |
| 520 | } |
| 521 | |
Marton Hunyady | ffbfdfb | 2018-05-30 13:03:29 +0200 | [diff] [blame] | 522 | void MetricsReporterOmaha::ReportKeyVersionMetrics( |
| 523 | int kernel_min_version, |
| 524 | int kernel_max_rollforward_version, |
| 525 | bool kernel_max_rollforward_success) { |
| 526 | int value = kernel_min_version; |
| 527 | string metric = metrics::kMetricKernelMinVersion; |
Marton Hunyady | ffbfdfb | 2018-05-30 13:03:29 +0200 | [diff] [blame] | 528 | metrics_lib_->SendSparseToUMA(metric, value); |
| 529 | |
| 530 | value = kernel_max_rollforward_version; |
| 531 | metric = metrics::kMetricKernelMaxRollforwardVersion; |
Marton Hunyady | ffbfdfb | 2018-05-30 13:03:29 +0200 | [diff] [blame] | 532 | metrics_lib_->SendSparseToUMA(metric, value); |
| 533 | |
| 534 | bool bool_value = kernel_max_rollforward_success; |
| 535 | metric = metrics::kMetricKernelMaxRollforwardSetSuccess; |
Marton Hunyady | ffbfdfb | 2018-05-30 13:03:29 +0200 | [diff] [blame] | 536 | metrics_lib_->SendBoolToUMA(metric, bool_value); |
| 537 | } |
| 538 | |
May Lippert | 60aa3ca | 2018-08-15 16:55:29 -0700 | [diff] [blame] | 539 | void MetricsReporterOmaha::ReportEnterpriseUpdateSeenToDownloadDays( |
| 540 | bool has_time_restriction_policy, int time_to_update_days) { |
| 541 | string metric = |
| 542 | has_time_restriction_policy |
| 543 | ? metrics::kMetricSuccessfulUpdateDurationFromSeenTimeRestrictedDays |
| 544 | : metrics::kMetricSuccessfulUpdateDurationFromSeenDays; |
May Lippert | 60aa3ca | 2018-08-15 16:55:29 -0700 | [diff] [blame] | 545 | |
| 546 | metrics_lib_->SendToUMA(metric, |
| 547 | time_to_update_days, |
| 548 | 1, // min: 1 days |
| 549 | 6 * 30, // max: 6 months (approx) |
| 550 | 50); // num_buckets |
| 551 | } |
| 552 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 553 | bool MetricsReporterOmaha::WallclockDurationHelper( |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 554 | const std::string& state_variable_key, |
| 555 | TimeDelta* out_duration) { |
| 556 | bool ret = false; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame^] | 557 | Time now = SystemState::Get()->clock()->GetWallclockTime(); |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 558 | int64_t stored_value; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame^] | 559 | if (SystemState::Get()->prefs()->GetInt64(state_variable_key, |
| 560 | &stored_value)) { |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 561 | Time stored_time = Time::FromInternalValue(stored_value); |
| 562 | if (stored_time > now) { |
| 563 | LOG(ERROR) << "Stored time-stamp used for " << state_variable_key |
| 564 | << " is in the future."; |
| 565 | } else { |
| 566 | *out_duration = now - stored_time; |
| 567 | ret = true; |
| 568 | } |
| 569 | } |
| 570 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame^] | 571 | if (!SystemState::Get()->prefs()->SetInt64(state_variable_key, |
| 572 | now.ToInternalValue())) { |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 573 | LOG(ERROR) << "Error storing time-stamp in " << state_variable_key; |
| 574 | } |
| 575 | |
| 576 | return ret; |
| 577 | } |
| 578 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame^] | 579 | bool MetricsReporterOmaha::MonotonicDurationHelper(int64_t* storage, |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 580 | TimeDelta* out_duration) { |
| 581 | bool ret = false; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame^] | 582 | Time now = SystemState::Get()->clock()->GetMonotonicTime(); |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 583 | if (*storage != 0) { |
| 584 | Time stored_time = Time::FromInternalValue(*storage); |
| 585 | *out_duration = now - stored_time; |
| 586 | ret = true; |
| 587 | } |
| 588 | *storage = now.ToInternalValue(); |
| 589 | |
| 590 | return ret; |
| 591 | } |
| 592 | |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 593 | } // namespace chromeos_update_engine |