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

Side by Side Diff: webrtc/api/rtcstatscollector.cc

Issue 2462573002: Refactor: Move RTCStatsCollector helper functions to anonymous namespace (Closed)
Patch Set: Created 4 years, 1 month 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/api/rtcstatscollector.h ('k') | 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 2016 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2016 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 case DataChannelInterface::kClosing: 64 case DataChannelInterface::kClosing:
65 return RTCDataChannelState::kClosing; 65 return RTCDataChannelState::kClosing;
66 case DataChannelInterface::kClosed: 66 case DataChannelInterface::kClosed:
67 return RTCDataChannelState::kClosed; 67 return RTCDataChannelState::kClosed;
68 default: 68 default:
69 RTC_NOTREACHED(); 69 RTC_NOTREACHED();
70 return nullptr; 70 return nullptr;
71 } 71 }
72 } 72 }
73 73
74 void ProduceCertificateStatsFromSSLCertificateStats(
75 int64_t timestamp_us, const rtc::SSLCertificateStats& certificate_stats,
76 RTCStatsReport* report) {
77 RTCCertificateStats* prev_certificate_stats = nullptr;
78 for (const rtc::SSLCertificateStats* s = &certificate_stats; s;
79 s = s->issuer.get()) {
80 RTCCertificateStats* certificate_stats = new RTCCertificateStats(
81 RTCCertificateIDFromFingerprint(s->fingerprint), timestamp_us);
82 certificate_stats->fingerprint = s->fingerprint;
83 certificate_stats->fingerprint_algorithm = s->fingerprint_algorithm;
84 certificate_stats->base64_certificate = s->base64_certificate;
85 if (prev_certificate_stats)
86 prev_certificate_stats->issuer_certificate_id = certificate_stats->id();
87 report->AddStats(std::unique_ptr<RTCCertificateStats>(certificate_stats));
88 prev_certificate_stats = certificate_stats;
89 }
90 }
91
92 const std::string& ProduceIceCandidateStats(
93 int64_t timestamp_us, const cricket::Candidate& candidate, bool is_local,
94 RTCStatsReport* report) {
95 const std::string& id = "RTCIceCandidate_" + candidate.id();
96 const RTCStats* stats = report->Get(id);
97 if (!stats) {
98 std::unique_ptr<RTCIceCandidateStats> candidate_stats;
99 if (is_local)
100 candidate_stats.reset(new RTCLocalIceCandidateStats(id, timestamp_us));
101 else
102 candidate_stats.reset(new RTCRemoteIceCandidateStats(id, timestamp_us));
103 candidate_stats->ip = candidate.address().ipaddr().ToString();
104 candidate_stats->port = static_cast<int32_t>(candidate.address().port());
105 candidate_stats->protocol = candidate.protocol();
106 candidate_stats->candidate_type = CandidateTypeToRTCIceCandidateType(
107 candidate.type());
108 candidate_stats->priority = static_cast<int32_t>(candidate.priority());
109
110 stats = candidate_stats.get();
111 report->AddStats(std::move(candidate_stats));
112 }
113 RTC_DCHECK_EQ(stats->type(), is_local ? RTCLocalIceCandidateStats::kType
114 : RTCRemoteIceCandidateStats::kType);
115 return stats->id();
116 }
117
74 } // namespace 118 } // namespace
75 119
76 rtc::scoped_refptr<RTCStatsCollector> RTCStatsCollector::Create( 120 rtc::scoped_refptr<RTCStatsCollector> RTCStatsCollector::Create(
77 PeerConnection* pc, int64_t cache_lifetime_us) { 121 PeerConnection* pc, int64_t cache_lifetime_us) {
78 return rtc::scoped_refptr<RTCStatsCollector>( 122 return rtc::scoped_refptr<RTCStatsCollector>(
79 new rtc::RefCountedObject<RTCStatsCollector>(pc, cache_lifetime_us)); 123 new rtc::RefCountedObject<RTCStatsCollector>(pc, cache_lifetime_us));
80 } 124 }
81 125
82 RTCStatsCollector::RTCStatsCollector(PeerConnection* pc, 126 RTCStatsCollector::RTCStatsCollector(PeerConnection* pc,
83 int64_t cache_lifetime_us) 127 int64_t cache_lifetime_us)
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 } 263 }
220 callbacks_.clear(); 264 callbacks_.clear();
221 } 265 }
222 266
223 void RTCStatsCollector::ProduceCertificateStats_s( 267 void RTCStatsCollector::ProduceCertificateStats_s(
224 int64_t timestamp_us, 268 int64_t timestamp_us,
225 const std::map<std::string, CertificateStatsPair>& transport_cert_stats, 269 const std::map<std::string, CertificateStatsPair>& transport_cert_stats,
226 RTCStatsReport* report) const { 270 RTCStatsReport* report) const {
227 RTC_DCHECK(signaling_thread_->IsCurrent()); 271 RTC_DCHECK(signaling_thread_->IsCurrent());
228 for (const auto& kvp : transport_cert_stats) { 272 for (const auto& kvp : transport_cert_stats) {
229 if (kvp.second.local) { 273 if (kvp.second.local) {
hta-webrtc 2016/10/28 11:27:33 Did I really let you get away with naming a local
hbos 2016/10/28 11:41:02 Yes :D Bwahaha. Okay, renamed.
230 ProduceCertificateStatsFromSSLCertificateStats_s( 274 ProduceCertificateStatsFromSSLCertificateStats(
231 timestamp_us, *kvp.second.local.get(), report); 275 timestamp_us, *kvp.second.local.get(), report);
232 } 276 }
233 if (kvp.second.remote) { 277 if (kvp.second.remote) {
234 ProduceCertificateStatsFromSSLCertificateStats_s( 278 ProduceCertificateStatsFromSSLCertificateStats(
235 timestamp_us, *kvp.second.remote.get(), report); 279 timestamp_us, *kvp.second.remote.get(), report);
236 } 280 }
237 } 281 }
238 } 282 }
239 283
240 void RTCStatsCollector::ProduceCertificateStatsFromSSLCertificateStats_s(
241 int64_t timestamp_us, const rtc::SSLCertificateStats& certificate_stats,
242 RTCStatsReport* report) const {
243 RTC_DCHECK(signaling_thread_->IsCurrent());
244 RTCCertificateStats* prev_certificate_stats = nullptr;
245 for (const rtc::SSLCertificateStats* s = &certificate_stats; s;
246 s = s->issuer.get()) {
247 RTCCertificateStats* certificate_stats = new RTCCertificateStats(
248 RTCCertificateIDFromFingerprint(s->fingerprint), timestamp_us);
249 certificate_stats->fingerprint = s->fingerprint;
250 certificate_stats->fingerprint_algorithm = s->fingerprint_algorithm;
251 certificate_stats->base64_certificate = s->base64_certificate;
252 if (prev_certificate_stats)
253 prev_certificate_stats->issuer_certificate_id = certificate_stats->id();
254 report->AddStats(std::unique_ptr<RTCCertificateStats>(certificate_stats));
255 prev_certificate_stats = certificate_stats;
256 }
257 }
258
259 void RTCStatsCollector::ProduceDataChannelStats_s( 284 void RTCStatsCollector::ProduceDataChannelStats_s(
260 int64_t timestamp_us, RTCStatsReport* report) const { 285 int64_t timestamp_us, RTCStatsReport* report) const {
261 RTC_DCHECK(signaling_thread_->IsCurrent()); 286 RTC_DCHECK(signaling_thread_->IsCurrent());
262 for (const rtc::scoped_refptr<DataChannel>& data_channel : 287 for (const rtc::scoped_refptr<DataChannel>& data_channel :
263 pc_->sctp_data_channels()) { 288 pc_->sctp_data_channels()) {
264 std::unique_ptr<RTCDataChannelStats> data_channel_stats( 289 std::unique_ptr<RTCDataChannelStats> data_channel_stats(
265 new RTCDataChannelStats( 290 new RTCDataChannelStats(
266 "RTCDataChannel_" + rtc::ToString<>(data_channel->id()), 291 "RTCDataChannel_" + rtc::ToString<>(data_channel->id()),
267 timestamp_us)); 292 timestamp_us));
268 data_channel_stats->label = data_channel->label(); 293 data_channel_stats->label = data_channel->label();
(...skipping 19 matching lines...) Expand all
288 channel_stats.connection_infos) { 313 channel_stats.connection_infos) {
289 std::unique_ptr<RTCIceCandidatePairStats> candidate_pair_stats( 314 std::unique_ptr<RTCIceCandidatePairStats> candidate_pair_stats(
290 new RTCIceCandidatePairStats( 315 new RTCIceCandidatePairStats(
291 RTCIceCandidatePairStatsIDFromConnectionInfo(info), 316 RTCIceCandidatePairStatsIDFromConnectionInfo(info),
292 timestamp_us)); 317 timestamp_us));
293 318
294 // TODO(hbos): There could be other candidates that are not paired with 319 // TODO(hbos): There could be other candidates that are not paired with
295 // anything. We don't have a complete list. Local candidates come from 320 // anything. We don't have a complete list. Local candidates come from
296 // Port objects, and prflx candidates (both local and remote) are only 321 // Port objects, and prflx candidates (both local and remote) are only
297 // stored in candidate pairs. crbug.com/632723 322 // stored in candidate pairs. crbug.com/632723
298 candidate_pair_stats->local_candidate_id = ProduceIceCandidateStats_s( 323 candidate_pair_stats->local_candidate_id = ProduceIceCandidateStats(
299 timestamp_us, info.local_candidate, true, report); 324 timestamp_us, info.local_candidate, true, report);
300 candidate_pair_stats->remote_candidate_id = ProduceIceCandidateStats_s( 325 candidate_pair_stats->remote_candidate_id = ProduceIceCandidateStats(
301 timestamp_us, info.remote_candidate, false, report); 326 timestamp_us, info.remote_candidate, false, report);
302 327
303 // TODO(hbos): This writable is different than the spec. It goes to 328 // TODO(hbos): This writable is different than the spec. It goes to
304 // false after a certain amount of time without a response passes. 329 // false after a certain amount of time without a response passes.
305 // crbug.com/633550 330 // crbug.com/633550
306 candidate_pair_stats->writable = info.writable; 331 candidate_pair_stats->writable = info.writable;
307 candidate_pair_stats->bytes_sent = 332 candidate_pair_stats->bytes_sent =
308 static_cast<uint64_t>(info.sent_total_bytes); 333 static_cast<uint64_t>(info.sent_total_bytes);
309 candidate_pair_stats->bytes_received = 334 candidate_pair_stats->bytes_received =
310 static_cast<uint64_t>(info.recv_total_bytes); 335 static_cast<uint64_t>(info.recv_total_bytes);
311 // TODO(hbos): The |info.rtt| measurement is smoothed. It shouldn't be 336 // TODO(hbos): The |info.rtt| measurement is smoothed. It shouldn't be
312 // smoothed according to the spec. crbug.com/633550. See 337 // smoothed according to the spec. crbug.com/633550. See
313 // https://w3c.github.io/webrtc-stats/#dom-rtcicecandidatepairstats-curr entrtt 338 // https://w3c.github.io/webrtc-stats/#dom-rtcicecandidatepairstats-curr entrtt
314 candidate_pair_stats->current_rtt = 339 candidate_pair_stats->current_rtt =
315 static_cast<double>(info.rtt) / 1000.0; 340 static_cast<double>(info.rtt) / 1000.0;
316 candidate_pair_stats->requests_sent = 341 candidate_pair_stats->requests_sent =
317 static_cast<uint64_t>(info.sent_ping_requests_total); 342 static_cast<uint64_t>(info.sent_ping_requests_total);
318 candidate_pair_stats->responses_received = 343 candidate_pair_stats->responses_received =
319 static_cast<uint64_t>(info.recv_ping_responses); 344 static_cast<uint64_t>(info.recv_ping_responses);
320 candidate_pair_stats->responses_sent = 345 candidate_pair_stats->responses_sent =
321 static_cast<uint64_t>(info.sent_ping_responses); 346 static_cast<uint64_t>(info.sent_ping_responses);
322 347
323 report->AddStats(std::move(candidate_pair_stats)); 348 report->AddStats(std::move(candidate_pair_stats));
324 } 349 }
325 } 350 }
326 } 351 }
327 } 352 }
328 353
329 const std::string& RTCStatsCollector::ProduceIceCandidateStats_s(
330 int64_t timestamp_us, const cricket::Candidate& candidate, bool is_local,
331 RTCStatsReport* report) const {
332 RTC_DCHECK(signaling_thread_->IsCurrent());
333 const std::string& id = "RTCIceCandidate_" + candidate.id();
334 const RTCStats* stats = report->Get(id);
335 if (!stats) {
336 std::unique_ptr<RTCIceCandidateStats> candidate_stats;
337 if (is_local)
338 candidate_stats.reset(new RTCLocalIceCandidateStats(id, timestamp_us));
339 else
340 candidate_stats.reset(new RTCRemoteIceCandidateStats(id, timestamp_us));
341 candidate_stats->ip = candidate.address().ipaddr().ToString();
342 candidate_stats->port = static_cast<int32_t>(candidate.address().port());
343 candidate_stats->protocol = candidate.protocol();
344 candidate_stats->candidate_type = CandidateTypeToRTCIceCandidateType(
345 candidate.type());
346 candidate_stats->priority = static_cast<int32_t>(candidate.priority());
347
348 stats = candidate_stats.get();
349 report->AddStats(std::move(candidate_stats));
350 }
351 RTC_DCHECK_EQ(stats->type(), is_local ? RTCLocalIceCandidateStats::kType
352 : RTCRemoteIceCandidateStats::kType);
353 return stats->id();
354 }
355
356 void RTCStatsCollector::ProducePeerConnectionStats_s( 354 void RTCStatsCollector::ProducePeerConnectionStats_s(
357 int64_t timestamp_us, RTCStatsReport* report) const { 355 int64_t timestamp_us, RTCStatsReport* report) const {
358 RTC_DCHECK(signaling_thread_->IsCurrent()); 356 RTC_DCHECK(signaling_thread_->IsCurrent());
359 // TODO(hbos): If data channels are removed from the peer connection this will 357 // TODO(hbos): If data channels are removed from the peer connection this will
360 // yield incorrect counts. Address before closing crbug.com/636818. See 358 // yield incorrect counts. Address before closing crbug.com/636818. See
361 // https://w3c.github.io/webrtc-stats/webrtc-stats.html#pcstats-dict*. 359 // https://w3c.github.io/webrtc-stats/webrtc-stats.html#pcstats-dict*.
362 uint32_t data_channels_opened = 0; 360 uint32_t data_channels_opened = 0;
363 const std::vector<rtc::scoped_refptr<DataChannel>>& data_channels = 361 const std::vector<rtc::scoped_refptr<DataChannel>>& data_channels =
364 pc_->sctp_data_channels(); 362 pc_->sctp_data_channels();
365 for (const rtc::scoped_refptr<DataChannel>& data_channel : data_channels) { 363 for (const rtc::scoped_refptr<DataChannel>& data_channel : data_channels) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 const std::string& type) { 470 const std::string& type) {
473 return CandidateTypeToRTCIceCandidateType(type); 471 return CandidateTypeToRTCIceCandidateType(type);
474 } 472 }
475 473
476 const char* DataStateToRTCDataChannelStateForTesting( 474 const char* DataStateToRTCDataChannelStateForTesting(
477 DataChannelInterface::DataState state) { 475 DataChannelInterface::DataState state) {
478 return DataStateToRTCDataChannelState(state); 476 return DataStateToRTCDataChannelState(state);
479 } 477 }
480 478
481 } // namespace webrtc 479 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/rtcstatscollector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698