From 8fb8b1b7ffa66807f5313ccb367a9d4891dab404 Mon Sep 17 00:00:00 2001 From: guoweis Date: Fri, 26 Sep 2014 10:07:58 -0700 Subject: Add two UMA counters for IPv4 and IPv6 local candidates gathered in WebRTC PeerConnection. Counter will be accumulated for each OnIceCandidate callback and report once the IceGathering is completed. BUG=411086 Review URL: https://codereview.chromium.org/600163004 Cr-Commit-Position: refs/heads/master@{#296965} --- .../renderer/media/rtc_peer_connection_handler.cc | 28 +++++++++++++++++++++- .../renderer/media/rtc_peer_connection_handler.h | 4 ++++ .../mock_peer_connection_dependency_factory.cc | 9 ++++--- 3 files changed, 35 insertions(+), 6 deletions(-) (limited to 'content/renderer') diff --git a/content/renderer/media/rtc_peer_connection_handler.cc b/content/renderer/media/rtc_peer_connection_handler.cc index c5c68e4..7f1b85a 100644 --- a/content/renderer/media/rtc_peer_connection_handler.cc +++ b/content/renderer/media/rtc_peer_connection_handler.cc @@ -390,7 +390,9 @@ RTCPeerConnectionHandler::RTCPeerConnectionHandler( dependency_factory_(dependency_factory), frame_(NULL), peer_connection_tracker_(NULL), - num_data_channels_created_(0) { + num_data_channels_created_(0), + num_local_candidates_ipv4_(0), + num_local_candidates_ipv6_(0) { g_peer_connection_handlers.Get().insert(this); } @@ -894,6 +896,18 @@ void RTCPeerConnectionHandler::OnIceGatheringChange( // to signal end of candidates. blink::WebRTCICECandidate null_candidate; client_->didGenerateICECandidate(null_candidate); + + UMA_HISTOGRAM_COUNTS_100("WebRTC.PeerConnection.IPv4LocalCandidates", + num_local_candidates_ipv4_); + + UMA_HISTOGRAM_COUNTS_100("WebRTC.PeerConnection.IPv6LocalCandidates", + num_local_candidates_ipv6_); + } else if (new_state == + webrtc::PeerConnectionInterface::kIceGatheringGathering) { + // ICE restarts will change gathering state back to "gathering", + // reset the counter. + num_local_candidates_ipv6_ = 0; + num_local_candidates_ipv4_ = 0; } blink::WebRTCPeerConnectionHandlerClient::ICEGatheringState state = @@ -968,6 +982,18 @@ void RTCPeerConnectionHandler::OnIceCandidate( peer_connection_tracker_->TrackAddIceCandidate( this, web_candidate, PeerConnectionTracker::SOURCE_LOCAL, true); + // Only the first m line's first component is tracked to avoid + // miscounting when doing BUNDLE or rtcp mux. + if (candidate->sdp_mline_index() == 0 && + candidate->candidate().component() == 1) { + if (candidate->candidate().address().family() == AF_INET) { + num_local_candidates_ipv4_++; + } else if (candidate->candidate().address().family() == AF_INET6) { + num_local_candidates_ipv6_++; + } else { + NOTREACHED(); + } + } client_->didGenerateICECandidate(web_candidate); } diff --git a/content/renderer/media/rtc_peer_connection_handler.h b/content/renderer/media/rtc_peer_connection_handler.h index 2a440f1..81be1ac 100644 --- a/content/renderer/media/rtc_peer_connection_handler.h +++ b/content/renderer/media/rtc_peer_connection_handler.h @@ -218,6 +218,10 @@ class CONTENT_EXPORT RTCPeerConnectionHandler // Counter for a UMA stat reported at destruction time. int num_data_channels_created_; + // Counter for number of IPv4 and IPv6 local candidates. + int num_local_candidates_ipv4_; + int num_local_candidates_ipv6_; + // |native_peer_connection_| is the libjingle native PeerConnection object. scoped_refptr native_peer_connection_; diff --git a/content/renderer/media/webrtc/mock_peer_connection_dependency_factory.cc b/content/renderer/media/webrtc/mock_peer_connection_dependency_factory.cc index 6d64c4c..d059fc9 100644 --- a/content/renderer/media/webrtc/mock_peer_connection_dependency_factory.cc +++ b/content/renderer/media/webrtc/mock_peer_connection_dependency_factory.cc @@ -404,6 +404,8 @@ class MockIceCandidate : public IceCandidateInterface { : sdp_mid_(sdp_mid), sdp_mline_index_(sdp_mline_index), sdp_(sdp) { + // Assign an valid address to |candidate_| to pass assert in code. + candidate_.set_address(rtc::SocketAddress("127.0.0.1", 5000)); } virtual ~MockIceCandidate() {} virtual std::string sdp_mid() const OVERRIDE { @@ -413,11 +415,7 @@ class MockIceCandidate : public IceCandidateInterface { return sdp_mline_index_; } virtual const cricket::Candidate& candidate() const OVERRIDE { - // This function should never be called. It will intentionally crash. The - // base class forces us to return a reference. - NOTREACHED(); - cricket::Candidate* candidate = NULL; - return *candidate; + return candidate_; } virtual bool ToString(std::string* out) const OVERRIDE { *out = sdp_; @@ -428,6 +426,7 @@ class MockIceCandidate : public IceCandidateInterface { std::string sdp_mid_; int sdp_mline_index_; std::string sdp_; + cricket::Candidate candidate_; }; MockPeerConnectionDependencyFactory::MockPeerConnectionDependencyFactory() -- cgit v1.1