| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "components/metrics/metrics_reporting_scheduler.h" | 5 #include "components/metrics/metrics_reporting_scheduler.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 // When uploading metrics to the server fails, we progressively wait longer and | 40 // When uploading metrics to the server fails, we progressively wait longer and |
| 41 // longer before sending the next log. This backoff process helps reduce load | 41 // longer before sending the next log. This backoff process helps reduce load |
| 42 // on a server that is having issues. | 42 // on a server that is having issues. |
| 43 // The following is the multiplier we use to expand that inter-log duration. | 43 // The following is the multiplier we use to expand that inter-log duration. |
| 44 const double kBackoffMultiplier = 1.1; | 44 const double kBackoffMultiplier = 1.1; |
| 45 | 45 |
| 46 // The maximum backoff multiplier. | 46 // The maximum backoff multiplier. |
| 47 const int kMaxBackoffMultiplier = 10; | 47 const int kMaxBackoffMultiplier = 10; |
| 48 | 48 |
| 49 enum InitSequence { | |
| 50 TIMER_FIRED_FIRST, | |
| 51 INIT_TASK_COMPLETED_FIRST, | |
| 52 INIT_SEQUENCE_ENUM_SIZE, | |
| 53 }; | |
| 54 | |
| 55 void LogMetricsInitSequence(InitSequence sequence) { | |
| 56 UMA_HISTOGRAM_ENUMERATION("UMA.InitSequence", sequence, | |
| 57 INIT_SEQUENCE_ENUM_SIZE); | |
| 58 } | |
| 59 | |
| 60 void LogActualUploadInterval(TimeDelta interval) { | |
| 61 UMA_HISTOGRAM_CUSTOM_COUNTS("UMA.ActualLogUploadInterval", | |
| 62 interval.InMinutes(), | |
| 63 1, | |
| 64 base::TimeDelta::FromHours(12).InMinutes(), | |
| 65 50); | |
| 66 } | |
| 67 | |
| 68 } // anonymous namespace | 49 } // anonymous namespace |
| 69 | 50 |
| 70 MetricsReportingScheduler::MetricsReportingScheduler( | 51 MetricsReportingScheduler::MetricsReportingScheduler( |
| 71 const base::Closure& upload_callback, | 52 const base::Closure& upload_callback, |
| 72 const base::Callback<base::TimeDelta(void)>& upload_interval_callback) | 53 const base::Callback<base::TimeDelta(void)>& upload_interval_callback) |
| 73 : upload_callback_(upload_callback), | 54 : upload_callback_(upload_callback), |
| 74 upload_interval_(TimeDelta::FromSeconds(kInitialUploadIntervalSeconds)), | 55 upload_interval_(TimeDelta::FromSeconds(kInitialUploadIntervalSeconds)), |
| 75 running_(false), | 56 running_(false), |
| 76 callback_pending_(false), | 57 callback_pending_(false), |
| 77 init_task_complete_(false), | 58 init_task_complete_(false), |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 callback_pending_ = false; | 110 callback_pending_ = false; |
| 130 if (running_) | 111 if (running_) |
| 131 ScheduleNextUpload(); | 112 ScheduleNextUpload(); |
| 132 } | 113 } |
| 133 | 114 |
| 134 void MetricsReportingScheduler::SetUploadIntervalForTesting( | 115 void MetricsReportingScheduler::SetUploadIntervalForTesting( |
| 135 base::TimeDelta interval) { | 116 base::TimeDelta interval) { |
| 136 upload_interval_ = interval; | 117 upload_interval_ = interval; |
| 137 } | 118 } |
| 138 | 119 |
| 120 void MetricsReportingScheduler::LogMetricsInitSequence(InitSequence sequence) { |
| 121 UMA_HISTOGRAM_ENUMERATION("UMA.InitSequence", sequence, |
| 122 INIT_SEQUENCE_ENUM_SIZE); |
| 123 } |
| 124 |
| 125 void MetricsReportingScheduler::LogActualUploadInterval(TimeDelta interval) { |
| 126 UMA_HISTOGRAM_CUSTOM_COUNTS("UMA.ActualLogUploadInterval", |
| 127 interval.InMinutes(), |
| 128 1, |
| 129 base::TimeDelta::FromHours(12).InMinutes(), |
| 130 50); |
| 131 } |
| 132 |
| 139 void MetricsReportingScheduler::TriggerUpload() { | 133 void MetricsReportingScheduler::TriggerUpload() { |
| 140 // If the timer fired before the init task has completed, don't trigger the | 134 // If the timer fired before the init task has completed, don't trigger the |
| 141 // upload yet - wait for the init task to complete and do it then. | 135 // upload yet - wait for the init task to complete and do it then. |
| 142 if (!init_task_complete_) { | 136 if (!init_task_complete_) { |
| 143 LogMetricsInitSequence(TIMER_FIRED_FIRST); | 137 LogMetricsInitSequence(TIMER_FIRED_FIRST); |
| 144 waiting_for_init_task_complete_ = true; | 138 waiting_for_init_task_complete_ = true; |
| 145 return; | 139 return; |
| 146 } | 140 } |
| 147 | 141 |
| 148 if (!last_upload_finish_time_.is_null()) { | 142 if (!last_upload_finish_time_.is_null()) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 172 if (upload_interval_ > max_interval || upload_interval_.InSeconds() < 0) { | 166 if (upload_interval_ > max_interval || upload_interval_.InSeconds() < 0) { |
| 173 upload_interval_ = max_interval; | 167 upload_interval_ = max_interval; |
| 174 } | 168 } |
| 175 } | 169 } |
| 176 | 170 |
| 177 base::TimeDelta MetricsReportingScheduler::GetStandardUploadInterval() { | 171 base::TimeDelta MetricsReportingScheduler::GetStandardUploadInterval() { |
| 178 return upload_interval_callback_.Run(); | 172 return upload_interval_callback_.Run(); |
| 179 } | 173 } |
| 180 | 174 |
| 181 } // namespace metrics | 175 } // namespace metrics |
| OLD | NEW |