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