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

Unified Diff: webrtc/stats/rtcstatscollector.h

Issue 2270033004: RTCStatsCollector collecting stats on multiple threads. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed comments Created 4 years, 3 months 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
« no previous file with comments | « no previous file | webrtc/stats/rtcstatscollector.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/stats/rtcstatscollector.h
diff --git a/webrtc/stats/rtcstatscollector.h b/webrtc/stats/rtcstatscollector.h
index 735421d5410533e0b642125c3b27262aed30062a..ee59a100225489f57495064638c6b072aa2f66c5 100644
--- a/webrtc/stats/rtcstatscollector.h
+++ b/webrtc/stats/rtcstatscollector.h
@@ -12,9 +12,12 @@
#define WEBRTC_STATS_RTCSTATSCOLLECTOR_H_
#include <memory>
+#include <vector>
#include "webrtc/api/rtcstats_objects.h"
#include "webrtc/api/rtcstatsreport.h"
+#include "webrtc/base/asyncinvoker.h"
+#include "webrtc/base/refcount.h"
#include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/base/timeutils.h"
@@ -22,11 +25,21 @@ namespace webrtc {
class PeerConnection;
-// All calls to the collector and gathering of stats is performed on the
-// signaling thread. A stats report is cached for |cache_lifetime_| ms.
-class RTCStatsCollector {
+class RTCStatsCollectorCallback : public virtual rtc::RefCountInterface {
public:
- explicit RTCStatsCollector(
+ virtual ~RTCStatsCollectorCallback() {}
+
+ virtual void OnStatsDelivered(
+ const rtc::scoped_refptr<const RTCStatsReport>& report) = 0;
+};
+
+// All public methods of the collector are to be called on the signaling thread.
+// Stats are gathered on the signaling, worker and network threads
+// asynchronously. The callback is invoked on the signaling thread. Resulting
+// reports are cached for |cache_lifetime_| ms.
+class RTCStatsCollector : public virtual rtc::RefCountInterface {
+ public:
+ static rtc::scoped_refptr<RTCStatsCollector> Create(
PeerConnection* pc,
int64_t cache_lifetime_us = 50 * rtc::kNumMicrosecsPerMillisec);
@@ -34,18 +47,42 @@ class RTCStatsCollector {
// it is returned, otherwise new stats are gathered and returned. A report is
// considered fresh for |cache_lifetime_| ms. const RTCStatsReports are safe
// to use across multiple threads and may be destructed on any thread.
- rtc::scoped_refptr<const RTCStatsReport> GetStatsReport();
+ void GetStatsReport(rtc::scoped_refptr<RTCStatsCollectorCallback> callback);
// Clears the cache's reference to the most recent stats report. Subsequently
// calling |GetStatsReport| guarantees fresh stats.
void ClearCachedStatsReport();
+ protected:
+ RTCStatsCollector(PeerConnection* pc, int64_t cache_lifetime_us);
+
+ // Stats gathering on a particular thread. Calls |AddPartialResults| before
+ // returning. Virtual for the sake of testing.
+ virtual void ProducePartialResultsOnSignalingThread(int64_t timestamp_us);
+ virtual void ProducePartialResultsOnWorkerThread(int64_t timestamp_us);
+ virtual void ProducePartialResultsOnNetworkThread(int64_t timestamp_us);
+
+ // Can be called on any thread.
+ void AddPartialResults(
+ const rtc::scoped_refptr<RTCStatsReport>& partial_report);
+
private:
- bool IsOnSignalingThread() const;
+ void AddPartialResults_s(rtc::scoped_refptr<RTCStatsReport> partial_report);
+ void DeliverCachedReport();
- std::unique_ptr<RTCPeerConnectionStats> ProducePeerConnectionStats(
+ std::unique_ptr<RTCPeerConnectionStats> ProducePeerConnectionStats_s(
int64_t timestamp_us) const;
PeerConnection* const pc_;
+ rtc::Thread* const signaling_thread_;
+ rtc::Thread* const worker_thread_;
+ rtc::Thread* const network_thread_;
+ rtc::AsyncInvoker invoker_;
+
+ int num_pending_partial_reports_;
+ int64_t partial_report_timestamp_us_;
+ rtc::scoped_refptr<RTCStatsReport> partial_report_;
+ std::vector<rtc::scoped_refptr<RTCStatsCollectorCallback>> callbacks_;
+
// A timestamp, in microseconds, that is based on a timer that is
// monotonically increasing. That is, even if the system clock is modified the
// difference between the timer and this timestamp is how fresh the cached
« no previous file with comments | « no previous file | webrtc/stats/rtcstatscollector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698