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

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

Issue 2746903004: Add traces for some video events. (Closed)
Patch Set: Use the webrtc_stats category instead. Created 3 years, 9 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 | « no previous file | 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) 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
11 #include "webrtc/video/send_statistics_proxy.h" 11 #include "webrtc/video/send_statistics_proxy.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <cmath> 14 #include <cmath>
15 #include <map> 15 #include <map>
16 #include <vector> 16 #include <vector>
17 17
18 #include "webrtc/base/checks.h" 18 #include "webrtc/base/checks.h"
19 #include "webrtc/base/logging.h" 19 #include "webrtc/base/logging.h"
20 #include "webrtc/base/trace_event.h"
20 #include "webrtc/modules/video_coding/include/video_codec_interface.h" 21 #include "webrtc/modules/video_coding/include/video_codec_interface.h"
21 #include "webrtc/system_wrappers/include/metrics.h" 22 #include "webrtc/system_wrappers/include/metrics.h"
22 23
23 namespace webrtc { 24 namespace webrtc {
24 namespace { 25 namespace {
25 const float kEncodeTimeWeigthFactor = 0.5f; 26 const float kEncodeTimeWeigthFactor = 0.5f;
26 27
27 // Used by histograms. Values of entries should not be changed. 28 // Used by histograms. Values of entries should not be changed.
28 enum HistogramCodecType { 29 enum HistogramCodecType {
29 kVideoUnknown = 0, 30 kVideoUnknown = 0,
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 GetUmaPrefix(config.content_type), stats_, clock_)); 420 GetUmaPrefix(config.content_type), stats_, clock_));
420 content_type_ = config.content_type; 421 content_type_ = config.content_type;
421 } 422 }
422 } 423 }
423 424
424 void SendStatisticsProxy::OnEncoderStatsUpdate(uint32_t framerate, 425 void SendStatisticsProxy::OnEncoderStatsUpdate(uint32_t framerate,
425 uint32_t bitrate) { 426 uint32_t bitrate) {
426 rtc::CritScope lock(&crit_); 427 rtc::CritScope lock(&crit_);
427 stats_.encode_frame_rate = framerate; 428 stats_.encode_frame_rate = framerate;
428 stats_.media_bitrate_bps = bitrate; 429 stats_.media_bitrate_bps = bitrate;
430 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC::Video::FrameRateSent",
tommi 2017/03/15 13:49:08 nit: since WebRTC::Video::FrameRateSent does not m
ehmaldonado_webrtc 2017/03/15 15:29:33 Done. I decided to leave the WebRTC in so it has t
431 "frame_rate", framerate, "ssrc", rtp_config_.ssrcs[0]);
429 } 432 }
430 433
431 void SendStatisticsProxy::OnEncodedFrameTimeMeasured( 434 void SendStatisticsProxy::OnEncodedFrameTimeMeasured(
432 int encode_time_ms, 435 int encode_time_ms,
433 const CpuOveruseMetrics& metrics) { 436 const CpuOveruseMetrics& metrics) {
434 rtc::CritScope lock(&crit_); 437 rtc::CritScope lock(&crit_);
435 uma_container_->encode_time_counter_.Add(encode_time_ms); 438 uma_container_->encode_time_counter_.Add(encode_time_ms);
436 encode_time_.Apply(1.0f, encode_time_ms); 439 encode_time_.Apply(1.0f, encode_time_ms);
437 stats_.avg_encode_time_ms = round(encode_time_.filtered()); 440 stats_.avg_encode_time_ms = round(encode_time_.filtered());
438 stats_.encode_usage_percent = metrics.encode_usage_percent; 441 stats_.encode_usage_percent = metrics.encode_usage_percent;
442 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC::Video::EncodeTimeInMs",
443 "encode_time_ms", stats_.avg_encode_time_ms,
444 "ssrc", rtp_config_.ssrcs[0]);
445 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC::Video::EncodeUsagePercent",
446 "encode_usage_percent", stats_.encode_usage_percent,
447 "ssrc", rtp_config_.ssrcs[0]);
439 } 448 }
440 449
441 void SendStatisticsProxy::OnSuspendChange(bool is_suspended) { 450 void SendStatisticsProxy::OnSuspendChange(bool is_suspended) {
442 rtc::CritScope lock(&crit_); 451 rtc::CritScope lock(&crit_);
443 stats_.suspended = is_suspended; 452 stats_.suspended = is_suspended;
444 if (is_suspended) { 453 if (is_suspended) {
445 // Pause framerate (add min pause time since there may be frames/packets 454 // Pause framerate (add min pause time since there may be frames/packets
446 // that are not yet sent). 455 // that are not yet sent).
447 const int64_t kMinMs = 500; 456 const int64_t kMinMs = 500;
448 uma_container_->input_fps_counter_.ProcessAndPauseForDuration(kMinMs); 457 uma_container_->input_fps_counter_.ProcessAndPauseForDuration(kMinMs);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 uint32_t ssrc = rtp_config_.ssrcs[simulcast_idx]; 581 uint32_t ssrc = rtp_config_.ssrcs[simulcast_idx];
573 582
574 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); 583 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
575 if (!stats) 584 if (!stats)
576 return; 585 return;
577 586
578 stats->width = encoded_image._encodedWidth; 587 stats->width = encoded_image._encodedWidth;
579 stats->height = encoded_image._encodedHeight; 588 stats->height = encoded_image._encodedHeight;
580 update_times_[ssrc].resolution_update_ms = clock_->TimeInMilliseconds(); 589 update_times_[ssrc].resolution_update_ms = clock_->TimeInMilliseconds();
581 590
591 // Would it be better to report these at the end?
592 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC::Video::FrameHeightSent",
593 "frame_height", encoded_image._encodedHeight,
594 "ssrc", ssrc);
595 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC::Video::FrameWidthSent",
596 "frame_width", encoded_image._encodedWidth,
597 "ssrc", ssrc);
598
582 uma_container_->key_frame_counter_.Add(encoded_image._frameType == 599 uma_container_->key_frame_counter_.Add(encoded_image._frameType ==
583 kVideoFrameKey); 600 kVideoFrameKey);
584 stats_.bw_limited_resolution = 601 stats_.bw_limited_resolution =
585 encoded_image.adapt_reason_.bw_resolutions_disabled > 0 || 602 encoded_image.adapt_reason_.bw_resolutions_disabled > 0 ||
586 quality_downscales_ > 0; 603 quality_downscales_ > 0;
587 604
588 if (quality_downscales_ != -1) { 605 if (quality_downscales_ != -1) {
589 uma_container_->quality_limited_frame_counter_.Add(quality_downscales_ > 0); 606 uma_container_->quality_limited_frame_counter_.Add(quality_downscales_ > 0);
590 if (quality_downscales_ > 0) 607 if (quality_downscales_ > 0)
591 uma_container_->quality_downscales_counter_.Add(quality_downscales_); 608 uma_container_->quality_downscales_counter_.Add(quality_downscales_);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 return stats_.encode_frame_rate; 667 return stats_.encode_frame_rate;
651 } 668 }
652 669
653 void SendStatisticsProxy::OnIncomingFrame(int width, int height) { 670 void SendStatisticsProxy::OnIncomingFrame(int width, int height) {
654 rtc::CritScope lock(&crit_); 671 rtc::CritScope lock(&crit_);
655 uma_container_->input_frame_rate_tracker_.AddSamples(1); 672 uma_container_->input_frame_rate_tracker_.AddSamples(1);
656 uma_container_->input_fps_counter_.Add(1); 673 uma_container_->input_fps_counter_.Add(1);
657 uma_container_->input_width_counter_.Add(width); 674 uma_container_->input_width_counter_.Add(width);
658 uma_container_->input_height_counter_.Add(height); 675 uma_container_->input_height_counter_.Add(height);
659 uma_container_->cpu_limited_frame_counter_.Add(stats_.cpu_limited_resolution); 676 uma_container_->cpu_limited_frame_counter_.Add(stats_.cpu_limited_resolution);
677 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC::Video::FrameRateInput",
678 "frame_rate", round(
679 uma_container_->input_frame_rate_tracker_.ComputeRate()),
680 "ssrc", rtp_config_.ssrcs[0]);
660 } 681 }
661 682
662 void SendStatisticsProxy::SetResolutionRestrictionStats( 683 void SendStatisticsProxy::SetResolutionRestrictionStats(
663 bool scaling_enabled, 684 bool scaling_enabled,
664 bool cpu_restricted, 685 bool cpu_restricted,
665 int num_quality_downscales) { 686 int num_quality_downscales) {
666 rtc::CritScope lock(&crit_); 687 rtc::CritScope lock(&crit_);
667 if (scaling_enabled) { 688 if (scaling_enabled) {
668 quality_downscales_ = num_quality_downscales; 689 quality_downscales_ = num_quality_downscales;
669 stats_.bw_limited_resolution = quality_downscales_ > 0; 690 stats_.bw_limited_resolution = quality_downscales_ > 0;
670 stats_.cpu_limited_resolution = cpu_restricted; 691 stats_.cpu_limited_resolution = cpu_restricted;
671 } else { 692 } else {
672 stats_.bw_limited_resolution = false; 693 stats_.bw_limited_resolution = false;
673 stats_.cpu_limited_resolution = false; 694 stats_.cpu_limited_resolution = false;
674 quality_downscales_ = -1; 695 quality_downscales_ = -1;
675 } 696 }
676 } 697 }
677 698
678 void SendStatisticsProxy::OnCpuRestrictedResolutionChanged( 699 void SendStatisticsProxy::OnCpuRestrictedResolutionChanged(
679 bool cpu_restricted_resolution) { 700 bool cpu_restricted_resolution) {
680 rtc::CritScope lock(&crit_); 701 rtc::CritScope lock(&crit_);
681 stats_.cpu_limited_resolution = cpu_restricted_resolution; 702 stats_.cpu_limited_resolution = cpu_restricted_resolution;
682 ++stats_.number_of_cpu_adapt_changes; 703 ++stats_.number_of_cpu_adapt_changes;
704 TRACE_EVENT_INSTANT0("webrtc_stats", "WebRTC::Video::AdaptationChanges");
683 } 705 }
684 706
685 void SendStatisticsProxy::OnQualityRestrictedResolutionChanged( 707 void SendStatisticsProxy::OnQualityRestrictedResolutionChanged(
686 int num_quality_downscales) { 708 int num_quality_downscales) {
687 rtc::CritScope lock(&crit_); 709 rtc::CritScope lock(&crit_);
688 quality_downscales_ = num_quality_downscales; 710 quality_downscales_ = num_quality_downscales;
689 stats_.bw_limited_resolution = quality_downscales_ > 0; 711 stats_.bw_limited_resolution = quality_downscales_ > 0;
690 } 712 }
691 713
692 void SendStatisticsProxy::RtcpPacketTypesCounterUpdated( 714 void SendStatisticsProxy::RtcpPacketTypesCounterUpdated(
693 uint32_t ssrc, 715 uint32_t ssrc,
694 const RtcpPacketTypeCounter& packet_counter) { 716 const RtcpPacketTypeCounter& packet_counter) {
695 rtc::CritScope lock(&crit_); 717 rtc::CritScope lock(&crit_);
696 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); 718 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
697 if (!stats) 719 if (!stats)
698 return; 720 return;
699 721
700 stats->rtcp_packet_type_counts = packet_counter; 722 stats->rtcp_packet_type_counts = packet_counter;
701 if (uma_container_->first_rtcp_stats_time_ms_ == -1) 723 if (uma_container_->first_rtcp_stats_time_ms_ == -1)
702 uma_container_->first_rtcp_stats_time_ms_ = clock_->TimeInMilliseconds(); 724 uma_container_->first_rtcp_stats_time_ms_ = clock_->TimeInMilliseconds();
725
726 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC::Video::FirsReceived",
727 "fir_packets_received", packet_counter.fir_packets, "ssrc", ssrc);
728 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC::Video::NacksReceived",
729 "nack_packets_received", packet_counter.nack_packets, "ssrc", ssrc);
730 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC::Video::PlisReceived",
731 "pli_packets_received", packet_counter.pli_packets, "ssrc", ssrc);
703 } 732 }
704 733
705 void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics, 734 void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics,
706 uint32_t ssrc) { 735 uint32_t ssrc) {
707 rtc::CritScope lock(&crit_); 736 rtc::CritScope lock(&crit_);
708 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); 737 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
709 if (!stats) 738 if (!stats)
710 return; 739 return;
711 740
712 stats->rtcp_stats = statistics; 741 stats->rtcp_stats = statistics;
713 uma_container_->report_block_stats_.Store(statistics, 0, ssrc); 742 uma_container_->report_block_stats_.Store(statistics, 0, ssrc);
743
744 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC::Video::PacketsLost",
745 "packets_lost", statistics.cumulative_lost, "ssrc", ssrc);
714 } 746 }
715 747
716 void SendStatisticsProxy::CNameChanged(const char* cname, uint32_t ssrc) {} 748 void SendStatisticsProxy::CNameChanged(const char* cname, uint32_t ssrc) {}
717 749
718 void SendStatisticsProxy::DataCountersUpdated( 750 void SendStatisticsProxy::DataCountersUpdated(
719 const StreamDataCounters& counters, 751 const StreamDataCounters& counters,
720 uint32_t ssrc) { 752 uint32_t ssrc) {
721 rtc::CritScope lock(&crit_); 753 rtc::CritScope lock(&crit_);
722 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); 754 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
723 RTC_DCHECK(stats) << "DataCountersUpdated reported for unknown ssrc " << ssrc; 755 RTC_DCHECK(stats) << "DataCountersUpdated reported for unknown ssrc " << ssrc;
(...skipping 14 matching lines...) Expand all
738 ssrc); 770 ssrc);
739 uma_container_->retransmit_byte_counter_.Set( 771 uma_container_->retransmit_byte_counter_.Set(
740 counters.retransmitted.TotalBytes(), ssrc); 772 counters.retransmitted.TotalBytes(), ssrc);
741 uma_container_->fec_byte_counter_.Set(counters.fec.TotalBytes(), ssrc); 773 uma_container_->fec_byte_counter_.Set(counters.fec.TotalBytes(), ssrc);
742 if (stats->is_rtx) { 774 if (stats->is_rtx) {
743 uma_container_->rtx_byte_counter_.Set(counters.transmitted.TotalBytes(), 775 uma_container_->rtx_byte_counter_.Set(counters.transmitted.TotalBytes(),
744 ssrc); 776 ssrc);
745 } else { 777 } else {
746 uma_container_->media_byte_counter_.Set(counters.MediaPayloadBytes(), ssrc); 778 uma_container_->media_byte_counter_.Set(counters.MediaPayloadBytes(), ssrc);
747 } 779 }
780
781 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC::Video::PacketsSent",
782 "packets_sent", counters.transmitted.packets, "ssrc", ssrc);
748 } 783 }
749 784
750 void SendStatisticsProxy::Notify(uint32_t total_bitrate_bps, 785 void SendStatisticsProxy::Notify(uint32_t total_bitrate_bps,
751 uint32_t retransmit_bitrate_bps, 786 uint32_t retransmit_bitrate_bps,
752 uint32_t ssrc) { 787 uint32_t ssrc) {
753 rtc::CritScope lock(&crit_); 788 rtc::CritScope lock(&crit_);
754 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); 789 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
755 if (!stats) 790 if (!stats)
756 return; 791 return;
757 792
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 } 852 }
818 853
819 int SendStatisticsProxy::BoolSampleCounter::Fraction( 854 int SendStatisticsProxy::BoolSampleCounter::Fraction(
820 int64_t min_required_samples, 855 int64_t min_required_samples,
821 float multiplier) const { 856 float multiplier) const {
822 if (num_samples < min_required_samples || num_samples == 0) 857 if (num_samples < min_required_samples || num_samples == 0)
823 return -1; 858 return -1;
824 return static_cast<int>((sum * multiplier / num_samples) + 0.5f); 859 return static_cast<int>((sum * multiplier / num_samples) + 0.5f);
825 } 860 }
826 } // namespace webrtc 861 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698