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

Unified Diff: webrtc/api/rtcstatscollector.cc

Issue 2567243003: RTCStatsCollector: Utilize network thread to minimize thread hops. (Closed)
Patch Set: Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/api/rtcstatscollector.cc
diff --git a/webrtc/api/rtcstatscollector.cc b/webrtc/api/rtcstatscollector.cc
index 9998d9aafe89ed40eb212712adff98caec0cd275..68e7f64a177fbd98b1f2d0932843e38667d78648 100644
--- a/webrtc/api/rtcstatscollector.cc
+++ b/webrtc/api/rtcstatscollector.cc
@@ -410,9 +410,16 @@ void RTCStatsCollector::GetStatsReport(
invoker_.AsyncInvoke<void>(RTC_FROM_HERE, signaling_thread_,
rtc::Bind(&RTCStatsCollector::ProducePartialResultsOnSignalingThread,
rtc::scoped_refptr<RTCStatsCollector>(this), timestamp_us));
+
+ // TODO(hbos): No stats are gathered on the worker thread, remove this.
invoker_.AsyncInvoke<void>(RTC_FROM_HERE, worker_thread_,
rtc::Bind(&RTCStatsCollector::ProducePartialResultsOnWorkerThread,
rtc::scoped_refptr<RTCStatsCollector>(this), timestamp_us));
+
+ // Prepare |channel_names_| and |media_info_| for use in
+ // |ProducePartialResultsOnNetworkThread|.
+ channel_name_pairs_.reset(pc_->session()->GetChannelNamePairs().release());
Taylor Brandstetter 2016/12/13 19:47:07 I don't think a new method (GetChannelNamePairs) i
pthatcher1 2016/12/13 23:50:18 I was thinking the exact same thing.
hbos 2016/12/14 14:56:31 I replaced GetTransportStats with GetSessionStats
+ media_info_.reset(PrepareMediaInfo_s().release());
invoker_.AsyncInvoke<void>(RTC_FROM_HERE, network_thread_,
rtc::Bind(&RTCStatsCollector::ProducePartialResultsOnNetworkThread,
rtc::scoped_refptr<RTCStatsCollector>(this), timestamp_us));
@@ -430,23 +437,6 @@ void RTCStatsCollector::ProducePartialResultsOnSignalingThread(
rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(
timestamp_us);
- SessionStats session_stats;
- if (pc_->session()->GetTransportStats(&session_stats)) {
- std::map<std::string, CertificateStatsPair> transport_cert_stats =
- PrepareTransportCertificateStats(session_stats);
- MediaInfo media_info = PrepareMediaInfo(session_stats);
-
- ProduceCertificateStats_s(
- timestamp_us, transport_cert_stats, report.get());
- ProduceCodecStats_s(
- timestamp_us, media_info, report.get());
- ProduceIceCandidateAndPairStats_s(
- timestamp_us, session_stats, report.get());
- ProduceRTPStreamStats_s(
- timestamp_us, session_stats, media_info, report.get());
- ProduceTransportStats_s(
- timestamp_us, session_stats, transport_cert_stats, report.get());
- }
ProduceDataChannelStats_s(timestamp_us, report.get());
ProduceMediaStreamAndTrackStats_s(timestamp_us, report.get());
ProducePeerConnectionStats_s(timestamp_us, report.get());
@@ -460,13 +450,8 @@ void RTCStatsCollector::ProducePartialResultsOnWorkerThread(
rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(
timestamp_us);
- // TODO(hbos): Gather stats on worker thread.
- // pc_->session()'s channels are owned by the signaling thread but there are
- // some stats that are gathered on the worker thread. Instead of a synchronous
- // invoke on "s->w" we could to the "w" work here asynchronously if it wasn't
- // for the ownership issue. Synchronous invokes in other places makes it
- // difficult to introduce locks without introducing deadlocks and the channels
- // are not reference counted.
+ // TODO(hbos): There are no stats to be gathered on this thread, remove this
+ // method.
Taylor Brandstetter 2016/12/13 19:47:07 There are still stats that are ultimately gathered
hbos 2016/12/14 14:56:31 Acknowledge. Out of curiosity: this meaning (block
Taylor Brandstetter 2016/12/15 01:12:53 Yes. Here, to be specific: https://cs.chromium.org
hbos 2016/12/15 16:12:45 Oh, good to know, so we still do a network -> work
Taylor Brandstetter 2016/12/15 17:35:19 Yep, and it's actually two hops, one each for audi
hbos 2016/12/16 10:38:02 That should be reducible to 1 hop, but I don't thi
AddPartialResults(report);
}
@@ -477,13 +462,23 @@ void RTCStatsCollector::ProducePartialResultsOnNetworkThread(
rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(
timestamp_us);
- // TODO(hbos): Gather stats on network thread.
- // pc_->session()'s channels are owned by the signaling thread but there are
- // some stats that are gathered on the network thread. Instead of a
- // synchronous invoke on "s->n" we could to the "n" work here asynchronously
- // if it wasn't for the ownership issue. Synchronous invokes in other places
- // makes it difficult to introduce locks without introducing deadlocks and the
- // channels are not reference counted.
+ std::unique_ptr<SessionStats> session_stats =
+ pc_->session()->GetSessionStats_n(*channel_name_pairs_);
Taylor Brandstetter 2016/12/13 19:47:07 Instead of adding GetSessionStats_n, how about jus
pthatcher1 2016/12/13 23:50:19 I agree, but better yet, we could just expose the
Taylor Brandstetter 2016/12/14 00:10:25 Good point. But that may be introducing more inter
hbos 2016/12/14 14:56:31 With the latest changes there are no new functions
Taylor Brandstetter 2016/12/15 01:12:53 Makes sense; I didn't consider that.
+ if (session_stats) {
+ std::map<std::string, CertificateStatsPair> transport_cert_stats =
+ PrepareTransportCertificateStats_n(*session_stats);
+
+ ProduceCertificateStats_n(
+ timestamp_us, transport_cert_stats, report.get());
+ ProduceCodecStats_n(
+ timestamp_us, *media_info_, report.get());
+ ProduceIceCandidateAndPairStats_n(
+ timestamp_us, *session_stats, report.get());
+ ProduceRTPStreamStats_n(
+ timestamp_us, *session_stats, *media_info_, report.get());
+ ProduceTransportStats_n(
+ timestamp_us, *session_stats, transport_cert_stats, report.get());
+ }
AddPartialResults(report);
}
@@ -528,11 +523,11 @@ void RTCStatsCollector::DeliverCachedReport() {
callbacks_.clear();
}
-void RTCStatsCollector::ProduceCertificateStats_s(
+void RTCStatsCollector::ProduceCertificateStats_n(
int64_t timestamp_us,
const std::map<std::string, CertificateStatsPair>& transport_cert_stats,
RTCStatsReport* report) const {
- RTC_DCHECK(signaling_thread_->IsCurrent());
+ RTC_DCHECK(network_thread_->IsCurrent());
for (const auto& transport_cert_stats_pair : transport_cert_stats) {
if (transport_cert_stats_pair.second.local) {
ProduceCertificateStatsFromSSLCertificateStats(
@@ -545,10 +540,10 @@ void RTCStatsCollector::ProduceCertificateStats_s(
}
}
-void RTCStatsCollector::ProduceCodecStats_s(
+void RTCStatsCollector::ProduceCodecStats_n(
int64_t timestamp_us, const MediaInfo& media_info,
RTCStatsReport* report) const {
- RTC_DCHECK(signaling_thread_->IsCurrent());
+ RTC_DCHECK(network_thread_->IsCurrent());
// Audio
if (media_info.voice) {
// Inbound
@@ -599,10 +594,10 @@ void RTCStatsCollector::ProduceDataChannelStats_s(
}
}
-void RTCStatsCollector::ProduceIceCandidateAndPairStats_s(
+void RTCStatsCollector::ProduceIceCandidateAndPairStats_n(
int64_t timestamp_us, const SessionStats& session_stats,
RTCStatsReport* report) const {
- RTC_DCHECK(signaling_thread_->IsCurrent());
+ RTC_DCHECK(network_thread_->IsCurrent());
for (const auto& transport_stats : session_stats.transport_stats) {
for (const auto& channel_stats : transport_stats.second.channel_stats) {
std::string transport_id = RTCTransportStatsIDFromTransportChannel(
@@ -675,10 +670,10 @@ void RTCStatsCollector::ProducePeerConnectionStats_s(
report->AddStats(std::move(stats));
}
-void RTCStatsCollector::ProduceRTPStreamStats_s(
+void RTCStatsCollector::ProduceRTPStreamStats_n(
int64_t timestamp_us, const SessionStats& session_stats,
const MediaInfo& media_info, RTCStatsReport* report) const {
- RTC_DCHECK(signaling_thread_->IsCurrent());
+ RTC_DCHECK(network_thread_->IsCurrent());
// Audio
if (media_info.voice) {
@@ -782,11 +777,11 @@ void RTCStatsCollector::ProduceRTPStreamStats_s(
}
}
-void RTCStatsCollector::ProduceTransportStats_s(
+void RTCStatsCollector::ProduceTransportStats_n(
int64_t timestamp_us, const SessionStats& session_stats,
const std::map<std::string, CertificateStatsPair>& transport_cert_stats,
RTCStatsReport* report) const {
- RTC_DCHECK(signaling_thread_->IsCurrent());
+ RTC_DCHECK(network_thread_->IsCurrent());
for (const auto& transport : session_stats.transport_stats) {
// Get reference to RTCP channel, if it exists.
std::string rtcp_transport_stats_id;
@@ -849,20 +844,20 @@ void RTCStatsCollector::ProduceTransportStats_s(
}
std::map<std::string, RTCStatsCollector::CertificateStatsPair>
-RTCStatsCollector::PrepareTransportCertificateStats(
+RTCStatsCollector::PrepareTransportCertificateStats_n(
const SessionStats& session_stats) const {
- RTC_DCHECK(signaling_thread_->IsCurrent());
+ RTC_DCHECK(network_thread_->IsCurrent());
std::map<std::string, CertificateStatsPair> transport_cert_stats;
for (const auto& transport_stats : session_stats.transport_stats) {
CertificateStatsPair certificate_stats_pair;
rtc::scoped_refptr<rtc::RTCCertificate> local_certificate;
- if (pc_->session()->GetLocalCertificate(
+ if (pc_->session()->GetLocalCertificate_n(
transport_stats.second.transport_name, &local_certificate)) {
certificate_stats_pair.local =
local_certificate->ssl_certificate().GetStats();
}
std::unique_ptr<rtc::SSLCertificate> remote_certificate =
- pc_->session()->GetRemoteSSLCertificate(
+ pc_->session()->GetRemoteSSLCertificate_n(
transport_stats.second.transport_name);
if (remote_certificate) {
certificate_stats_pair.remote = remote_certificate->GetStats();
@@ -874,20 +869,21 @@ RTCStatsCollector::PrepareTransportCertificateStats(
return transport_cert_stats;
}
-RTCStatsCollector::MediaInfo RTCStatsCollector::PrepareMediaInfo(
- const SessionStats& session_stats) const {
- MediaInfo media_info;
+std::unique_ptr<RTCStatsCollector::MediaInfo>
+RTCStatsCollector::PrepareMediaInfo_s() const {
+ RTC_DCHECK(signaling_thread_->IsCurrent());
+ std::unique_ptr<MediaInfo> media_info(new MediaInfo());
if (pc_->session()->voice_channel()) {
cricket::VoiceMediaInfo voice_media_info;
if (pc_->session()->voice_channel()->GetStats(&voice_media_info)) {
- media_info.voice = rtc::Optional<cricket::VoiceMediaInfo>(
+ media_info->voice = rtc::Optional<cricket::VoiceMediaInfo>(
std::move(voice_media_info));
}
}
if (pc_->session()->video_channel()) {
cricket::VideoMediaInfo video_media_info;
if (pc_->session()->video_channel()->GetStats(&video_media_info)) {
- media_info.video = rtc::Optional<cricket::VideoMediaInfo>(
+ media_info->video = rtc::Optional<cricket::VideoMediaInfo>(
std::move(video_media_info));
}
}

Powered by Google App Engine
This is Rietveld 408576698