From 9799fe036ac38dd2891d16168b7db51b8deed061 Mon Sep 17 00:00:00 2001 From: Philipp Hancke Date: Wed, 6 Jul 2022 09:26:41 +0200 Subject: [PATCH] peerconnection: move first connect metrics gathering to helper function since it has grown too large BUG=None Change-Id: I9dfffd6264db3206c0674a3446c857c139ba6fb8 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/267826 Reviewed-by: Harald Alvestrand Commit-Queue: Philipp Hancke Cr-Commit-Position: refs/heads/main@{#37492} --- pc/peer_connection.cc | 115 ++++++++++++++++++++++-------------------- pc/peer_connection.h | 3 ++ 2 files changed, 62 insertions(+), 56 deletions(-) diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index f2727a4fdf..fe6e863efd 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -1934,67 +1934,70 @@ void PeerConnection::SetConnectionState( connection_state_ = new_state; Observer()->OnConnectionChange(new_state); + // The first connection state change to connected happens once per + // connection which makes it a good point to report metrics. if (new_state == PeerConnectionState::kConnected && !was_ever_connected_) { was_ever_connected_ = true; - - // The first connection state change to connected happens once per - // connection which makes it a good point to report metrics. - // Record bundle-policy from configuration. Done here from - // connectionStateChange to limit to actually established connections. - BundlePolicyUsage policy = kBundlePolicyUsageMax; - switch (configuration_.bundle_policy) { - case kBundlePolicyBalanced: - policy = kBundlePolicyUsageBalanced; - break; - case kBundlePolicyMaxBundle: - policy = kBundlePolicyUsageMaxBundle; - break; - case kBundlePolicyMaxCompat: - policy = kBundlePolicyUsageMaxCompat; - break; - } - RTC_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.BundlePolicy", policy, - kBundlePolicyUsageMax); - - // Record configured ice candidate pool size depending on the - // BUNDLE policy. See - // https://w3c.github.io/webrtc-pc/#dom-rtcconfiguration-icecandidatepoolsize - // The ICE candidate pool size is an optimization and it may be desirable - // to restrict the maximum size of the pre-gathered candidates. - switch (configuration_.bundle_policy) { - case kBundlePolicyBalanced: - RTC_HISTOGRAM_COUNTS_LINEAR( - "WebRTC.PeerConnection.CandidatePoolUsage.Balanced", - configuration_.ice_candidate_pool_size, 0, 255, 256); - break; - case kBundlePolicyMaxBundle: - RTC_HISTOGRAM_COUNTS_LINEAR( - "WebRTC.PeerConnection.CandidatePoolUsage.MaxBundle", - configuration_.ice_candidate_pool_size, 0, 255, 256); - break; - case kBundlePolicyMaxCompat: - RTC_HISTOGRAM_COUNTS_LINEAR( - "WebRTC.PeerConnection.CandidatePoolUsage.MaxCompat", - configuration_.ice_candidate_pool_size, 0, 255, 256); - break; - } - - // Record whether there was a local or remote provisional answer. - ProvisionalAnswerUsage pranswer = kProvisionalAnswerNotUsed; - if (local_description()->GetType() == SdpType::kPrAnswer) { - pranswer = kProvisionalAnswerLocal; - } else if (remote_description()->GetType() == SdpType::kPrAnswer) { - pranswer = kProvisionalAnswerRemote; - } - RTC_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.ProvisionalAnswer", - pranswer, kProvisionalAnswerMax); - - // Record the number of configured ICE servers for connected connections. - RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.PeerConnection.IceServers.Connected", - configuration_.servers.size(), 0, 31, 32); + ReportFirstConnectUsageMetrics(); } } +void PeerConnection::ReportFirstConnectUsageMetrics() { + // Record bundle-policy from configuration. Done here from + // connectionStateChange to limit to actually established connections. + BundlePolicyUsage policy = kBundlePolicyUsageMax; + switch (configuration_.bundle_policy) { + case kBundlePolicyBalanced: + policy = kBundlePolicyUsageBalanced; + break; + case kBundlePolicyMaxBundle: + policy = kBundlePolicyUsageMaxBundle; + break; + case kBundlePolicyMaxCompat: + policy = kBundlePolicyUsageMaxCompat; + break; + } + RTC_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.BundlePolicy", policy, + kBundlePolicyUsageMax); + + // Record configured ice candidate pool size depending on the + // BUNDLE policy. See + // https://w3c.github.io/webrtc-pc/#dom-rtcconfiguration-icecandidatepoolsize + // The ICE candidate pool size is an optimization and it may be desirable + // to restrict the maximum size of the pre-gathered candidates. + switch (configuration_.bundle_policy) { + case kBundlePolicyBalanced: + RTC_HISTOGRAM_COUNTS_LINEAR( + "WebRTC.PeerConnection.CandidatePoolUsage.Balanced", + configuration_.ice_candidate_pool_size, 0, 255, 256); + break; + case kBundlePolicyMaxBundle: + RTC_HISTOGRAM_COUNTS_LINEAR( + "WebRTC.PeerConnection.CandidatePoolUsage.MaxBundle", + configuration_.ice_candidate_pool_size, 0, 255, 256); + break; + case kBundlePolicyMaxCompat: + RTC_HISTOGRAM_COUNTS_LINEAR( + "WebRTC.PeerConnection.CandidatePoolUsage.MaxCompat", + configuration_.ice_candidate_pool_size, 0, 255, 256); + break; + } + + // Record whether there was a local or remote provisional answer. + ProvisionalAnswerUsage pranswer = kProvisionalAnswerNotUsed; + if (local_description()->GetType() == SdpType::kPrAnswer) { + pranswer = kProvisionalAnswerLocal; + } else if (remote_description()->GetType() == SdpType::kPrAnswer) { + pranswer = kProvisionalAnswerRemote; + } + RTC_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.ProvisionalAnswer", pranswer, + kProvisionalAnswerMax); + + // Record the number of configured ICE servers for connected connections. + RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.PeerConnection.IceServers.Connected", + configuration_.servers.size(), 0, 31, 32); +} + void PeerConnection::OnIceGatheringChange( PeerConnectionInterface::IceGatheringState new_state) { if (IsClosed()) { diff --git a/pc/peer_connection.h b/pc/peer_connection.h index 30bcdf3b80..4398058628 100644 --- a/pc/peer_connection.h +++ b/pc/peer_connection.h @@ -379,6 +379,9 @@ class PeerConnection : public PeerConnectionInternal, void ReportSdpBundleUsage( const SessionDescriptionInterface& remote_description) override; + // Report several UMA metrics on establishing the connection. + void ReportFirstConnectUsageMetrics() RTC_RUN_ON(signaling_thread()); + // Returns true if the PeerConnection is configured to use Unified Plan // semantics for creating offers/answers and setting local/remote // descriptions. If this is true the RtpTransceiver API will also be available