Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(979)

Side by Side Diff: components/metrics/metrics_reporting_scheduler.cc

Issue 1871733002: Add histograms for observing UMA throttling effect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 TIMER_FIRED_FIRST, 50 TIMER_FIRED_FIRST,
51 INIT_TASK_COMPLETED_FIRST, 51 INIT_TASK_COMPLETED_FIRST,
52 INIT_SEQUENCE_ENUM_SIZE, 52 INIT_SEQUENCE_ENUM_SIZE,
53 }; 53 };
54 54
55 void LogMetricsInitSequence(InitSequence sequence) { 55 void LogMetricsInitSequence(InitSequence sequence) {
56 UMA_HISTOGRAM_ENUMERATION("UMA.InitSequence", sequence, 56 UMA_HISTOGRAM_ENUMERATION("UMA.InitSequence", sequence,
57 INIT_SEQUENCE_ENUM_SIZE); 57 INIT_SEQUENCE_ENUM_SIZE);
58 } 58 }
59 59
60 void LogActualUploadInterval(TimeDelta interval) {
61 UMA_HISTOGRAM_CUSTOM_COUNTS("UMA.ActualLogUploadInterval",
Alexei Svitkine (slow) 2016/04/08 20:07:12 I'm not convinced we should stop logging this yet.
gayane -on leave until 09-2017 2016/04/08 20:40:14 Done.
62 interval.InMinutes(),
63 1,
64 base::TimeDelta::FromHours(12).InMinutes(),
65 50);
66 }
67
68 } // anonymous namespace 60 } // anonymous namespace
69 61
70 MetricsReportingScheduler::MetricsReportingScheduler( 62 MetricsReportingScheduler::MetricsReportingScheduler(
71 const base::Closure& upload_callback, 63 const base::Closure& upload_callback,
72 const base::Callback<base::TimeDelta(void)>& upload_interval_callback) 64 const base::Callback<base::TimeDelta(void)>& upload_interval_callback)
73 : upload_callback_(upload_callback), 65 : upload_callback_(upload_callback),
74 upload_interval_(TimeDelta::FromSeconds(kInitialUploadIntervalSeconds)), 66 upload_interval_(TimeDelta::FromSeconds(kInitialUploadIntervalSeconds)),
75 running_(false), 67 running_(false),
76 callback_pending_(false), 68 callback_pending_(false),
77 init_task_complete_(false), 69 init_task_complete_(false),
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 callback_pending_ = false; 102 callback_pending_ = false;
111 // If the server is having issues, back off. Otherwise, reset to default 103 // If the server is having issues, back off. Otherwise, reset to default
112 // (unless there are more logs to send, in which case the next upload should 104 // (unless there are more logs to send, in which case the next upload should
113 // happen sooner). 105 // happen sooner).
114 if (!server_is_healthy) { 106 if (!server_is_healthy) {
115 BackOffUploadInterval(); 107 BackOffUploadInterval();
116 } else if (more_logs_remaining) { 108 } else if (more_logs_remaining) {
117 upload_interval_ = TimeDelta::FromSeconds(kUnsentLogsIntervalSeconds); 109 upload_interval_ = TimeDelta::FromSeconds(kUnsentLogsIntervalSeconds);
118 } else { 110 } else {
119 upload_interval_ = GetStandardUploadInterval(); 111 upload_interval_ = GetStandardUploadInterval();
120 last_upload_finish_time_ = base::TimeTicks::Now();
121 } 112 }
122 113
123 if (running_) 114 if (running_)
124 ScheduleNextUpload(); 115 ScheduleNextUpload();
125 } 116 }
126 117
127 void MetricsReportingScheduler::UploadCancelled() { 118 void MetricsReportingScheduler::UploadCancelled() {
128 DCHECK(callback_pending_); 119 DCHECK(callback_pending_);
129 callback_pending_ = false; 120 callback_pending_ = false;
130 if (running_) 121 if (running_)
131 ScheduleNextUpload(); 122 ScheduleNextUpload();
132 } 123 }
133 124
134 void MetricsReportingScheduler::SetUploadIntervalForTesting( 125 void MetricsReportingScheduler::SetUploadIntervalForTesting(
135 base::TimeDelta interval) { 126 base::TimeDelta interval) {
136 upload_interval_ = interval; 127 upload_interval_ = interval;
137 } 128 }
138 129
139 void MetricsReportingScheduler::TriggerUpload() { 130 void MetricsReportingScheduler::TriggerUpload() {
140 // If the timer fired before the init task has completed, don't trigger the 131 // 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. 132 // upload yet - wait for the init task to complete and do it then.
142 if (!init_task_complete_) { 133 if (!init_task_complete_) {
143 LogMetricsInitSequence(TIMER_FIRED_FIRST); 134 LogMetricsInitSequence(TIMER_FIRED_FIRST);
144 waiting_for_init_task_complete_ = true; 135 waiting_for_init_task_complete_ = true;
145 return; 136 return;
146 } 137 }
147 138
148 if (!last_upload_finish_time_.is_null()) {
149 LogActualUploadInterval(base::TimeTicks::Now() - last_upload_finish_time_);
150 last_upload_finish_time_ = base::TimeTicks();
151 }
152
153 callback_pending_ = true; 139 callback_pending_ = true;
154 upload_callback_.Run(); 140 upload_callback_.Run();
155 } 141 }
156 142
157 void MetricsReportingScheduler::ScheduleNextUpload() { 143 void MetricsReportingScheduler::ScheduleNextUpload() {
158 DCHECK(running_); 144 DCHECK(running_);
159 if (upload_timer_.IsRunning() || callback_pending_) 145 if (upload_timer_.IsRunning() || callback_pending_)
160 return; 146 return;
161 147
162 upload_timer_.Start(FROM_HERE, upload_interval_, this, 148 upload_timer_.Start(FROM_HERE, upload_interval_, this,
163 &MetricsReportingScheduler::TriggerUpload); 149 &MetricsReportingScheduler::TriggerUpload);
164 } 150 }
165 151
166 void MetricsReportingScheduler::BackOffUploadInterval() { 152 void MetricsReportingScheduler::BackOffUploadInterval() {
167 DCHECK_GT(kBackoffMultiplier, 1.0); 153 DCHECK_GT(kBackoffMultiplier, 1.0);
168 upload_interval_ = TimeDelta::FromMicroseconds(static_cast<int64_t>( 154 upload_interval_ = TimeDelta::FromMicroseconds(static_cast<int64_t>(
169 kBackoffMultiplier * upload_interval_.InMicroseconds())); 155 kBackoffMultiplier * upload_interval_.InMicroseconds()));
170 156
171 TimeDelta max_interval = kMaxBackoffMultiplier * GetStandardUploadInterval(); 157 TimeDelta max_interval = kMaxBackoffMultiplier * GetStandardUploadInterval();
172 if (upload_interval_ > max_interval || upload_interval_.InSeconds() < 0) { 158 if (upload_interval_ > max_interval || upload_interval_.InSeconds() < 0) {
173 upload_interval_ = max_interval; 159 upload_interval_ = max_interval;
174 } 160 }
175 } 161 }
176 162
177 base::TimeDelta MetricsReportingScheduler::GetStandardUploadInterval() { 163 base::TimeDelta MetricsReportingScheduler::GetStandardUploadInterval() {
178 return upload_interval_callback_.Run(); 164 return upload_interval_callback_.Run();
179 } 165 }
180 166
181 } // namespace metrics 167 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698