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