OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // ReportingService specialized to report UMA metrics. | 5 // ReportingService specialized to report UMA metrics. |
6 | 6 |
7 #include "components/metrics/metrics_reporting_service.h" | 7 #include "components/metrics/metrics_reporting_service.h" |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
12 #include "components/metrics/metrics_pref_names.h" | 12 #include "components/metrics/metrics_pref_names.h" |
13 #include "components/metrics/persisted_logs_metrics_impl.h" | 13 #include "components/metrics/persisted_logs_metrics_impl.h" |
14 #include "components/metrics/url_constants.h" | 14 #include "components/metrics/url_constants.h" |
15 #include "components/prefs/pref_registry_simple.h" | 15 #include "components/prefs/pref_registry_simple.h" |
16 | 16 |
17 namespace metrics { | 17 namespace metrics { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // If an upload fails, and the transmission was over this byte count, then we | 21 // If an upload fails, and the transmission was over this byte count, then we |
22 // will discard the log, and not try to retransmit it. We also don't persist | 22 // will discard the log, and not try to retransmit it. We also don't persist |
23 // the log to the prefs for transmission during the next chrome session if this | 23 // the log to the prefs for transmission during the next chrome session if this |
24 // limit is exceeded. | 24 // limit is exceeded. |
25 const size_t kUploadLogAvoidRetransmitSize = 100 * 1024; | 25 const size_t kUploadLogAvoidRetransmitSize = 100 * 1024; |
26 | 26 |
27 enum ResponseStatus { | |
28 UNKNOWN_FAILURE, | |
29 SUCCESS, | |
30 BAD_REQUEST, // Invalid syntax or log too large. | |
31 NO_RESPONSE, | |
32 NUM_RESPONSE_STATUSES | |
33 }; | |
34 | |
35 ResponseStatus ResponseCodeToStatus(int response_code) { | |
36 switch (response_code) { | |
37 case -1: | |
38 return NO_RESPONSE; | |
39 case 200: | |
40 return SUCCESS; | |
41 case 400: | |
42 return BAD_REQUEST; | |
43 default: | |
44 return UNKNOWN_FAILURE; | |
45 } | |
46 } | |
47 | |
48 } // namespace | 27 } // namespace |
49 | 28 |
50 // static | 29 // static |
51 void MetricsReportingService::RegisterPrefs(PrefRegistrySimple* registry) { | 30 void MetricsReportingService::RegisterPrefs(PrefRegistrySimple* registry) { |
52 ReportingService::RegisterPrefs(registry); | 31 ReportingService::RegisterPrefs(registry); |
53 MetricsLogStore::RegisterPrefs(registry); | 32 MetricsLogStore::RegisterPrefs(registry); |
54 } | 33 } |
55 | 34 |
56 MetricsReportingService::MetricsReportingService(MetricsServiceClient* client, | 35 MetricsReportingService::MetricsReportingService(MetricsServiceClient* client, |
57 PrefService* local_state) | 36 PrefService* local_state) |
(...skipping 24 matching lines...) Expand all Loading... |
82 UMA_HISTOGRAM_CUSTOM_COUNTS("UMA.ActualLogUploadInterval", | 61 UMA_HISTOGRAM_CUSTOM_COUNTS("UMA.ActualLogUploadInterval", |
83 interval.InMinutes(), 1, | 62 interval.InMinutes(), 1, |
84 base::TimeDelta::FromHours(12).InMinutes(), 50); | 63 base::TimeDelta::FromHours(12).InMinutes(), 50); |
85 } | 64 } |
86 | 65 |
87 void MetricsReportingService::LogCellularConstraint(bool upload_canceled) { | 66 void MetricsReportingService::LogCellularConstraint(bool upload_canceled) { |
88 UMA_HISTOGRAM_BOOLEAN("UMA.LogUpload.Canceled.CellularConstraint", | 67 UMA_HISTOGRAM_BOOLEAN("UMA.LogUpload.Canceled.CellularConstraint", |
89 upload_canceled); | 68 upload_canceled); |
90 } | 69 } |
91 | 70 |
92 void MetricsReportingService::LogResponseCode(int response_code) { | 71 void MetricsReportingService::LogResponseOrErrorCode(int response_code, |
93 // Log a histogram to track response success vs. failure rates. | 72 int error_code) { |
94 UMA_HISTOGRAM_ENUMERATION("UMA.UploadResponseStatus.Protobuf", | 73 UMA_HISTOGRAM_SPARSE_SLOWLY("UMA.LogUpload.ResponseOrErrorCode", |
95 ResponseCodeToStatus(response_code), | 74 response_code >= 0 ? response_code : error_code); |
96 NUM_RESPONSE_STATUSES); | |
97 } | 75 } |
98 | 76 |
99 void MetricsReportingService::LogSuccess(size_t log_size) { | 77 void MetricsReportingService::LogSuccess(size_t log_size) { |
100 UMA_HISTOGRAM_COUNTS_10000("UMA.LogSize.OnSuccess", log_size / 1024); | 78 UMA_HISTOGRAM_COUNTS_10000("UMA.LogSize.OnSuccess", log_size / 1024); |
101 } | 79 } |
102 | 80 |
103 void MetricsReportingService::LogLargeRejection(size_t log_size) { | 81 void MetricsReportingService::LogLargeRejection(size_t log_size) { |
104 UMA_HISTOGRAM_COUNTS_1M("UMA.Large Rejected Log was Discarded", | 82 UMA_HISTOGRAM_COUNTS_1M("UMA.Large Rejected Log was Discarded", |
105 static_cast<int>(log_size)); | 83 static_cast<int>(log_size)); |
106 } | 84 } |
107 | 85 |
108 } // namespace metrics | 86 } // namespace metrics |
OLD | NEW |