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

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

Issue 2786593003: Add histogram stats for number of cpu/quality adapt changes per minute for sent video streams: (Closed)
Patch Set: address comments Created 3 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
« no previous file with comments | « webrtc/video/send_statistics_proxy.cc ('k') | webrtc/video/vie_encoder.cc » ('j') | 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) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 EncodedImage encoded_image; 362 EncodedImage encoded_image;
363 CodecSpecificInfo codec_info; 363 CodecSpecificInfo codec_info;
364 encoded_image.qp_ = -1; 364 encoded_image.qp_ = -1;
365 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum); 365 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum);
366 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info); 366 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
367 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum); 367 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum);
368 } 368 }
369 369
370 TEST_F(SendStatisticsProxyTest, SetCpuScalingUpdatesStats) { 370 TEST_F(SendStatisticsProxyTest, SetCpuScalingUpdatesStats) {
371 EXPECT_FALSE(statistics_proxy_->GetStats().cpu_limited_resolution); 371 EXPECT_FALSE(statistics_proxy_->GetStats().cpu_limited_resolution);
372 statistics_proxy_->SetCpuScalingStats(true); 372 statistics_proxy_->SetCpuScalingStats(-1);
373 EXPECT_FALSE(statistics_proxy_->GetStats().cpu_limited_resolution);
374 statistics_proxy_->SetCpuScalingStats(0);
375 EXPECT_FALSE(statistics_proxy_->GetStats().cpu_limited_resolution);
376 statistics_proxy_->SetCpuScalingStats(1);
373 EXPECT_TRUE(statistics_proxy_->GetStats().cpu_limited_resolution); 377 EXPECT_TRUE(statistics_proxy_->GetStats().cpu_limited_resolution);
374 statistics_proxy_->SetCpuScalingStats(false);
375 EXPECT_FALSE(statistics_proxy_->GetStats().cpu_limited_resolution);
376 } 378 }
377 379
378 TEST_F(SendStatisticsProxyTest, SetQualityScalingUpdatesStats) { 380 TEST_F(SendStatisticsProxyTest, SetQualityScalingUpdatesStats) {
379 EXPECT_FALSE(statistics_proxy_->GetStats().bw_limited_resolution); 381 EXPECT_FALSE(statistics_proxy_->GetStats().bw_limited_resolution);
380 statistics_proxy_->SetQualityScalingStats(-1); 382 statistics_proxy_->SetQualityScalingStats(-1);
381 EXPECT_FALSE(statistics_proxy_->GetStats().bw_limited_resolution); 383 EXPECT_FALSE(statistics_proxy_->GetStats().bw_limited_resolution);
382 statistics_proxy_->SetQualityScalingStats(0); 384 statistics_proxy_->SetQualityScalingStats(0);
383 EXPECT_FALSE(statistics_proxy_->GetStats().bw_limited_resolution); 385 EXPECT_FALSE(statistics_proxy_->GetStats().bw_limited_resolution);
384 statistics_proxy_->SetQualityScalingStats(1); 386 statistics_proxy_->SetQualityScalingStats(1);
385 EXPECT_TRUE(statistics_proxy_->GetStats().bw_limited_resolution); 387 EXPECT_TRUE(statistics_proxy_->GetStats().bw_limited_resolution);
(...skipping 26 matching lines...) Expand all
412 414
413 statistics_proxy_->OnQualityRestrictedResolutionChanged(1); 415 statistics_proxy_->OnQualityRestrictedResolutionChanged(1);
414 EXPECT_TRUE(statistics_proxy_->GetStats().bw_limited_resolution); 416 EXPECT_TRUE(statistics_proxy_->GetStats().bw_limited_resolution);
415 EXPECT_EQ(3, statistics_proxy_->GetStats().number_of_quality_adapt_changes); 417 EXPECT_EQ(3, statistics_proxy_->GetStats().number_of_quality_adapt_changes);
416 418
417 statistics_proxy_->OnQualityRestrictedResolutionChanged(0); 419 statistics_proxy_->OnQualityRestrictedResolutionChanged(0);
418 EXPECT_FALSE(statistics_proxy_->GetStats().bw_limited_resolution); 420 EXPECT_FALSE(statistics_proxy_->GetStats().bw_limited_resolution);
419 EXPECT_EQ(4, statistics_proxy_->GetStats().number_of_quality_adapt_changes); 421 EXPECT_EQ(4, statistics_proxy_->GetStats().number_of_quality_adapt_changes);
420 } 422 }
421 423
424 TEST_F(SendStatisticsProxyTest, AdaptChangesNotReported_ScalingNotEnabled) {
425 // Min runtime has passed.
426 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
427 statistics_proxy_.reset();
428 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.AdaptChangesPerMinute.Cpu"));
429 EXPECT_EQ(0,
430 metrics::NumSamples("WebRTC.Video.AdaptChangesPerMinute.Quality"));
431 }
432
433 TEST_F(SendStatisticsProxyTest, AdaptChangesNotReported_MinRuntimeNotPassed) {
434 // Enable scaling.
435 statistics_proxy_->SetQualityScalingStats(0);
436 statistics_proxy_->SetCpuScalingStats(0);
437 // Min runtime has not passed.
438 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000 - 1);
439 statistics_proxy_.reset();
440 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.AdaptChangesPerMinute.Cpu"));
441 EXPECT_EQ(0,
442 metrics::NumSamples("WebRTC.Video.AdaptChangesPerMinute.Quality"));
443 }
444
445 TEST_F(SendStatisticsProxyTest, ZeroCpuAdaptChangesReported) {
446 // Enable scaling.
447 statistics_proxy_->SetCpuScalingStats(0);
448 // Min runtime has passed.
449 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
450 statistics_proxy_.reset();
451 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.AdaptChangesPerMinute.Cpu"));
452 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.AdaptChangesPerMinute.Cpu", 0));
453 }
454
455 TEST_F(SendStatisticsProxyTest, ZeroQualityAdaptChangesReported) {
456 // Enable scaling.
457 statistics_proxy_->SetQualityScalingStats(0);
458 // Min runtime has passed.
459 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
460 statistics_proxy_.reset();
461 EXPECT_EQ(1,
462 metrics::NumSamples("WebRTC.Video.AdaptChangesPerMinute.Quality"));
463 EXPECT_EQ(
464 1, metrics::NumEvents("WebRTC.Video.AdaptChangesPerMinute.Quality", 0));
465 }
466
467 TEST_F(SendStatisticsProxyTest, CpuAdaptChangesReported) {
468 // Enable scaling.
469 // Adapt changes: 1, elapsed time: 10 ms => 6 per minute.
470 statistics_proxy_->SetCpuScalingStats(0);
471 statistics_proxy_->OnCpuRestrictedResolutionChanged(true);
472 fake_clock_.AdvanceTimeMilliseconds(10000);
473 statistics_proxy_.reset();
474 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.AdaptChangesPerMinute.Cpu"));
475 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.AdaptChangesPerMinute.Cpu", 6));
476 }
477
478 TEST_F(SendStatisticsProxyTest, AdaptChangesStatsExcludesDisabledTime) {
479 // Disable scaling.
480 statistics_proxy_->SetQualityScalingStats(-1);
481 fake_clock_.AdvanceTimeMilliseconds(10000);
482
483 // Enable scaling.
484 // Adapt changes: 2, elapsed time: 20 ms.
485 statistics_proxy_->SetQualityScalingStats(0);
486 fake_clock_.AdvanceTimeMilliseconds(5000);
487 statistics_proxy_->SetQualityScalingStats(1);
488 fake_clock_.AdvanceTimeMilliseconds(9000);
489 statistics_proxy_->OnQualityRestrictedResolutionChanged(1);
490 fake_clock_.AdvanceTimeMilliseconds(6000);
491 statistics_proxy_->OnQualityRestrictedResolutionChanged(2);
492
493 // Disable scaling.
494 statistics_proxy_->SetQualityScalingStats(-1);
495 fake_clock_.AdvanceTimeMilliseconds(30000);
496
497 // Enable scaling.
498 // Adapt changes: 1, elapsed time: 10 ms.
499 statistics_proxy_->SetQualityScalingStats(0);
500 statistics_proxy_->OnQualityRestrictedResolutionChanged(1);
501 fake_clock_.AdvanceTimeMilliseconds(10000);
502
503 // Disable scaling.
504 statistics_proxy_->SetQualityScalingStats(-1);
505 fake_clock_.AdvanceTimeMilliseconds(5000);
506 statistics_proxy_->SetQualityScalingStats(-1);
507 fake_clock_.AdvanceTimeMilliseconds(20000);
508
509 // Adapt changes: 3, elapsed time: 30 ms => 6 per minute.
510 statistics_proxy_.reset();
511 EXPECT_EQ(1,
512 metrics::NumSamples("WebRTC.Video.AdaptChangesPerMinute.Quality"));
513 EXPECT_EQ(
514 1, metrics::NumEvents("WebRTC.Video.AdaptChangesPerMinute.Quality", 6));
515 }
516
517 TEST_F(SendStatisticsProxyTest, AdaptChangesStatsRestartsOnFirstSentPacket) {
518 StreamDataCounters counters;
519 StreamDataCountersCallback* proxy =
520 static_cast<StreamDataCountersCallback*>(statistics_proxy_.get());
521
522 // Send first packet, scaling enabled.
523 // Elapsed time before first packet is sent should be excluded.
524 statistics_proxy_->SetQualityScalingStats(0);
525 fake_clock_.AdvanceTimeMilliseconds(10000);
526 proxy->DataCountersUpdated(counters, kFirstSsrc);
527
528 // Adapt changes: 1, elapsed time: 10 ms.
529 fake_clock_.AdvanceTimeMilliseconds(10000);
530 statistics_proxy_->OnQualityRestrictedResolutionChanged(1);
531 proxy->DataCountersUpdated(counters, kFirstSsrc);
532
533 // Adapt changes: 1, elapsed time: 10 ms => 6 per minute.
534 statistics_proxy_.reset();
535 EXPECT_EQ(1,
536 metrics::NumSamples("WebRTC.Video.AdaptChangesPerMinute.Quality"));
537 EXPECT_EQ(
538 1, metrics::NumEvents("WebRTC.Video.AdaptChangesPerMinute.Quality", 6));
539 }
540
541 TEST_F(SendStatisticsProxyTest, AdaptChangesStatsStartedAfterFirstSentPacket) {
542 StreamDataCounters counters;
543 StreamDataCountersCallback* proxy =
544 static_cast<StreamDataCountersCallback*>(statistics_proxy_.get());
545
546 // Enable and disable scaling.
547 statistics_proxy_->SetCpuScalingStats(0);
548 fake_clock_.AdvanceTimeMilliseconds(60000);
549 statistics_proxy_->SetCpuScalingStats(-1);
550
551 // Send first packet, scaling disabled.
552 // Elapsed time before first packet is sent should be excluded.
553 proxy->DataCountersUpdated(counters, kFirstSsrc);
554 fake_clock_.AdvanceTimeMilliseconds(60000);
555
556 // Enable scaling.
557 statistics_proxy_->SetCpuScalingStats(0);
558 fake_clock_.AdvanceTimeMilliseconds(10000);
559 proxy->DataCountersUpdated(counters, kFirstSsrc);
560
561 // Adapt changes: 1, elapsed time: 20 ms.
562 fake_clock_.AdvanceTimeMilliseconds(10000);
563 statistics_proxy_->OnCpuRestrictedResolutionChanged(true);
564
565 // Adapt changes: 1, elapsed time: 20 ms => 3 per minute.
566 statistics_proxy_.reset();
567 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.AdaptChangesPerMinute.Cpu"));
568 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.AdaptChangesPerMinute.Cpu", 3));
569 }
570
571 TEST_F(SendStatisticsProxyTest, AdaptChangesReportedAfterContentSwitch) {
572 // Enable scaling.
573 statistics_proxy_->SetCpuScalingStats(0);
574
575 // Adapt changes: 2, elapsed time: 15 ms => 8 per minute.
576 statistics_proxy_->OnCpuRestrictedResolutionChanged(true);
577 fake_clock_.AdvanceTimeMilliseconds(6000);
578 statistics_proxy_->OnCpuRestrictedResolutionChanged(true);
579 fake_clock_.AdvanceTimeMilliseconds(9000);
580
581 // Switch content type, real-time stats should be updated.
582 VideoEncoderConfig config;
583 config.content_type = VideoEncoderConfig::ContentType::kScreen;
584 statistics_proxy_->OnEncoderReconfigured(config, 50);
585 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.AdaptChangesPerMinute.Cpu"));
586 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.AdaptChangesPerMinute.Cpu", 8));
587 EXPECT_EQ(0,
588 metrics::NumSamples("WebRTC.Video.AdaptChangesPerMinute.Quality"));
589
590 // Enable scaling.
591 statistics_proxy_->SetCpuScalingStats(0);
592
593 // Adapt changes: 4, elapsed time: 120 ms => 2 per minute.
594 statistics_proxy_->OnCpuRestrictedResolutionChanged(true);
595 statistics_proxy_->OnCpuRestrictedResolutionChanged(true);
596 statistics_proxy_->OnCpuRestrictedResolutionChanged(true);
597 statistics_proxy_->OnCpuRestrictedResolutionChanged(true);
598 fake_clock_.AdvanceTimeMilliseconds(120000);
599
600 statistics_proxy_.reset();
601 EXPECT_EQ(1, metrics::NumSamples(
602 "WebRTC.Video.Screenshare.AdaptChangesPerMinute.Cpu"));
603 EXPECT_EQ(1, metrics::NumEvents(
604 "WebRTC.Video.Screenshare.AdaptChangesPerMinute.Cpu", 2));
605 EXPECT_EQ(0, metrics::NumSamples(
606 "WebRTC.Video.Screenshare.AdaptChangesPerMinute.Quality"));
607 }
608
422 TEST_F(SendStatisticsProxyTest, SwitchContentTypeUpdatesHistograms) { 609 TEST_F(SendStatisticsProxyTest, SwitchContentTypeUpdatesHistograms) {
423 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) 610 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i)
424 statistics_proxy_->OnIncomingFrame(kWidth, kHeight); 611 statistics_proxy_->OnIncomingFrame(kWidth, kHeight);
425 612
426 // No switch, stats should not be updated. 613 // No switch, stats should not be updated.
427 VideoEncoderConfig config; 614 VideoEncoderConfig config;
428 config.content_type = VideoEncoderConfig::ContentType::kRealtimeVideo; 615 config.content_type = VideoEncoderConfig::ContentType::kRealtimeVideo;
429 statistics_proxy_->OnEncoderReconfigured(config, 50); 616 statistics_proxy_->OnEncoderReconfigured(config, 50);
430 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.InputWidthInPixels")); 617 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.InputWidthInPixels"));
431 618
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 fake_clock_.AdvanceTimeMilliseconds(kPeriodIntervalMs); 1583 fake_clock_.AdvanceTimeMilliseconds(kPeriodIntervalMs);
1397 proxy->DataCountersUpdated(counters, kFirstSsrc); 1584 proxy->DataCountersUpdated(counters, kFirstSsrc);
1398 } 1585 }
1399 1586
1400 // FEC not enabled. 1587 // FEC not enabled.
1401 statistics_proxy_.reset(); 1588 statistics_proxy_.reset();
1402 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.FecBitrateSentInKbps")); 1589 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.FecBitrateSentInKbps"));
1403 } 1590 }
1404 1591
1405 } // namespace webrtc 1592 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/send_statistics_proxy.cc ('k') | webrtc/video/vie_encoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698