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

Side by Side Diff: webrtc/video/stats_counter_unittest.cc

Issue 2236923002: Make variable for selecting if intervals without samples should be included in stats configurable (… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « webrtc/video/stats_counter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 EXPECT_EQ(500, observer->last_sample_); 163 EXPECT_EQ(500, observer->last_sample_);
164 // Aggregated stats. 164 // Aggregated stats.
165 AggregatedStats stats = counter.GetStats(); 165 AggregatedStats stats = counter.GetStats();
166 EXPECT_EQ(1, stats.num_samples); 166 EXPECT_EQ(1, stats.num_samples);
167 EXPECT_EQ(500, stats.min); 167 EXPECT_EQ(500, stats.min);
168 EXPECT_EQ(500, stats.max); 168 EXPECT_EQ(500, stats.max);
169 } 169 }
170 170
171 TEST_F(StatsCounterTest, TestMetric_RateCounter) { 171 TEST_F(StatsCounterTest, TestMetric_RateCounter) {
172 StatsCounterObserverImpl* observer = new StatsCounterObserverImpl(); 172 StatsCounterObserverImpl* observer = new StatsCounterObserverImpl();
173 RateCounter counter(&clock_, observer); 173 RateCounter counter(&clock_, observer, true);
174 counter.Add(186); 174 counter.Add(186);
175 counter.Add(350); 175 counter.Add(350);
176 counter.Add(22); 176 counter.Add(22);
177 clock_.AdvanceTimeMilliseconds(kProcessIntervalMs); 177 clock_.AdvanceTimeMilliseconds(kProcessIntervalMs);
178 // Trigger process (sample included in next interval). 178 // Trigger process (sample included in next interval).
179 counter.Add(111); 179 counter.Add(111);
180 // Rate per interval, (186 + 350 + 22) / 2 sec = 279 samples/sec 180 // Rate per interval, (186 + 350 + 22) / 2 sec = 279 samples/sec
181 EXPECT_EQ(1, observer->num_calls_); 181 EXPECT_EQ(1, observer->num_calls_);
182 EXPECT_EQ(279, observer->last_sample_); 182 EXPECT_EQ(279, observer->last_sample_);
183 // Aggregated stats. 183 // Aggregated stats.
184 AggregatedStats stats = counter.GetStats(); 184 AggregatedStats stats = counter.GetStats();
185 EXPECT_EQ(1, stats.num_samples); 185 EXPECT_EQ(1, stats.num_samples);
186 EXPECT_EQ(279, stats.min); 186 EXPECT_EQ(279, stats.min);
187 EXPECT_EQ(279, stats.max); 187 EXPECT_EQ(279, stats.max);
188 } 188 }
189 189
190 TEST_F(StatsCounterTest, TestMetric_RateAccCounter) { 190 TEST_F(StatsCounterTest, TestMetric_RateAccCounter) {
191 StatsCounterObserverImpl* observer = new StatsCounterObserverImpl(); 191 StatsCounterObserverImpl* observer = new StatsCounterObserverImpl();
192 RateAccCounter counter(&clock_, observer); 192 RateAccCounter counter(&clock_, observer, true);
193 counter.Set(175); 193 counter.Set(175);
194 counter.Set(188); 194 counter.Set(188);
195 clock_.AdvanceTimeMilliseconds(kProcessIntervalMs); 195 clock_.AdvanceTimeMilliseconds(kProcessIntervalMs);
196 // Trigger process (sample included in next interval). 196 // Trigger process (sample included in next interval).
197 counter.Set(192); 197 counter.Set(192);
198 // Rate per interval: (188 - 0) / 2 sec = 94 samples/sec 198 // Rate per interval: (188 - 0) / 2 sec = 94 samples/sec
199 EXPECT_EQ(1, observer->num_calls_); 199 EXPECT_EQ(1, observer->num_calls_);
200 EXPECT_EQ(94, observer->last_sample_); 200 EXPECT_EQ(94, observer->last_sample_);
201 // Aggregated stats. 201 // Aggregated stats.
202 AggregatedStats stats = counter.GetStats(); 202 AggregatedStats stats = counter.GetStats();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 EXPECT_EQ(kSample1, stats.min); 245 EXPECT_EQ(kSample1, stats.min);
246 EXPECT_EQ(kSample2, stats.max); 246 EXPECT_EQ(kSample2, stats.max);
247 EXPECT_EQ(6, stats.average); 247 EXPECT_EQ(6, stats.average);
248 } 248 }
249 249
250 TEST_F(StatsCounterTest, TestRateAccCounter_NegativeRateIgnored) { 250 TEST_F(StatsCounterTest, TestRateAccCounter_NegativeRateIgnored) {
251 StatsCounterObserverImpl* observer = new StatsCounterObserverImpl(); 251 StatsCounterObserverImpl* observer = new StatsCounterObserverImpl();
252 const int kSample1 = 200; // 200 / 2 sec 252 const int kSample1 = 200; // 200 / 2 sec
253 const int kSample2 = 100; // -100 / 2 sec - negative ignored 253 const int kSample2 = 100; // -100 / 2 sec - negative ignored
254 const int kSample3 = 700; // 600 / 2 sec 254 const int kSample3 = 700; // 600 / 2 sec
255 RateAccCounter counter(&clock_, observer); 255 RateAccCounter counter(&clock_, observer, true);
256 SetSampleAndAdvance(kSample1, kProcessIntervalMs, &counter); 256 SetSampleAndAdvance(kSample1, kProcessIntervalMs, &counter);
257 SetSampleAndAdvance(kSample2, kProcessIntervalMs, &counter); 257 SetSampleAndAdvance(kSample2, kProcessIntervalMs, &counter);
258 SetSampleAndAdvance(kSample3, kProcessIntervalMs, &counter); 258 SetSampleAndAdvance(kSample3, kProcessIntervalMs, &counter);
259 EXPECT_EQ(1, observer->num_calls_); 259 EXPECT_EQ(1, observer->num_calls_);
260 EXPECT_EQ(100, observer->last_sample_); 260 EXPECT_EQ(100, observer->last_sample_);
261 // Trigger process (sample included in next interval). 261 // Trigger process (sample included in next interval).
262 counter.Set(2000); 262 counter.Set(2000);
263 EXPECT_EQ(2, observer->num_calls_); 263 EXPECT_EQ(2, observer->num_calls_);
264 EXPECT_EQ(300, observer->last_sample_); 264 EXPECT_EQ(300, observer->last_sample_);
265 // Aggregated stats. 265 // Aggregated stats.
(...skipping 19 matching lines...) Expand all
285 // [6:1],[8:1] 285 // [6:1],[8:1]
286 EXPECT_EQ(2, observer->num_calls_); 286 EXPECT_EQ(2, observer->num_calls_);
287 EXPECT_EQ(8, observer->last_sample_); 287 EXPECT_EQ(8, observer->last_sample_);
288 // Aggregated stats. 288 // Aggregated stats.
289 AggregatedStats stats = counter.GetStats(); 289 AggregatedStats stats = counter.GetStats();
290 EXPECT_EQ(2, stats.num_samples); 290 EXPECT_EQ(2, stats.num_samples);
291 EXPECT_EQ(6, stats.min); 291 EXPECT_EQ(6, stats.min);
292 EXPECT_EQ(8, stats.max); 292 EXPECT_EQ(8, stats.max);
293 } 293 }
294 294
295 TEST_F(StatsCounterTest, TestRateCounter_IntervalsWithoutSamplesIncluded) { 295 TEST_F(StatsCounterTest, TestRateCounter_IntervalsWithoutSamplesIgnored) {
296 const bool kIncludeEmptyIntervals = false;
296 StatsCounterObserverImpl* observer = new StatsCounterObserverImpl(); 297 StatsCounterObserverImpl* observer = new StatsCounterObserverImpl();
297 const int kSample1 = 50; // 50 / 2 sec 298 const int kSample1 = 50; // 50 / 2 sec
298 const int kSample2 = 20; // 20 / 2 sec 299 const int kSample2 = 20; // 20 / 2 sec
299 RateCounter counter(&clock_, observer); 300 RateCounter counter(&clock_, observer, kIncludeEmptyIntervals);
300 counter.Add(kSample1); 301 counter.Add(kSample1);
301 clock_.AdvanceTimeMilliseconds(kProcessIntervalMs * 3 - 1); 302 clock_.AdvanceTimeMilliseconds(kProcessIntervalMs * 3 - 1);
302 // Trigger process (sample included in next interval). 303 // Trigger process (sample included in next interval).
304 counter.Add(kSample2);
305 // [25:1], one interval without samples passed.
306 EXPECT_EQ(1, observer->num_calls_);
307 EXPECT_EQ(25, observer->last_sample_);
308 // Make last interval pass.
309 clock_.AdvanceTimeMilliseconds(1);
310 counter.Add(111); // Trigger process (sample included in next interval).
311 // [10:1],[25:1]
312 EXPECT_EQ(2, observer->num_calls_);
313 EXPECT_EQ(10, observer->last_sample_);
314 // Aggregated stats.
315 AggregatedStats stats = counter.GetStats();
316 EXPECT_EQ(2, stats.num_samples);
317 EXPECT_EQ(10, stats.min);
318 EXPECT_EQ(25, stats.max);
319 }
320
321 TEST_F(StatsCounterTest, TestRateCounter_IntervalsWithoutSamplesIncluded) {
322 const bool kIncludeEmptyIntervals = true;
323 StatsCounterObserverImpl* observer = new StatsCounterObserverImpl();
324 const int kSample1 = 50; // 50 / 2 sec
325 const int kSample2 = 20; // 20 / 2 sec
326 RateCounter counter(&clock_, observer, kIncludeEmptyIntervals);
327 counter.Add(kSample1);
328 clock_.AdvanceTimeMilliseconds(kProcessIntervalMs * 3 - 1);
329 // Trigger process (sample included in next interval).
303 counter.Add(kSample2); 330 counter.Add(kSample2);
304 // [0:1],[25:1], one interval without samples passed. 331 // [0:1],[25:1], one interval without samples passed.
305 EXPECT_EQ(2, observer->num_calls_); 332 EXPECT_EQ(2, observer->num_calls_);
306 EXPECT_EQ(25, observer->last_sample_); 333 EXPECT_EQ(25, observer->last_sample_);
307 // Make last interval pass. 334 // Make last interval pass.
308 clock_.AdvanceTimeMilliseconds(1); 335 clock_.AdvanceTimeMilliseconds(1);
309 counter.Add(111); // Trigger process (sample included in next interval). 336 counter.Add(111); // Trigger process (sample included in next interval).
310 // [0:1],[10:1],[25:1] 337 // [0:1],[10:1],[25:1]
311 EXPECT_EQ(3, observer->num_calls_); 338 EXPECT_EQ(3, observer->num_calls_);
312 EXPECT_EQ(10, observer->last_sample_); 339 EXPECT_EQ(10, observer->last_sample_);
313 // Aggregated stats. 340 // Aggregated stats.
314 AggregatedStats stats = counter.GetStats(); 341 AggregatedStats stats = counter.GetStats();
315 EXPECT_EQ(3, stats.num_samples); 342 EXPECT_EQ(3, stats.num_samples);
316 EXPECT_EQ(0, stats.min); 343 EXPECT_EQ(0, stats.min);
317 EXPECT_EQ(25, stats.max); 344 EXPECT_EQ(25, stats.max);
318 } 345 }
319 346
320 } // namespace webrtc 347 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/stats_counter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698