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( |
| 158 | SystemState* system_state, |
| 159 | metrics::CheckResult result, |
| 160 | metrics::CheckReaction reaction, |
| 161 | metrics::DownloadErrorCode download_error_code) { |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 162 | string metric; |
| 163 | int value; |
| 164 | int max_value; |
| 165 | |
| 166 | if (result != metrics::CheckResult::kUnset) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 167 | metric = metrics::kMetricCheckResult; |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 168 | value = static_cast<int>(result); |
| 169 | max_value = static_cast<int>(metrics::CheckResult::kNumConstants) - 1; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 170 | metrics_lib_->SendEnumToUMA(metric, value, max_value); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 171 | } |
| 172 | if (reaction != metrics::CheckReaction::kUnset) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 173 | metric = metrics::kMetricCheckReaction; |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 174 | value = static_cast<int>(reaction); |
| 175 | max_value = static_cast<int>(metrics::CheckReaction::kNumConstants) - 1; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 176 | metrics_lib_->SendEnumToUMA(metric, value, max_value); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 177 | } |
| 178 | if (download_error_code != metrics::DownloadErrorCode::kUnset) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 179 | metric = metrics::kMetricCheckDownloadErrorCode; |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 180 | value = static_cast<int>(download_error_code); |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 181 | metrics_lib_->SendSparseToUMA(metric, value); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | base::TimeDelta time_since_last; |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame^] | 185 | if (WallclockDurationHelper(system_state, |
| 186 | kPrefsMetricsCheckLastReportingTime, |
| 187 | &time_since_last)) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 188 | metric = metrics::kMetricCheckTimeSinceLastCheckMinutes; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 189 | metrics_lib_->SendToUMA(metric, |
| 190 | time_since_last.InMinutes(), |
| 191 | 0, // min: 0 min |
| 192 | 30 * 24 * 60, // max: 30 days |
| 193 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | base::TimeDelta uptime_since_last; |
| 197 | static int64_t uptime_since_last_storage = 0; |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame^] | 198 | if (MonotonicDurationHelper( |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 199 | system_state, &uptime_since_last_storage, &uptime_since_last)) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 200 | metric = metrics::kMetricCheckTimeSinceLastCheckUptimeMinutes; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 201 | metrics_lib_->SendToUMA(metric, |
| 202 | uptime_since_last.InMinutes(), |
| 203 | 0, // min: 0 min |
| 204 | 30 * 24 * 60, // max: 30 days |
| 205 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 206 | } |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 207 | |
| 208 | // First section of target version specified for the update. |
| 209 | if (system_state && system_state->request_params()) { |
| 210 | string target_version = |
| 211 | system_state->request_params()->target_version_prefix(); |
| 212 | value = utils::VersionPrefix(target_version); |
| 213 | if (value != 0) { |
| 214 | metric = metrics::kMetricCheckTargetVersion; |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 215 | metrics_lib_->SendSparseToUMA(metric, value); |
| 216 | if (system_state->request_params()->rollback_allowed()) { |
| 217 | metric = metrics::kMetricCheckRollbackTargetVersion; |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 218 | metrics_lib_->SendSparseToUMA(metric, value); |
| 219 | } |
| 220 | } |
| 221 | } |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 222 | } |
| 223 | |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 224 | void MetricsReporterOmaha::ReportAbnormallyTerminatedUpdateAttemptMetrics() { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 225 | string metric = metrics::kMetricAttemptResult; |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 226 | metrics::AttemptResult attempt_result = |
| 227 | metrics::AttemptResult::kAbnormalTermination; |
David Zeuthen | 4e1d149 | 2014-04-25 13:12:27 -0700 | [diff] [blame] | 228 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 229 | metrics_lib_->SendEnumToUMA( |
David Zeuthen | 4e1d149 | 2014-04-25 13:12:27 -0700 | [diff] [blame] | 230 | metric, |
| 231 | static_cast<int>(attempt_result), |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 232 | static_cast<int>(metrics::AttemptResult::kNumConstants)); |
David Zeuthen | 4e1d149 | 2014-04-25 13:12:27 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 235 | void MetricsReporterOmaha::ReportUpdateAttemptMetrics( |
| 236 | SystemState* system_state, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 237 | int attempt_number, |
| 238 | PayloadType payload_type, |
| 239 | base::TimeDelta duration, |
| 240 | base::TimeDelta duration_uptime, |
| 241 | int64_t payload_size, |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 242 | metrics::AttemptResult attempt_result, |
Tianjie Xu | 1f93d09 | 2017-10-09 12:13:29 -0700 | [diff] [blame] | 243 | ErrorCode internal_error_code) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 244 | string metric = metrics::kMetricAttemptNumber; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 245 | metrics_lib_->SendToUMA(metric, |
| 246 | attempt_number, |
| 247 | 0, // min: 0 attempts |
| 248 | 49, // max: 49 attempts |
| 249 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 250 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 251 | metric = metrics::kMetricAttemptPayloadType; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 252 | metrics_lib_->SendEnumToUMA(metric, payload_type, kNumPayloadTypes); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 253 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 254 | metric = metrics::kMetricAttemptDurationMinutes; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 255 | metrics_lib_->SendToUMA(metric, |
| 256 | duration.InMinutes(), |
| 257 | 0, // min: 0 min |
| 258 | 10 * 24 * 60, // max: 10 days |
| 259 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 260 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 261 | metric = metrics::kMetricAttemptDurationUptimeMinutes; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 262 | metrics_lib_->SendToUMA(metric, |
| 263 | duration_uptime.InMinutes(), |
| 264 | 0, // min: 0 min |
| 265 | 10 * 24 * 60, // max: 10 days |
| 266 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 267 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 268 | metric = metrics::kMetricAttemptPayloadSizeMiB; |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 269 | int64_t payload_size_mib = payload_size / kNumBytesInOneMiB; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 270 | metrics_lib_->SendToUMA(metric, |
| 271 | payload_size_mib, |
| 272 | 0, // min: 0 MiB |
| 273 | 1024, // max: 1024 MiB = 1 GiB |
| 274 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 275 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 276 | metric = metrics::kMetricAttemptResult; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 277 | metrics_lib_->SendEnumToUMA( |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 278 | metric, |
| 279 | static_cast<int>(attempt_result), |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 280 | static_cast<int>(metrics::AttemptResult::kNumConstants)); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 281 | |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 282 | if (internal_error_code != ErrorCode::kSuccess) { |
Amin Hassani | 80f4d4c | 2018-05-16 13:34:00 -0700 | [diff] [blame] | 283 | ReportInternalErrorCode(internal_error_code); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 284 | } |
| 285 | |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 286 | base::TimeDelta time_since_last; |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame^] | 287 | if (WallclockDurationHelper(system_state, |
| 288 | kPrefsMetricsAttemptLastReportingTime, |
| 289 | &time_since_last)) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 290 | metric = metrics::kMetricAttemptTimeSinceLastAttemptMinutes; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 291 | metrics_lib_->SendToUMA(metric, |
| 292 | time_since_last.InMinutes(), |
| 293 | 0, // min: 0 min |
| 294 | 30 * 24 * 60, // max: 30 days |
| 295 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | static int64_t uptime_since_last_storage = 0; |
| 299 | base::TimeDelta uptime_since_last; |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame^] | 300 | if (MonotonicDurationHelper( |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 301 | system_state, &uptime_since_last_storage, &uptime_since_last)) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 302 | metric = metrics::kMetricAttemptTimeSinceLastAttemptUptimeMinutes; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 303 | metrics_lib_->SendToUMA(metric, |
| 304 | uptime_since_last.InMinutes(), |
| 305 | 0, // min: 0 min |
| 306 | 30 * 24 * 60, // max: 30 days |
| 307 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 308 | } |
Tianjie Xu | 1f93d09 | 2017-10-09 12:13:29 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | void MetricsReporterOmaha::ReportUpdateAttemptDownloadMetrics( |
| 312 | int64_t payload_bytes_downloaded, |
| 313 | int64_t payload_download_speed_bps, |
| 314 | DownloadSource download_source, |
| 315 | metrics::DownloadErrorCode payload_download_error_code, |
| 316 | metrics::ConnectionType connection_type) { |
| 317 | string metric = metrics::kMetricAttemptPayloadBytesDownloadedMiB; |
| 318 | int64_t payload_bytes_downloaded_mib = |
| 319 | payload_bytes_downloaded / kNumBytesInOneMiB; |
Tianjie Xu | 1f93d09 | 2017-10-09 12:13:29 -0700 | [diff] [blame] | 320 | metrics_lib_->SendToUMA(metric, |
| 321 | payload_bytes_downloaded_mib, |
| 322 | 0, // min: 0 MiB |
| 323 | 1024, // max: 1024 MiB = 1 GiB |
| 324 | 50); // num_buckets |
| 325 | |
| 326 | metric = metrics::kMetricAttemptPayloadDownloadSpeedKBps; |
| 327 | int64_t payload_download_speed_kbps = payload_download_speed_bps / 1000; |
Tianjie Xu | 1f93d09 | 2017-10-09 12:13:29 -0700 | [diff] [blame] | 328 | metrics_lib_->SendToUMA(metric, |
| 329 | payload_download_speed_kbps, |
| 330 | 0, // min: 0 kB/s |
| 331 | 10 * 1000, // max: 10000 kB/s = 10 MB/s |
| 332 | 50); // num_buckets |
| 333 | |
| 334 | metric = metrics::kMetricAttemptDownloadSource; |
Tianjie Xu | 1f93d09 | 2017-10-09 12:13:29 -0700 | [diff] [blame] | 335 | metrics_lib_->SendEnumToUMA(metric, download_source, kNumDownloadSources); |
| 336 | |
| 337 | if (payload_download_error_code != metrics::DownloadErrorCode::kUnset) { |
| 338 | metric = metrics::kMetricAttemptDownloadErrorCode; |
Tianjie Xu | 1f93d09 | 2017-10-09 12:13:29 -0700 | [diff] [blame] | 339 | metrics_lib_->SendSparseToUMA( |
| 340 | metric, static_cast<int>(payload_download_error_code)); |
| 341 | } |
David Zeuthen | b281f07 | 2014-04-02 10:20:19 -0700 | [diff] [blame] | 342 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 343 | metric = metrics::kMetricAttemptConnectionType; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 344 | metrics_lib_->SendEnumToUMA( |
David Zeuthen | b281f07 | 2014-04-02 10:20:19 -0700 | [diff] [blame] | 345 | metric, |
| 346 | static_cast<int>(connection_type), |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 347 | static_cast<int>(metrics::ConnectionType::kNumConstants)); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 348 | } |
| 349 | |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 350 | void MetricsReporterOmaha::ReportSuccessfulUpdateMetrics( |
| 351 | int attempt_count, |
| 352 | int updates_abandoned_count, |
| 353 | PayloadType payload_type, |
| 354 | int64_t payload_size, |
| 355 | int64_t num_bytes_downloaded[kNumDownloadSources], |
| 356 | int download_overhead_percentage, |
| 357 | base::TimeDelta total_duration, |
Sen Jiang | 8712e96 | 2018-05-08 12:12:28 -0700 | [diff] [blame] | 358 | base::TimeDelta total_duration_uptime, |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 359 | int reboot_count, |
| 360 | int url_switch_count) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 361 | string metric = metrics::kMetricSuccessfulUpdatePayloadSizeMiB; |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 362 | int64_t mbs = payload_size / kNumBytesInOneMiB; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 363 | metrics_lib_->SendToUMA(metric, |
| 364 | mbs, |
| 365 | 0, // min: 0 MiB |
| 366 | 1024, // max: 1024 MiB = 1 GiB |
| 367 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 368 | |
| 369 | int64_t total_bytes = 0; |
| 370 | int download_sources_used = 0; |
| 371 | for (int i = 0; i < kNumDownloadSources + 1; i++) { |
| 372 | DownloadSource source = static_cast<DownloadSource>(i); |
| 373 | |
| 374 | // Only consider this download source (and send byte counts) as |
| 375 | // having been used if we downloaded a non-trivial amount of bytes |
Alex Vakulenko | 072359c | 2014-07-18 11:41:07 -0700 | [diff] [blame] | 376 | // (e.g. at least 1 MiB) that contributed to the |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 377 | // update. Otherwise we're going to end up with a lot of zero-byte |
| 378 | // events in the histogram. |
| 379 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 380 | metric = metrics::kMetricSuccessfulUpdateBytesDownloadedMiB; |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 381 | if (i < kNumDownloadSources) { |
| 382 | metric += utils::ToString(source); |
| 383 | mbs = num_bytes_downloaded[i] / kNumBytesInOneMiB; |
| 384 | total_bytes += num_bytes_downloaded[i]; |
| 385 | if (mbs > 0) |
| 386 | download_sources_used |= (1 << i); |
| 387 | } else { |
| 388 | mbs = total_bytes / kNumBytesInOneMiB; |
| 389 | } |
| 390 | |
| 391 | if (mbs > 0) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 392 | metrics_lib_->SendToUMA(metric, |
| 393 | mbs, |
| 394 | 0, // min: 0 MiB |
| 395 | 1024, // max: 1024 MiB = 1 GiB |
| 396 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 397 | } |
| 398 | } |
| 399 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 400 | metric = metrics::kMetricSuccessfulUpdateDownloadSourcesUsed; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 401 | metrics_lib_->SendToUMA(metric, |
| 402 | download_sources_used, |
| 403 | 0, // min |
| 404 | (1 << kNumDownloadSources) - 1, // max |
| 405 | 1 << kNumDownloadSources); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 406 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 407 | metric = metrics::kMetricSuccessfulUpdateDownloadOverheadPercentage; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 408 | metrics_lib_->SendToUMA(metric, |
| 409 | download_overhead_percentage, |
| 410 | 0, // min: 0% overhead |
| 411 | 1000, // max: 1000% overhead |
| 412 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 413 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 414 | metric = metrics::kMetricSuccessfulUpdateUrlSwitchCount; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 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 Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 420 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 421 | metric = metrics::kMetricSuccessfulUpdateTotalDurationMinutes; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 422 | metrics_lib_->SendToUMA(metric, |
| 423 | static_cast<int>(total_duration.InMinutes()), |
| 424 | 0, // min: 0 min |
| 425 | 365 * 24 * 60, // max: 365 days ~= 1 year |
| 426 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 427 | |
Sen Jiang | 8712e96 | 2018-05-08 12:12:28 -0700 | [diff] [blame] | 428 | metric = metrics::kMetricSuccessfulUpdateTotalDurationUptimeMinutes; |
Sen Jiang | 8712e96 | 2018-05-08 12:12:28 -0700 | [diff] [blame] | 429 | metrics_lib_->SendToUMA(metric, |
| 430 | static_cast<int>(total_duration_uptime.InMinutes()), |
| 431 | 0, // min: 0 min |
| 432 | 30 * 24 * 60, // max: 30 days |
| 433 | 50); // num_buckets |
| 434 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 435 | metric = metrics::kMetricSuccessfulUpdateRebootCount; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 436 | metrics_lib_->SendToUMA(metric, |
| 437 | reboot_count, |
| 438 | 0, // min: 0 reboots |
| 439 | 49, // max: 49 reboots |
| 440 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 441 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 442 | metric = metrics::kMetricSuccessfulUpdatePayloadType; |
| 443 | metrics_lib_->SendEnumToUMA(metric, payload_type, kNumPayloadTypes); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 444 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 445 | metric = metrics::kMetricSuccessfulUpdateAttemptCount; |
| 446 | metrics_lib_->SendToUMA(metric, |
| 447 | attempt_count, |
| 448 | 1, // min: 1 attempt |
| 449 | 50, // max: 50 attempts |
| 450 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 451 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 452 | metric = metrics::kMetricSuccessfulUpdateUpdatesAbandonedCount; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 453 | metrics_lib_->SendToUMA(metric, |
| 454 | updates_abandoned_count, |
| 455 | 0, // min: 0 counts |
| 456 | 49, // max: 49 counts |
| 457 | 50); // num_buckets |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 458 | } |
| 459 | |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 460 | void MetricsReporterOmaha::ReportRollbackMetrics( |
| 461 | metrics::RollbackResult result) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 462 | string metric = metrics::kMetricRollbackResult; |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 463 | int value = static_cast<int>(result); |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 464 | metrics_lib_->SendEnumToUMA( |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 465 | metric, value, static_cast<int>(metrics::RollbackResult::kNumConstants)); |
David Zeuthen | 96197df | 2014-04-16 12:22:39 -0700 | [diff] [blame] | 466 | } |
| 467 | |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 468 | void MetricsReporterOmaha::ReportEnterpriseRollbackMetrics( |
| 469 | bool success, const string& rollback_version) { |
| 470 | int value = utils::VersionPrefix(rollback_version); |
| 471 | string metric = metrics::kMetricEnterpriseRollbackSuccess; |
| 472 | if (!success) |
| 473 | metric = metrics::kMetricEnterpriseRollbackFailure; |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 474 | metrics_lib_->SendSparseToUMA(metric, value); |
| 475 | } |
| 476 | |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 477 | void MetricsReporterOmaha::ReportCertificateCheckMetrics( |
| 478 | ServerToCheck server_to_check, CertificateCheckResult result) { |
Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 479 | string metric; |
| 480 | switch (server_to_check) { |
| 481 | case ServerToCheck::kUpdate: |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 482 | metric = metrics::kMetricCertificateCheckUpdateCheck; |
Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 483 | break; |
| 484 | case ServerToCheck::kDownload: |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 485 | metric = metrics::kMetricCertificateCheckDownload; |
Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 486 | break; |
Alex Deymo | 33e91e7 | 2015-12-01 18:26:08 -0300 | [diff] [blame] | 487 | case ServerToCheck::kNone: |
| 488 | return; |
Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 489 | } |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 490 | metrics_lib_->SendEnumToUMA( |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 491 | metric, |
| 492 | static_cast<int>(result), |
Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 493 | static_cast<int>(CertificateCheckResult::kNumConstants)); |
| 494 | } |
| 495 | |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 496 | void MetricsReporterOmaha::ReportFailedUpdateCount(int target_attempt) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 497 | string metric = metrics::kMetricFailedUpdateCount; |
| 498 | metrics_lib_->SendToUMA(metric, |
| 499 | target_attempt, |
| 500 | 1, // min value |
| 501 | 50, // max value |
| 502 | kNumDefaultUmaBuckets); |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | void MetricsReporterOmaha::ReportTimeToReboot(int time_to_reboot_minutes) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 506 | string metric = metrics::kMetricTimeToRebootMinutes; |
| 507 | metrics_lib_->SendToUMA(metric, |
| 508 | time_to_reboot_minutes, |
| 509 | 0, // min: 0 minute |
| 510 | 30 * 24 * 60, // max: 1 month (approx) |
| 511 | kNumDefaultUmaBuckets); |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | void MetricsReporterOmaha::ReportInstallDateProvisioningSource(int source, |
| 515 | int max) { |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 516 | metrics_lib_->SendEnumToUMA(metrics::kMetricInstallDateProvisioningSource, |
| 517 | source, // Sample. |
| 518 | max); |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 519 | } |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 520 | |
Amin Hassani | 80f4d4c | 2018-05-16 13:34:00 -0700 | [diff] [blame] | 521 | void MetricsReporterOmaha::ReportInternalErrorCode(ErrorCode error_code) { |
| 522 | auto metric = metrics::kMetricAttemptInternalErrorCode; |
Amin Hassani | 80f4d4c | 2018-05-16 13:34:00 -0700 | [diff] [blame] | 523 | metrics_lib_->SendEnumToUMA(metric, |
| 524 | static_cast<int>(error_code), |
| 525 | static_cast<int>(ErrorCode::kUmaReportedMax)); |
| 526 | } |
| 527 | |
Marton Hunyady | ffbfdfb | 2018-05-30 13:03:29 +0200 | [diff] [blame] | 528 | void MetricsReporterOmaha::ReportKeyVersionMetrics( |
| 529 | int kernel_min_version, |
| 530 | int kernel_max_rollforward_version, |
| 531 | bool kernel_max_rollforward_success) { |
| 532 | int value = kernel_min_version; |
| 533 | string metric = metrics::kMetricKernelMinVersion; |
Marton Hunyady | ffbfdfb | 2018-05-30 13:03:29 +0200 | [diff] [blame] | 534 | metrics_lib_->SendSparseToUMA(metric, value); |
| 535 | |
| 536 | value = kernel_max_rollforward_version; |
| 537 | metric = metrics::kMetricKernelMaxRollforwardVersion; |
Marton Hunyady | ffbfdfb | 2018-05-30 13:03:29 +0200 | [diff] [blame] | 538 | metrics_lib_->SendSparseToUMA(metric, value); |
| 539 | |
| 540 | bool bool_value = kernel_max_rollforward_success; |
| 541 | metric = metrics::kMetricKernelMaxRollforwardSetSuccess; |
Marton Hunyady | ffbfdfb | 2018-05-30 13:03:29 +0200 | [diff] [blame] | 542 | metrics_lib_->SendBoolToUMA(metric, bool_value); |
| 543 | } |
| 544 | |
May Lippert | 60aa3ca | 2018-08-15 16:55:29 -0700 | [diff] [blame] | 545 | void MetricsReporterOmaha::ReportEnterpriseUpdateSeenToDownloadDays( |
| 546 | bool has_time_restriction_policy, int time_to_update_days) { |
| 547 | string metric = |
| 548 | has_time_restriction_policy |
| 549 | ? metrics::kMetricSuccessfulUpdateDurationFromSeenTimeRestrictedDays |
| 550 | : metrics::kMetricSuccessfulUpdateDurationFromSeenDays; |
May Lippert | 60aa3ca | 2018-08-15 16:55:29 -0700 | [diff] [blame] | 551 | |
| 552 | metrics_lib_->SendToUMA(metric, |
| 553 | time_to_update_days, |
| 554 | 1, // min: 1 days |
| 555 | 6 * 30, // max: 6 months (approx) |
| 556 | 50); // num_buckets |
| 557 | } |
| 558 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame^] | 559 | bool MetricsReporterOmaha::WallclockDurationHelper( |
| 560 | SystemState* system_state, |
| 561 | const std::string& state_variable_key, |
| 562 | TimeDelta* out_duration) { |
| 563 | bool ret = false; |
| 564 | Time now = system_state->clock()->GetWallclockTime(); |
| 565 | int64_t stored_value; |
| 566 | if (system_state->prefs()->GetInt64(state_variable_key, &stored_value)) { |
| 567 | Time stored_time = Time::FromInternalValue(stored_value); |
| 568 | if (stored_time > now) { |
| 569 | LOG(ERROR) << "Stored time-stamp used for " << state_variable_key |
| 570 | << " is in the future."; |
| 571 | } else { |
| 572 | *out_duration = now - stored_time; |
| 573 | ret = true; |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | if (!system_state->prefs()->SetInt64(state_variable_key, |
| 578 | now.ToInternalValue())) { |
| 579 | LOG(ERROR) << "Error storing time-stamp in " << state_variable_key; |
| 580 | } |
| 581 | |
| 582 | return ret; |
| 583 | } |
| 584 | |
| 585 | bool MetricsReporterOmaha::MonotonicDurationHelper(SystemState* system_state, |
| 586 | int64_t* storage, |
| 587 | TimeDelta* out_duration) { |
| 588 | bool ret = false; |
| 589 | Time now = system_state->clock()->GetMonotonicTime(); |
| 590 | if (*storage != 0) { |
| 591 | Time stored_time = Time::FromInternalValue(*storage); |
| 592 | *out_duration = now - stored_time; |
| 593 | ret = true; |
| 594 | } |
| 595 | *storage = now.ToInternalValue(); |
| 596 | |
| 597 | return ret; |
| 598 | } |
| 599 | |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 600 | } // namespace chromeos_update_engine |