metrics_reporter_omaha.cc 26 KB

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