RTCStatsCollector: timestamps updated.
Using a timestamp based on a timer that is monotonically increasing for the cache, so that cache's freshness can be checked regardless of if system clock is modified. Using a system clock for the stats' timestamp, which needs to be relative to UNIX epoch (Jan 1, 1970, UTC). This CL removes the dependency on faketiming.h. BUG=chromium:627816 NOTRY=True Review-Url: https://codereview.webrtc.org/2299643002 Cr-Commit-Position: refs/heads/master@{#13997}
This commit is contained in:
@ -49,17 +49,17 @@ class RTCStatsMemberInterface;
|
|||||||
// }
|
// }
|
||||||
class RTCStats {
|
class RTCStats {
|
||||||
public:
|
public:
|
||||||
RTCStats(const std::string& id, double timestamp)
|
RTCStats(const std::string& id, int64_t timestamp_us)
|
||||||
: id_(id), timestamp_(timestamp) {}
|
: id_(id), timestamp_us_(timestamp_us) {}
|
||||||
RTCStats(std::string&& id, double timestamp)
|
RTCStats(std::string&& id, int64_t timestamp_us)
|
||||||
: id_(std::move(id)), timestamp_(timestamp) {}
|
: id_(std::move(id)), timestamp_us_(timestamp_us) {}
|
||||||
virtual ~RTCStats() {}
|
virtual ~RTCStats() {}
|
||||||
|
|
||||||
virtual std::unique_ptr<RTCStats> copy() const = 0;
|
virtual std::unique_ptr<RTCStats> copy() const = 0;
|
||||||
|
|
||||||
const std::string& id() const { return id_; }
|
const std::string& id() const { return id_; }
|
||||||
// Time relative to the UNIX epoch (Jan 1, 1970, UTC), in seconds.
|
// Time relative to the UNIX epoch (Jan 1, 1970, UTC), in microseconds.
|
||||||
double timestamp() const { return timestamp_; }
|
int64_t timestamp_us() const { return timestamp_us_; }
|
||||||
// Returns the static member variable |kType| of the implementing class.
|
// Returns the static member variable |kType| of the implementing class.
|
||||||
virtual const char* type() const = 0;
|
virtual const char* type() const = 0;
|
||||||
// Returns a vector of pointers to all the RTCStatsMemberInterface members of
|
// Returns a vector of pointers to all the RTCStatsMemberInterface members of
|
||||||
@ -88,7 +88,7 @@ class RTCStats {
|
|||||||
size_t additional_capacity) const;
|
size_t additional_capacity) const;
|
||||||
|
|
||||||
std::string const id_;
|
std::string const id_;
|
||||||
double timestamp_;
|
int64_t timestamp_us_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// All |RTCStats| classes should use this macro in a public section of the class
|
// All |RTCStats| classes should use this macro in a public section of the class
|
||||||
@ -112,8 +112,8 @@ class RTCStats {
|
|||||||
// rtcfoostats.h:
|
// rtcfoostats.h:
|
||||||
// class RTCFooStats : public RTCStats {
|
// class RTCFooStats : public RTCStats {
|
||||||
// public:
|
// public:
|
||||||
// RTCFooStats(const std::string& id, double timestamp)
|
// RTCFooStats(const std::string& id, int64_t timestamp_us)
|
||||||
// : RTCStats(id, timestamp),
|
// : RTCStats(id, timestamp_us),
|
||||||
// foo("foo"),
|
// foo("foo"),
|
||||||
// bar("bar") {
|
// bar("bar") {
|
||||||
// }
|
// }
|
||||||
|
|||||||
@ -19,8 +19,8 @@ namespace webrtc {
|
|||||||
|
|
||||||
class RTCPeerConnectionStats : public RTCStats {
|
class RTCPeerConnectionStats : public RTCStats {
|
||||||
public:
|
public:
|
||||||
RTCPeerConnectionStats(const std::string& id, double timestamp);
|
RTCPeerConnectionStats(const std::string& id, int64_t timestamp_us);
|
||||||
RTCPeerConnectionStats(std::string&& id, double timestamp);
|
RTCPeerConnectionStats(std::string&& id, int64_t timestamp_us);
|
||||||
|
|
||||||
WEBRTC_RTCSTATS_IMPL(RTCStats, RTCPeerConnectionStats,
|
WEBRTC_RTCSTATS_IMPL(RTCStats, RTCPeerConnectionStats,
|
||||||
&data_channels_opened,
|
&data_channels_opened,
|
||||||
|
|||||||
@ -51,7 +51,7 @@ std::string VectorOfStringsToString(const std::vector<T>& strings) {
|
|||||||
std::string RTCStats::ToString() const {
|
std::string RTCStats::ToString() const {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << type() << " {\n id: \"" << id_ << "\"\n timestamp: "
|
oss << type() << " {\n id: \"" << id_ << "\"\n timestamp: "
|
||||||
<< timestamp_ << '\n';
|
<< timestamp_us_ << '\n';
|
||||||
for (const RTCStatsMemberInterface* member : Members()) {
|
for (const RTCStatsMemberInterface* member : Members()) {
|
||||||
oss << " " << member->name() << ": ";
|
oss << " " << member->name() << ": ";
|
||||||
if (member->is_defined()) {
|
if (member->is_defined()) {
|
||||||
|
|||||||
@ -15,13 +15,13 @@ namespace webrtc {
|
|||||||
const char RTCPeerConnectionStats::kType[] = "peer-connection";
|
const char RTCPeerConnectionStats::kType[] = "peer-connection";
|
||||||
|
|
||||||
RTCPeerConnectionStats::RTCPeerConnectionStats(
|
RTCPeerConnectionStats::RTCPeerConnectionStats(
|
||||||
const std::string& id, double timestamp)
|
const std::string& id, int64_t timestamp_us)
|
||||||
: RTCPeerConnectionStats(std::string(id), timestamp) {
|
: RTCPeerConnectionStats(std::string(id), timestamp_us) {
|
||||||
}
|
}
|
||||||
|
|
||||||
RTCPeerConnectionStats::RTCPeerConnectionStats(
|
RTCPeerConnectionStats::RTCPeerConnectionStats(
|
||||||
std::string&& id, double timestamp)
|
std::string&& id, int64_t timestamp_us)
|
||||||
: RTCStats(std::move(id), timestamp),
|
: RTCStats(std::move(id), timestamp_us),
|
||||||
data_channels_opened("dataChannelsOpened"),
|
data_channels_opened("dataChannelsOpened"),
|
||||||
data_channels_closed("dataChannelsClosed") {
|
data_channels_closed("dataChannelsClosed") {
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,8 +17,8 @@ namespace webrtc {
|
|||||||
|
|
||||||
class RTCTestStats : public RTCStats {
|
class RTCTestStats : public RTCStats {
|
||||||
public:
|
public:
|
||||||
RTCTestStats(const std::string& id, double timestamp)
|
RTCTestStats(const std::string& id, int64_t timestamp_us)
|
||||||
: RTCStats(id, timestamp),
|
: RTCStats(id, timestamp_us),
|
||||||
m_int32("mInt32"),
|
m_int32("mInt32"),
|
||||||
m_uint32("mUint32"),
|
m_uint32("mUint32"),
|
||||||
m_int64("mInt64"),
|
m_int64("mInt64"),
|
||||||
@ -72,8 +72,8 @@ const char RTCTestStats::kType[] = "test-stats";
|
|||||||
|
|
||||||
class RTCChildStats : public RTCStats {
|
class RTCChildStats : public RTCStats {
|
||||||
public:
|
public:
|
||||||
RTCChildStats(const std::string& id, double timestamp)
|
RTCChildStats(const std::string& id, int64_t timestamp_us)
|
||||||
: RTCStats(id, timestamp),
|
: RTCStats(id, timestamp_us),
|
||||||
child_int("childInt") {}
|
child_int("childInt") {}
|
||||||
|
|
||||||
WEBRTC_RTCSTATS_IMPL(RTCStats, RTCChildStats,
|
WEBRTC_RTCSTATS_IMPL(RTCStats, RTCChildStats,
|
||||||
@ -86,8 +86,8 @@ const char RTCChildStats::kType[] = "child-stats";
|
|||||||
|
|
||||||
class RTCGrandChildStats : public RTCChildStats {
|
class RTCGrandChildStats : public RTCChildStats {
|
||||||
public:
|
public:
|
||||||
RTCGrandChildStats(const std::string& id, double timestamp)
|
RTCGrandChildStats(const std::string& id, int64_t timestamp_us)
|
||||||
: RTCChildStats(id, timestamp),
|
: RTCChildStats(id, timestamp_us),
|
||||||
grandchild_int("grandchildInt") {}
|
grandchild_int("grandchildInt") {}
|
||||||
|
|
||||||
WEBRTC_RTCSTATS_IMPL(RTCChildStats, RTCGrandChildStats,
|
WEBRTC_RTCSTATS_IMPL(RTCChildStats, RTCGrandChildStats,
|
||||||
@ -99,9 +99,9 @@ class RTCGrandChildStats : public RTCChildStats {
|
|||||||
const char RTCGrandChildStats::kType[] = "grandchild-stats";
|
const char RTCGrandChildStats::kType[] = "grandchild-stats";
|
||||||
|
|
||||||
TEST(RTCStatsTest, RTCStatsAndMembers) {
|
TEST(RTCStatsTest, RTCStatsAndMembers) {
|
||||||
RTCTestStats stats("testId", 42.0);
|
RTCTestStats stats("testId", 42);
|
||||||
EXPECT_EQ(stats.id(), "testId");
|
EXPECT_EQ(stats.id(), "testId");
|
||||||
EXPECT_EQ(stats.timestamp(), 42.0);
|
EXPECT_EQ(stats.timestamp_us(), static_cast<int64_t>(42));
|
||||||
std::vector<const RTCStatsMemberInterface*> members = stats.Members();
|
std::vector<const RTCStatsMemberInterface*> members = stats.Members();
|
||||||
EXPECT_EQ(members.size(), static_cast<size_t>(14));
|
EXPECT_EQ(members.size(), static_cast<size_t>(14));
|
||||||
for (const RTCStatsMemberInterface* member : members) {
|
for (const RTCStatsMemberInterface* member : members) {
|
||||||
|
|||||||
@ -16,32 +16,38 @@
|
|||||||
|
|
||||||
#include "webrtc/api/peerconnection.h"
|
#include "webrtc/api/peerconnection.h"
|
||||||
#include "webrtc/base/checks.h"
|
#include "webrtc/base/checks.h"
|
||||||
|
#include "webrtc/base/timing.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
RTCStatsCollector::RTCStatsCollector(
|
RTCStatsCollector::RTCStatsCollector(
|
||||||
PeerConnection* pc,
|
PeerConnection* pc,
|
||||||
double cache_lifetime,
|
int64_t cache_lifetime_us)
|
||||||
std::unique_ptr<rtc::Timing> timing)
|
|
||||||
: pc_(pc),
|
: pc_(pc),
|
||||||
timing_(std::move(timing)),
|
cache_timestamp_us_(0),
|
||||||
cache_timestamp_(0.0),
|
cache_lifetime_us_(cache_lifetime_us) {
|
||||||
cache_lifetime_(cache_lifetime) {
|
|
||||||
RTC_DCHECK(pc_);
|
RTC_DCHECK(pc_);
|
||||||
RTC_DCHECK(timing_);
|
|
||||||
RTC_DCHECK(IsOnSignalingThread());
|
RTC_DCHECK(IsOnSignalingThread());
|
||||||
RTC_DCHECK_GE(cache_lifetime_, 0.0);
|
RTC_DCHECK_GE(cache_lifetime_us_, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::scoped_refptr<const RTCStatsReport> RTCStatsCollector::GetStatsReport() {
|
rtc::scoped_refptr<const RTCStatsReport> RTCStatsCollector::GetStatsReport() {
|
||||||
RTC_DCHECK(IsOnSignalingThread());
|
RTC_DCHECK(IsOnSignalingThread());
|
||||||
double now = timing_->TimerNow();
|
// "Now" using a monotonically increasing timer.
|
||||||
if (cached_report_ && now - cache_timestamp_ <= cache_lifetime_)
|
int64_t cache_now_us = rtc::TimeMicros();
|
||||||
|
if (cached_report_ &&
|
||||||
|
cache_now_us - cache_timestamp_us_ <= cache_lifetime_us_) {
|
||||||
return cached_report_;
|
return cached_report_;
|
||||||
cache_timestamp_ = now;
|
}
|
||||||
|
cache_timestamp_us_ = cache_now_us;
|
||||||
|
// "Now" using a system clock, relative to the UNIX epoch (Jan 1, 1970, UTC),
|
||||||
|
// in microseconds. The system clock could be modified and is not necessarily
|
||||||
|
// monotonically increasing.
|
||||||
|
int64_t timestamp_us = static_cast<int64_t>(
|
||||||
|
rtc::Timing::WallTimeNow() * rtc::kNumMicrosecsPerSec);
|
||||||
|
|
||||||
rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create();
|
rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create();
|
||||||
report->AddStats(ProducePeerConnectionStats());
|
report->AddStats(ProducePeerConnectionStats(timestamp_us));
|
||||||
|
|
||||||
cached_report_ = report;
|
cached_report_ = report;
|
||||||
return cached_report_;
|
return cached_report_;
|
||||||
@ -57,7 +63,7 @@ bool RTCStatsCollector::IsOnSignalingThread() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<RTCPeerConnectionStats>
|
std::unique_ptr<RTCPeerConnectionStats>
|
||||||
RTCStatsCollector::ProducePeerConnectionStats() const {
|
RTCStatsCollector::ProducePeerConnectionStats(int64_t timestamp_us) const {
|
||||||
// TODO(hbos): If data channels are removed from the peer connection this will
|
// TODO(hbos): If data channels are removed from the peer connection this will
|
||||||
// yield incorrect counts. Address before closing crbug.com/636818. See
|
// yield incorrect counts. Address before closing crbug.com/636818. See
|
||||||
// https://w3c.github.io/webrtc-stats/webrtc-stats.html#pcstats-dict*.
|
// https://w3c.github.io/webrtc-stats/webrtc-stats.html#pcstats-dict*.
|
||||||
@ -71,7 +77,7 @@ RTCStatsCollector::ProducePeerConnectionStats() const {
|
|||||||
// There is always just one |RTCPeerConnectionStats| so its |id| can be a
|
// There is always just one |RTCPeerConnectionStats| so its |id| can be a
|
||||||
// constant.
|
// constant.
|
||||||
std::unique_ptr<RTCPeerConnectionStats> stats(
|
std::unique_ptr<RTCPeerConnectionStats> stats(
|
||||||
new RTCPeerConnectionStats("RTCPeerConnection", cache_timestamp_));
|
new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us));
|
||||||
stats->data_channels_opened = data_channels_opened;
|
stats->data_channels_opened = data_channels_opened;
|
||||||
stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) -
|
stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) -
|
||||||
data_channels_opened;
|
data_channels_opened;
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
#include "webrtc/api/rtcstats_objects.h"
|
#include "webrtc/api/rtcstats_objects.h"
|
||||||
#include "webrtc/api/rtcstatsreport.h"
|
#include "webrtc/api/rtcstatsreport.h"
|
||||||
#include "webrtc/base/scoped_ref_ptr.h"
|
#include "webrtc/base/scoped_ref_ptr.h"
|
||||||
#include "webrtc/base/timing.h"
|
#include "webrtc/base/timeutils.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
@ -28,9 +28,7 @@ class RTCStatsCollector {
|
|||||||
public:
|
public:
|
||||||
explicit RTCStatsCollector(
|
explicit RTCStatsCollector(
|
||||||
PeerConnection* pc,
|
PeerConnection* pc,
|
||||||
double cache_lifetime = 0.05,
|
int64_t cache_lifetime_us = 50 * rtc::kNumMicrosecsPerMillisec);
|
||||||
std::unique_ptr<rtc::Timing> timing = std::unique_ptr<rtc::Timing>(
|
|
||||||
new rtc::Timing()));
|
|
||||||
|
|
||||||
// Gets a recent stats report. If there is a report cached that is still fresh
|
// Gets a recent stats report. If there is a report cached that is still fresh
|
||||||
// it is returned, otherwise new stats are gathered and returned. A report is
|
// it is returned, otherwise new stats are gathered and returned. A report is
|
||||||
@ -44,13 +42,16 @@ class RTCStatsCollector {
|
|||||||
private:
|
private:
|
||||||
bool IsOnSignalingThread() const;
|
bool IsOnSignalingThread() const;
|
||||||
|
|
||||||
std::unique_ptr<RTCPeerConnectionStats> ProducePeerConnectionStats() const;
|
std::unique_ptr<RTCPeerConnectionStats> ProducePeerConnectionStats(
|
||||||
|
int64_t timestamp_us) const;
|
||||||
|
|
||||||
PeerConnection* const pc_;
|
PeerConnection* const pc_;
|
||||||
mutable std::unique_ptr<rtc::Timing> timing_;
|
// A timestamp, in microseconds, that is based on a timer that is
|
||||||
// Time relative to the UNIX epoch (Jan 1, 1970, UTC), in seconds.
|
// monotonically increasing. That is, even if the system clock is modified the
|
||||||
double cache_timestamp_;
|
// difference between the timer and this timestamp is how fresh the cached
|
||||||
double cache_lifetime_; // In seconds.
|
// report is.
|
||||||
|
int64_t cache_timestamp_us_;
|
||||||
|
int64_t cache_lifetime_us_;
|
||||||
rtc::scoped_refptr<const RTCStatsReport> cached_report_;
|
rtc::scoped_refptr<const RTCStatsReport> cached_report_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -21,9 +21,12 @@
|
|||||||
#include "webrtc/api/test/mock_peerconnection.h"
|
#include "webrtc/api/test/mock_peerconnection.h"
|
||||||
#include "webrtc/api/test/mock_webrtcsession.h"
|
#include "webrtc/api/test/mock_webrtcsession.h"
|
||||||
#include "webrtc/base/checks.h"
|
#include "webrtc/base/checks.h"
|
||||||
|
#include "webrtc/base/fakeclock.h"
|
||||||
#include "webrtc/base/gunit.h"
|
#include "webrtc/base/gunit.h"
|
||||||
#include "webrtc/base/logging.h"
|
#include "webrtc/base/logging.h"
|
||||||
#include "webrtc/base/test/faketiming.h"
|
#include "webrtc/base/timedelta.h"
|
||||||
|
#include "webrtc/base/timeutils.h"
|
||||||
|
#include "webrtc/base/timing.h"
|
||||||
#include "webrtc/media/base/fakemediaengine.h"
|
#include "webrtc/media/base/fakemediaengine.h"
|
||||||
|
|
||||||
using testing::Return;
|
using testing::Return;
|
||||||
@ -78,17 +81,16 @@ class RTCStatsCollectorTest : public testing::Test {
|
|||||||
public:
|
public:
|
||||||
RTCStatsCollectorTest()
|
RTCStatsCollectorTest()
|
||||||
: test_(new rtc::RefCountedObject<RTCStatsCollectorTester>()),
|
: test_(new rtc::RefCountedObject<RTCStatsCollectorTester>()),
|
||||||
timing_(new rtc::FakeTiming()),
|
collector_(&test_->pc(), 50 * rtc::kNumMicrosecsPerMillisec) {
|
||||||
collector_(&test_->pc(), 0.05, std::unique_ptr<rtc::Timing>(timing_)) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
rtc::scoped_refptr<RTCStatsCollectorTester> test_;
|
rtc::scoped_refptr<RTCStatsCollectorTester> test_;
|
||||||
rtc::FakeTiming* timing_; // Owned by |collector_|.
|
|
||||||
RTCStatsCollector collector_;
|
RTCStatsCollector collector_;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(RTCStatsCollectorTest, CachedStatsReport) {
|
TEST_F(RTCStatsCollectorTest, CachedStatsReport) {
|
||||||
|
rtc::ScopedFakeClock fake_clock;
|
||||||
// Caching should ensure |a| and |b| are the same report.
|
// Caching should ensure |a| and |b| are the same report.
|
||||||
rtc::scoped_refptr<const RTCStatsReport> a = collector_.GetStatsReport();
|
rtc::scoped_refptr<const RTCStatsReport> a = collector_.GetStatsReport();
|
||||||
rtc::scoped_refptr<const RTCStatsReport> b = collector_.GetStatsReport();
|
rtc::scoped_refptr<const RTCStatsReport> b = collector_.GetStatsReport();
|
||||||
@ -100,19 +102,24 @@ TEST_F(RTCStatsCollectorTest, CachedStatsReport) {
|
|||||||
EXPECT_TRUE(c);
|
EXPECT_TRUE(c);
|
||||||
EXPECT_NE(b.get(), c.get());
|
EXPECT_NE(b.get(), c.get());
|
||||||
// Invalidate cache by advancing time.
|
// Invalidate cache by advancing time.
|
||||||
timing_->AdvanceTimeMillisecs(51.0);
|
fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(51));
|
||||||
rtc::scoped_refptr<const RTCStatsReport> d = collector_.GetStatsReport();
|
rtc::scoped_refptr<const RTCStatsReport> d = collector_.GetStatsReport();
|
||||||
EXPECT_TRUE(d);
|
EXPECT_TRUE(d);
|
||||||
EXPECT_NE(c.get(), d.get());
|
EXPECT_NE(c.get(), d.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) {
|
TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) {
|
||||||
|
int64_t before = static_cast<int64_t>(
|
||||||
|
rtc::Timing::WallTimeNow() * rtc::kNumMicrosecsPerSec);
|
||||||
rtc::scoped_refptr<const RTCStatsReport> report = collector_.GetStatsReport();
|
rtc::scoped_refptr<const RTCStatsReport> report = collector_.GetStatsReport();
|
||||||
|
int64_t after = static_cast<int64_t>(
|
||||||
|
rtc::Timing::WallTimeNow() * rtc::kNumMicrosecsPerSec);
|
||||||
EXPECT_EQ(report->GetStatsOfType<RTCPeerConnectionStats>().size(),
|
EXPECT_EQ(report->GetStatsOfType<RTCPeerConnectionStats>().size(),
|
||||||
static_cast<size_t>(1)) << "Expecting 1 RTCPeerConnectionStats.";
|
static_cast<size_t>(1)) << "Expecting 1 RTCPeerConnectionStats.";
|
||||||
const RTCStats* stats = report->Get("RTCPeerConnection");
|
const RTCStats* stats = report->Get("RTCPeerConnection");
|
||||||
EXPECT_TRUE(stats);
|
EXPECT_TRUE(stats);
|
||||||
EXPECT_EQ(stats->timestamp(), timing_->TimerNow());
|
EXPECT_LE(before, stats->timestamp_us());
|
||||||
|
EXPECT_LE(stats->timestamp_us(), after);
|
||||||
{
|
{
|
||||||
// Expected stats with no data channels
|
// Expected stats with no data channels
|
||||||
const RTCPeerConnectionStats& pcstats =
|
const RTCPeerConnectionStats& pcstats =
|
||||||
|
|||||||
@ -18,8 +18,8 @@ namespace webrtc {
|
|||||||
|
|
||||||
class RTCTestStats1 : public RTCStats {
|
class RTCTestStats1 : public RTCStats {
|
||||||
public:
|
public:
|
||||||
RTCTestStats1(const std::string& id, double timestamp)
|
RTCTestStats1(const std::string& id, int64_t timestamp_us)
|
||||||
: RTCStats(id, timestamp),
|
: RTCStats(id, timestamp_us),
|
||||||
integer("integer") {}
|
integer("integer") {}
|
||||||
|
|
||||||
WEBRTC_RTCSTATS_IMPL(RTCStats, RTCTestStats1,
|
WEBRTC_RTCSTATS_IMPL(RTCStats, RTCTestStats1,
|
||||||
@ -32,8 +32,8 @@ const char RTCTestStats1::kType[] = "test-stats-1";
|
|||||||
|
|
||||||
class RTCTestStats2 : public RTCStats {
|
class RTCTestStats2 : public RTCStats {
|
||||||
public:
|
public:
|
||||||
RTCTestStats2(const std::string& id, double timestamp)
|
RTCTestStats2(const std::string& id, int64_t timestamp_us)
|
||||||
: RTCStats(id, timestamp),
|
: RTCStats(id, timestamp_us),
|
||||||
number("number") {}
|
number("number") {}
|
||||||
|
|
||||||
WEBRTC_RTCSTATS_IMPL(RTCStats, RTCTestStats2,
|
WEBRTC_RTCSTATS_IMPL(RTCStats, RTCTestStats2,
|
||||||
@ -46,8 +46,8 @@ const char RTCTestStats2::kType[] = "test-stats-2";
|
|||||||
|
|
||||||
class RTCTestStats3 : public RTCStats {
|
class RTCTestStats3 : public RTCStats {
|
||||||
public:
|
public:
|
||||||
RTCTestStats3(const std::string& id, double timestamp)
|
RTCTestStats3(const std::string& id, int64_t timestamp_us)
|
||||||
: RTCStats(id, timestamp),
|
: RTCStats(id, timestamp_us),
|
||||||
string("string") {}
|
string("string") {}
|
||||||
|
|
||||||
WEBRTC_RTCSTATS_IMPL(RTCStats, RTCTestStats3,
|
WEBRTC_RTCSTATS_IMPL(RTCStats, RTCTestStats3,
|
||||||
@ -61,12 +61,12 @@ const char RTCTestStats3::kType[] = "test-stats-3";
|
|||||||
TEST(RTCStatsReport, AddAndGetStats) {
|
TEST(RTCStatsReport, AddAndGetStats) {
|
||||||
rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create();
|
rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create();
|
||||||
EXPECT_EQ(report->size(), static_cast<size_t>(0));
|
EXPECT_EQ(report->size(), static_cast<size_t>(0));
|
||||||
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("a0", 1.0)));
|
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("a0", 1)));
|
||||||
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("a1", 2.0)));
|
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("a1", 2)));
|
||||||
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("b0", 4.0)));
|
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("b0", 4)));
|
||||||
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("b1", 8.0)));
|
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("b1", 8)));
|
||||||
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("a2", 16.0)));
|
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("a2", 16)));
|
||||||
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("b2", 32.0)));
|
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("b2", 32)));
|
||||||
EXPECT_EQ(report->size(), static_cast<size_t>(6));
|
EXPECT_EQ(report->size(), static_cast<size_t>(6));
|
||||||
|
|
||||||
EXPECT_EQ(report->Get("missing"), nullptr);
|
EXPECT_EQ(report->Get("missing"), nullptr);
|
||||||
@ -75,17 +75,17 @@ TEST(RTCStatsReport, AddAndGetStats) {
|
|||||||
|
|
||||||
std::vector<const RTCTestStats1*> a = report->GetStatsOfType<RTCTestStats1>();
|
std::vector<const RTCTestStats1*> a = report->GetStatsOfType<RTCTestStats1>();
|
||||||
EXPECT_EQ(a.size(), static_cast<size_t>(3));
|
EXPECT_EQ(a.size(), static_cast<size_t>(3));
|
||||||
uint32_t mask = 0;
|
int64_t mask = 0;
|
||||||
for (const RTCTestStats1* stats : a)
|
for (const RTCTestStats1* stats : a)
|
||||||
mask |= static_cast<uint32_t>(stats->timestamp());
|
mask |= stats->timestamp_us();
|
||||||
EXPECT_EQ(mask, static_cast<uint32_t>(1 | 2 | 16));
|
EXPECT_EQ(mask, static_cast<int64_t>(1 | 2 | 16));
|
||||||
|
|
||||||
std::vector<const RTCTestStats2*> b = report->GetStatsOfType<RTCTestStats2>();
|
std::vector<const RTCTestStats2*> b = report->GetStatsOfType<RTCTestStats2>();
|
||||||
EXPECT_EQ(b.size(), static_cast<size_t>(3));
|
EXPECT_EQ(b.size(), static_cast<size_t>(3));
|
||||||
mask = 0;
|
mask = 0;
|
||||||
for (const RTCTestStats2* stats : b)
|
for (const RTCTestStats2* stats : b)
|
||||||
mask |= static_cast<uint32_t>(stats->timestamp());
|
mask |= stats->timestamp_us();
|
||||||
EXPECT_EQ(mask, static_cast<uint32_t>(4 | 8 | 32));
|
EXPECT_EQ(mask, static_cast<int64_t>(4 | 8 | 32));
|
||||||
|
|
||||||
EXPECT_EQ(report->GetStatsOfType<RTCTestStats3>().size(),
|
EXPECT_EQ(report->GetStatsOfType<RTCTestStats3>().size(),
|
||||||
static_cast<size_t>(0));
|
static_cast<size_t>(0));
|
||||||
@ -93,39 +93,39 @@ TEST(RTCStatsReport, AddAndGetStats) {
|
|||||||
|
|
||||||
TEST(RTCStatsReport, StatsOrder) {
|
TEST(RTCStatsReport, StatsOrder) {
|
||||||
rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create();
|
rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create();
|
||||||
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("C", 2.0)));
|
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("C", 2)));
|
||||||
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("D", 3.0)));
|
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("D", 3)));
|
||||||
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("B", 1.0)));
|
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("B", 1)));
|
||||||
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("A", 0.0)));
|
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("A", 0)));
|
||||||
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("E", 4.0)));
|
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("E", 4)));
|
||||||
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("F", 5.0)));
|
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("F", 5)));
|
||||||
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("G", 6.0)));
|
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("G", 6)));
|
||||||
size_t i = 0;
|
int64_t i = 0;
|
||||||
for (const RTCStats& stats : *report) {
|
for (const RTCStats& stats : *report) {
|
||||||
EXPECT_EQ(static_cast<size_t>(stats.timestamp()), i);
|
EXPECT_EQ(stats.timestamp_us(), i);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
EXPECT_EQ(i, static_cast<size_t>(7));
|
EXPECT_EQ(i, static_cast<int64_t>(7));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(RTCStatsReport, TakeMembersFrom) {
|
TEST(RTCStatsReport, TakeMembersFrom) {
|
||||||
rtc::scoped_refptr<RTCStatsReport> a = RTCStatsReport::Create();
|
rtc::scoped_refptr<RTCStatsReport> a = RTCStatsReport::Create();
|
||||||
a->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("B", 1.0)));
|
a->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("B", 1)));
|
||||||
a->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("C", 2.0)));
|
a->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("C", 2)));
|
||||||
a->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("E", 4.0)));
|
a->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("E", 4)));
|
||||||
rtc::scoped_refptr<RTCStatsReport> b = RTCStatsReport::Create();
|
rtc::scoped_refptr<RTCStatsReport> b = RTCStatsReport::Create();
|
||||||
b->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("A", 0.0)));
|
b->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("A", 0)));
|
||||||
b->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("D", 3.0)));
|
b->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("D", 3)));
|
||||||
b->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("F", 5.0)));
|
b->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("F", 5)));
|
||||||
|
|
||||||
a->TakeMembersFrom(b);
|
a->TakeMembersFrom(b);
|
||||||
EXPECT_EQ(b->size(), static_cast<size_t>(0));
|
EXPECT_EQ(b->size(), static_cast<size_t>(0));
|
||||||
size_t i = 0;
|
int64_t i = 0;
|
||||||
for (const RTCStats& stats : *a) {
|
for (const RTCStats& stats : *a) {
|
||||||
EXPECT_EQ(static_cast<size_t>(stats.timestamp()), i);
|
EXPECT_EQ(stats.timestamp_us(), i);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
EXPECT_EQ(i, static_cast<size_t>(6));
|
EXPECT_EQ(i, static_cast<int64_t>(6));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|||||||
Reference in New Issue
Block a user