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

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: (nits, no need to rerun bots yet) Created 4 years, 4 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') | webrtc/stats/rtcstatscollector.cc » ('J')
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 1e4d6c3c2685f8e0961d78b9ca3c9b86eadf7624..1b7d3677692e699fe7d0f113ed1bab774c788ae9 100644
--- a/webrtc/stats/rtcstatscollector.h
+++ b/webrtc/stats/rtcstatscollector.h
@@ -12,9 +12,13 @@
#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/criticalsection.h"
+#include "webrtc/base/refcount.h"
#include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/base/timing.h"
@@ -22,11 +26,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,
double cache_lifetime = 0.05,
std::unique_ptr<rtc::Timing> timing = std::unique_ptr<rtc::Timing>(
@@ -36,18 +50,49 @@ 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:
+ // Takes ownership of |timing| (not using |std::unique_ptr| due to
+ // incompatibility with |rtc::RefCountedObject| constructors).
+ RTCStatsCollector(
+ PeerConnection* pc,
+ double cache_lifetime,
+ rtc::Timing* timing);
+
+ // Stats gathering on a particular thread. Calls |AddPartialResults| before
+ // returning. Virtual for the sake of testing.
+ virtual void ProducePartialResultsOnSignalingThread_s(double timestamp);
+ virtual void ProducePartialResultsOnWorkerThread_w(double timestamp);
+ virtual void ProducePartialResultsOnNetworkThread_n(double timestamp);
hta-webrtc 2016/08/31 09:57:36 Is the _s/_n/_w suffix a WebRTC convention that we
hbos 2016/09/01 14:16:16 Probably not, I'll skip it for these three.
+
+ // Can be called on any thread.
+ void AddPartialResults(
+ const rtc::scoped_refptr<RTCStatsReport>& partial_report,
+ double timestamp);
+
private:
- bool IsOnSignalingThread() const;
+ void AddPartialResults_s(rtc::scoped_refptr<RTCStatsReport> partial_report,
+ double timestamp);
- std::unique_ptr<RTCPeerConnectionStats> ProducePeerConnectionStats() const;
+ std::unique_ptr<RTCPeerConnectionStats> ProducePeerConnectionStats_s(
+ double timestamp) const;
PeerConnection* const pc_;
- mutable std::unique_ptr<rtc::Timing> timing_;
+ rtc::Thread* const signaling_thread_;
+ rtc::Thread* const worker_thread_;
+ rtc::Thread* const network_thread_;
+ rtc::AsyncInvoker invoker_;
+
+ rtc::CriticalSection lock_;
hta-webrtc 2016/08/31 09:57:36 Please add GUARDED_BY statements on the stuff that
hbos 2016/09/01 14:16:16 Done.
+ int num_pending_partial_reports_;
+ rtc::scoped_refptr<RTCStatsReport> partial_report_;
+ std::vector<rtc::scoped_refptr<RTCStatsCollectorCallback>> callbacks_;
+
+ const std::unique_ptr<rtc::Timing> timing_;
// Time relative to the UNIX epoch (Jan 1, 1970, UTC), in seconds.
double cache_timestamp_;
double cache_lifetime_; // In seconds.
« no previous file with comments | « no previous file | webrtc/stats/rtcstatscollector.cc » ('j') | webrtc/stats/rtcstatscollector.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698