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

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

Issue 2472113002: Correct stats for RTCPeerConnectionStats.dataChannels[Opened/Closed]. (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
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
11 #ifndef WEBRTC_API_RTCSTATSCOLLECTOR_H_ 11 #ifndef WEBRTC_API_RTCSTATSCOLLECTOR_H_
12 #define WEBRTC_API_RTCSTATSCOLLECTOR_H_ 12 #define WEBRTC_API_RTCSTATSCOLLECTOR_H_
13 13
14 #include <map> 14 #include <map>
15 #include <memory> 15 #include <memory>
16 #include <set>
16 #include <vector> 17 #include <vector>
17 18
19 #include "webrtc/api/datachannel.h"
18 #include "webrtc/api/datachannelinterface.h" 20 #include "webrtc/api/datachannelinterface.h"
19 #include "webrtc/api/stats/rtcstats_objects.h" 21 #include "webrtc/api/stats/rtcstats_objects.h"
20 #include "webrtc/api/stats/rtcstatsreport.h" 22 #include "webrtc/api/stats/rtcstatsreport.h"
21 #include "webrtc/base/asyncinvoker.h" 23 #include "webrtc/base/asyncinvoker.h"
22 #include "webrtc/base/refcount.h" 24 #include "webrtc/base/refcount.h"
23 #include "webrtc/base/scoped_ref_ptr.h" 25 #include "webrtc/base/scoped_ref_ptr.h"
26 #include "webrtc/base/sigslot.h"
24 #include "webrtc/base/sslidentity.h" 27 #include "webrtc/base/sslidentity.h"
25 #include "webrtc/base/timeutils.h" 28 #include "webrtc/base/timeutils.h"
26 29
27 namespace cricket { 30 namespace cricket {
28 class Candidate; 31 class Candidate;
29 } // namespace cricket 32 } // namespace cricket
30 33
31 namespace rtc { 34 namespace rtc {
32 class SSLCertificate; 35 class SSLCertificate;
33 } // namespace rtc 36 } // namespace rtc
34 37
35 namespace webrtc { 38 namespace webrtc {
36 39
37 class PeerConnection; 40 class PeerConnection;
38 struct SessionStats; 41 struct SessionStats;
39 42
40 class RTCStatsCollectorCallback : public virtual rtc::RefCountInterface { 43 class RTCStatsCollectorCallback : public virtual rtc::RefCountInterface {
41 public: 44 public:
42 virtual ~RTCStatsCollectorCallback() {} 45 virtual ~RTCStatsCollectorCallback() {}
43 46
44 virtual void OnStatsDelivered( 47 virtual void OnStatsDelivered(
45 const rtc::scoped_refptr<const RTCStatsReport>& report) = 0; 48 const rtc::scoped_refptr<const RTCStatsReport>& report) = 0;
46 }; 49 };
47 50
48 // All public methods of the collector are to be called on the signaling thread. 51 // All public methods of the collector are to be called on the signaling thread.
49 // Stats are gathered on the signaling, worker and network threads 52 // Stats are gathered on the signaling, worker and network threads
50 // asynchronously. The callback is invoked on the signaling thread. Resulting 53 // asynchronously. The callback is invoked on the signaling thread. Resulting
51 // reports are cached for |cache_lifetime_| ms. 54 // reports are cached for |cache_lifetime_| ms.
52 class RTCStatsCollector : public virtual rtc::RefCountInterface { 55 class RTCStatsCollector : public virtual rtc::RefCountInterface,
56 public sigslot::has_slots<> {
53 public: 57 public:
54 static rtc::scoped_refptr<RTCStatsCollector> Create( 58 static rtc::scoped_refptr<RTCStatsCollector> Create(
55 PeerConnection* pc, 59 PeerConnection* pc,
56 int64_t cache_lifetime_us = 50 * rtc::kNumMicrosecsPerMillisec); 60 int64_t cache_lifetime_us = 50 * rtc::kNumMicrosecsPerMillisec);
57 61
58 // Gets a recent stats report. If there is a report cached that is still fresh 62 // Gets a recent stats report. If there is a report cached that is still fresh
59 // it is returned, otherwise new stats are gathered and returned. A report is 63 // it is returned, otherwise new stats are gathered and returned. A report is
60 // considered fresh for |cache_lifetime_| ms. const RTCStatsReports are safe 64 // considered fresh for |cache_lifetime_| ms. const RTCStatsReports are safe
61 // to use across multiple threads and may be destructed on any thread. 65 // to use across multiple threads and may be destructed on any thread.
62 void GetStatsReport(rtc::scoped_refptr<RTCStatsCollectorCallback> callback); 66 void GetStatsReport(rtc::scoped_refptr<RTCStatsCollectorCallback> callback);
63 // Clears the cache's reference to the most recent stats report. Subsequently 67 // Clears the cache's reference to the most recent stats report. Subsequently
64 // calling |GetStatsReport| guarantees fresh stats. 68 // calling |GetStatsReport| guarantees fresh stats.
65 void ClearCachedStatsReport(); 69 void ClearCachedStatsReport();
66 70
71 // Exposed for testing only.
72 void OnDataChannelOpenedForTesting(DataChannel* channel);
73 void OnDataChannelClosedForTesting(DataChannel* channel);
74
67 protected: 75 protected:
68 RTCStatsCollector(PeerConnection* pc, int64_t cache_lifetime_us); 76 RTCStatsCollector(PeerConnection* pc, int64_t cache_lifetime_us);
69 77
70 // Stats gathering on a particular thread. Calls |AddPartialResults| before 78 // Stats gathering on a particular thread. Calls |AddPartialResults| before
71 // returning. Virtual for the sake of testing. 79 // returning. Virtual for the sake of testing.
72 virtual void ProducePartialResultsOnSignalingThread(int64_t timestamp_us); 80 virtual void ProducePartialResultsOnSignalingThread(int64_t timestamp_us);
73 virtual void ProducePartialResultsOnWorkerThread(int64_t timestamp_us); 81 virtual void ProducePartialResultsOnWorkerThread(int64_t timestamp_us);
74 virtual void ProducePartialResultsOnNetworkThread(int64_t timestamp_us); 82 virtual void ProducePartialResultsOnNetworkThread(int64_t timestamp_us);
75 83
76 // Can be called on any thread. 84 // Can be called on any thread.
77 void AddPartialResults( 85 void AddPartialResults(
78 const rtc::scoped_refptr<RTCStatsReport>& partial_report); 86 const rtc::scoped_refptr<RTCStatsReport>& partial_report);
79 87
80 private: 88 private:
89 // To allow |pc_| to wire up RTCStatsCollector::OnBlahBlah signal slots.
90 friend class PeerConnection;
91
81 struct CertificateStatsPair { 92 struct CertificateStatsPair {
82 std::unique_ptr<rtc::SSLCertificateStats> local; 93 std::unique_ptr<rtc::SSLCertificateStats> local;
83 std::unique_ptr<rtc::SSLCertificateStats> remote; 94 std::unique_ptr<rtc::SSLCertificateStats> remote;
84 }; 95 };
85 96
86 void AddPartialResults_s(rtc::scoped_refptr<RTCStatsReport> partial_report); 97 void AddPartialResults_s(rtc::scoped_refptr<RTCStatsReport> partial_report);
87 void DeliverCachedReport(); 98 void DeliverCachedReport();
88 99
89 // Produces |RTCCertificateStats|. 100 // Produces |RTCCertificateStats|.
90 void ProduceCertificateStats_s( 101 void ProduceCertificateStats_s(
(...skipping 17 matching lines...) Expand all
108 // Produces |RTCTransportStats|. 119 // Produces |RTCTransportStats|.
109 void ProduceTransportStats_s( 120 void ProduceTransportStats_s(
110 int64_t timestamp_us, const SessionStats& session_stats, 121 int64_t timestamp_us, const SessionStats& session_stats,
111 const std::map<std::string, CertificateStatsPair>& transport_cert_stats, 122 const std::map<std::string, CertificateStatsPair>& transport_cert_stats,
112 RTCStatsReport* report) const; 123 RTCStatsReport* report) const;
113 124
114 // Helper function to stats-producing functions. 125 // Helper function to stats-producing functions.
115 std::map<std::string, CertificateStatsPair> 126 std::map<std::string, CertificateStatsPair>
116 PrepareTransportCertificateStats_s(const SessionStats& session_stats) const; 127 PrepareTransportCertificateStats_s(const SessionStats& session_stats) const;
117 128
129 // Slots for signals (sigslot).
130 void OnDataChannelOpened(DataChannel* channel);
131 void OnDataChannelClosed(DataChannel* channel);
132
118 PeerConnection* const pc_; 133 PeerConnection* const pc_;
119 rtc::Thread* const signaling_thread_; 134 rtc::Thread* const signaling_thread_;
120 rtc::Thread* const worker_thread_; 135 rtc::Thread* const worker_thread_;
121 rtc::Thread* const network_thread_; 136 rtc::Thread* const network_thread_;
122 rtc::AsyncInvoker invoker_; 137 rtc::AsyncInvoker invoker_;
123 138
124 int num_pending_partial_reports_; 139 int num_pending_partial_reports_;
125 int64_t partial_report_timestamp_us_; 140 int64_t partial_report_timestamp_us_;
126 rtc::scoped_refptr<RTCStatsReport> partial_report_; 141 rtc::scoped_refptr<RTCStatsReport> partial_report_;
127 std::vector<rtc::scoped_refptr<RTCStatsCollectorCallback>> callbacks_; 142 std::vector<rtc::scoped_refptr<RTCStatsCollectorCallback>> callbacks_;
128 143
129 // A timestamp, in microseconds, that is based on a timer that is 144 // A timestamp, in microseconds, that is based on a timer that is
130 // monotonically increasing. That is, even if the system clock is modified the 145 // monotonically increasing. That is, even if the system clock is modified the
131 // difference between the timer and this timestamp is how fresh the cached 146 // difference between the timer and this timestamp is how fresh the cached
132 // report is. 147 // report is.
133 int64_t cache_timestamp_us_; 148 int64_t cache_timestamp_us_;
134 int64_t cache_lifetime_us_; 149 int64_t cache_lifetime_us_;
135 rtc::scoped_refptr<const RTCStatsReport> cached_report_; 150 rtc::scoped_refptr<const RTCStatsReport> cached_report_;
151
152 // The opened count goes up when a channel is fully opened and the closed
153 // count goes up if a previously opened channel has fully closed. The opened
154 // count does not go down when a channel closes, meaning (opened - closed) is
155 // the number of channels currently opened. A channel that is closed before
156 // reaching the open state does not affect these counters.
157 uint32_t data_channels_opened_;
158 uint32_t data_channels_closed_;
hta-webrtc 2016/11/03 13:49:58 This is actually the beginning of a new path in st
hbos 2016/11/03 15:02:02 Created struct InternalRecord and added a comment.
159 // Channels that have been opened, they remain in the set until fully closed.
160 std::set<DataChannel*> opened_data_channels_;
hta-webrtc 2016/11/03 13:49:58 Do we actually need this? I'd suggest not retainin
hbos 2016/11/03 15:02:02 Changed to std::set<uintptr_t>
136 }; 161 };
137 162
138 const char* CandidateTypeToRTCIceCandidateTypeForTesting( 163 const char* CandidateTypeToRTCIceCandidateTypeForTesting(
139 const std::string& type); 164 const std::string& type);
140 const char* DataStateToRTCDataChannelStateForTesting( 165 const char* DataStateToRTCDataChannelStateForTesting(
141 DataChannelInterface::DataState state); 166 DataChannelInterface::DataState state);
142 167
143 } // namespace webrtc 168 } // namespace webrtc
144 169
145 #endif // WEBRTC_API_RTCSTATSCOLLECTOR_H_ 170 #endif // WEBRTC_API_RTCSTATSCOLLECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698