Chromium Code Reviews| 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 "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 TIMER_FIRED_FIRST, | 55 TIMER_FIRED_FIRST, |
| 56 INIT_TASK_COMPLETED_FIRST, | 56 INIT_TASK_COMPLETED_FIRST, |
| 57 INIT_SEQUENCE_ENUM_SIZE, | 57 INIT_SEQUENCE_ENUM_SIZE, |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 void LogMetricsInitSequence(InitSequence sequence) { | 60 void LogMetricsInitSequence(InitSequence sequence) { |
| 61 UMA_HISTOGRAM_ENUMERATION("UMA.InitSequence", sequence, | 61 UMA_HISTOGRAM_ENUMERATION("UMA.InitSequence", sequence, |
| 62 INIT_SEQUENCE_ENUM_SIZE); | 62 INIT_SEQUENCE_ENUM_SIZE); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void LogActualUploadInterval(TimeDelta interval) { | |
| 66 UMA_HISTOGRAM_CUSTOM_COUNTS("UMA.ActualLogUploadInterval", | |
| 67 interval.InMinutes(), | |
| 68 1, | |
| 69 base::TimeDelta::FromHours(4).InMinutes(), | |
|
Alexei Svitkine (slow)
2014/10/15 20:44:19
Let's make this longer to ensure we catch any outl
gayane -on leave until 09-2017
2014/10/15 21:02:00
Done.
| |
| 70 100); | |
|
Alexei Svitkine (slow)
2014/10/15 20:44:19
Let's use 50 buckets - I'm not convinced we need 1
gayane -on leave until 09-2017
2014/10/15 21:02:00
Done.
| |
| 71 } | |
| 72 | |
| 65 // Returns upload interval specified for the current experiment running. | 73 // Returns upload interval specified for the current experiment running. |
| 66 // TODO(gayane): Only for experimenting with upload interval for Android | 74 // TODO(gayane): Only for experimenting with upload interval for Android |
| 67 // (bug: 17391128). Should be removed once the experiments are done. | 75 // (bug: 17391128). Should be removed once the experiments are done. |
| 68 base::TimeDelta GetUploadIntervalFromExperiment() { | 76 base::TimeDelta GetUploadIntervalFromExperiment() { |
| 69 std::string interval_str = variations::GetVariationParamValue( | 77 std::string interval_str = variations::GetVariationParamValue( |
| 70 "UMALogUploadInterval", "interval"); | 78 "UMALogUploadInterval", "interval"); |
| 71 int interval; | 79 int interval; |
| 72 if (interval_str.empty() || !base::StringToInt(interval_str, &interval)) | 80 if (interval_str.empty() || !base::StringToInt(interval_str, &interval)) |
| 73 return TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); | 81 return TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); |
| 74 | 82 |
| 75 return TimeDelta::FromMinutes(interval); | 83 return TimeDelta::FromMinutes(interval); |
| 76 } | 84 } |
| 77 | 85 |
| 78 } // anonymous namespace | 86 } // anonymous namespace |
| 79 | 87 |
| 80 MetricsReportingScheduler::MetricsReportingScheduler( | 88 MetricsReportingScheduler::MetricsReportingScheduler( |
| 81 const base::Closure& upload_callback) | 89 const base::Closure& upload_callback) |
| 82 : upload_callback_(upload_callback), | 90 : upload_callback_(upload_callback), |
| 83 upload_interval_(TimeDelta::FromSeconds(kInitialUploadIntervalSeconds)), | 91 upload_interval_(TimeDelta::FromSeconds(kInitialUploadIntervalSeconds)), |
| 92 last_upload_finish_time_(), | |
|
Alexei Svitkine (slow)
2014/10/15 20:44:19
This line is not necessary if there's a default ct
gayane -on leave until 09-2017
2014/10/15 21:02:00
Done.
| |
| 84 running_(false), | 93 running_(false), |
| 85 callback_pending_(false), | 94 callback_pending_(false), |
| 86 init_task_complete_(false), | 95 init_task_complete_(false), |
| 87 waiting_for_init_task_complete_(false) { | 96 waiting_for_init_task_complete_(false) { |
| 88 } | 97 } |
| 89 | 98 |
| 90 MetricsReportingScheduler::~MetricsReportingScheduler() {} | 99 MetricsReportingScheduler::~MetricsReportingScheduler() {} |
| 91 | 100 |
| 92 void MetricsReportingScheduler::Start() { | 101 void MetricsReportingScheduler::Start() { |
| 93 GetUploadIntervalFromExperiment(); | 102 GetUploadIntervalFromExperiment(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 119 callback_pending_ = false; | 128 callback_pending_ = false; |
| 120 // If the server is having issues, back off. Otherwise, reset to default | 129 // If the server is having issues, back off. Otherwise, reset to default |
| 121 // (unless there are more logs to send, in which case the next upload should | 130 // (unless there are more logs to send, in which case the next upload should |
| 122 // happen sooner). | 131 // happen sooner). |
| 123 if (!server_is_healthy) { | 132 if (!server_is_healthy) { |
| 124 BackOffUploadInterval(); | 133 BackOffUploadInterval(); |
| 125 } else if (more_logs_remaining) { | 134 } else if (more_logs_remaining) { |
| 126 upload_interval_ = TimeDelta::FromSeconds(kUnsentLogsIntervalSeconds); | 135 upload_interval_ = TimeDelta::FromSeconds(kUnsentLogsIntervalSeconds); |
| 127 } else { | 136 } else { |
| 128 upload_interval_ = GetStandardUploadInterval(); | 137 upload_interval_ = GetStandardUploadInterval(); |
| 138 last_upload_finish_time_ = base::TimeTicks::Now(); | |
| 129 } | 139 } |
| 130 | 140 |
| 131 if (running_) | 141 if (running_) |
| 132 ScheduleNextUpload(); | 142 ScheduleNextUpload(); |
| 133 } | 143 } |
| 134 | 144 |
| 135 void MetricsReportingScheduler::UploadCancelled() { | 145 void MetricsReportingScheduler::UploadCancelled() { |
| 136 DCHECK(callback_pending_); | 146 DCHECK(callback_pending_); |
| 137 callback_pending_ = false; | 147 callback_pending_ = false; |
| 138 if (running_) | 148 if (running_) |
| 139 ScheduleNextUpload(); | 149 ScheduleNextUpload(); |
| 140 } | 150 } |
| 141 | 151 |
| 142 void MetricsReportingScheduler::SetUploadIntervalForTesting( | 152 void MetricsReportingScheduler::SetUploadIntervalForTesting( |
| 143 base::TimeDelta interval) { | 153 base::TimeDelta interval) { |
| 144 upload_interval_ = interval; | 154 upload_interval_ = interval; |
| 145 } | 155 } |
| 146 | 156 |
| 147 void MetricsReportingScheduler::TriggerUpload() { | 157 void MetricsReportingScheduler::TriggerUpload() { |
| 148 // If the timer fired before the init task has completed, don't trigger the | 158 // If the timer fired before the init task has completed, don't trigger the |
| 149 // upload yet - wait for the init task to complete and do it then. | 159 // upload yet - wait for the init task to complete and do it then. |
| 150 if (!init_task_complete_) { | 160 if (!init_task_complete_) { |
| 151 LogMetricsInitSequence(TIMER_FIRED_FIRST); | 161 LogMetricsInitSequence(TIMER_FIRED_FIRST); |
| 152 waiting_for_init_task_complete_ = true; | 162 waiting_for_init_task_complete_ = true; |
| 153 return; | 163 return; |
| 154 } | 164 } |
| 165 | |
| 166 if (!last_upload_finish_time_.is_null()) { | |
| 167 LogActualUploadInterval(base::TimeTicks::Now() - last_upload_finish_time_); | |
| 168 last_upload_finish_time_.FromInternalValue(0); | |
|
Alexei Svitkine (slow)
2014/10/15 20:44:19
FromInternalValue is a static method that returns
gayane -on leave until 09-2017
2014/10/15 21:02:00
Done.
| |
| 169 } | |
| 170 | |
| 155 callback_pending_ = true; | 171 callback_pending_ = true; |
| 156 upload_callback_.Run(); | 172 upload_callback_.Run(); |
| 157 } | 173 } |
| 158 | 174 |
| 159 void MetricsReportingScheduler::ScheduleNextUpload() { | 175 void MetricsReportingScheduler::ScheduleNextUpload() { |
| 160 DCHECK(running_); | 176 DCHECK(running_); |
| 161 if (upload_timer_.IsRunning() || callback_pending_) | 177 if (upload_timer_.IsRunning() || callback_pending_) |
| 162 return; | 178 return; |
| 163 | 179 |
| 164 upload_timer_.Start(FROM_HERE, upload_interval_, this, | 180 upload_timer_.Start(FROM_HERE, upload_interval_, this, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 179 | 195 |
| 180 base::TimeDelta MetricsReportingScheduler::GetStandardUploadInterval() { | 196 base::TimeDelta MetricsReportingScheduler::GetStandardUploadInterval() { |
| 181 #if defined(OS_ANDROID) | 197 #if defined(OS_ANDROID) |
| 182 return GetUploadIntervalFromExperiment(); | 198 return GetUploadIntervalFromExperiment(); |
| 183 #else | 199 #else |
| 184 return TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); | 200 return TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); |
| 185 #endif | 201 #endif |
| 186 } | 202 } |
| 187 | 203 |
| 188 } // namespace metrics | 204 } // namespace metrics |
| OLD | NEW |