Reland "stats: migrate to Timestamp"
This is a reland of commit 2235776597e2f47ec353ac911428eb9a54d64a10 Original change's description: > stats: migrate to Timestamp > > BUG=webrtc:13756 > > Change-Id: I04ba57f9c2ca5a974a406814023911b4eb2d6d38 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/273942 > Commit-Queue: Philipp Hancke <phancke@microsoft.com> > Reviewed-by: Henrik Boström <hbos@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#38365} Bug: webrtc:13756 Change-Id: Ib8dc208197ae5e90f67114e7b043a73ee35421ea Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/279080 Reviewed-by: Henrik Boström <hbos@webrtc.org> Commit-Queue: Philipp Hancke <phancke@microsoft.com> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/main@{#38380}
This commit is contained in:
parent
f363d0d4d3
commit
036b3fdea2
@ -706,6 +706,7 @@ rtc_source_set("rtc_stats_api") {
|
||||
"../rtc_base:checks",
|
||||
"../rtc_base:refcount",
|
||||
"../rtc_base/system:rtc_export",
|
||||
"units:timestamp",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#include "api/ref_counted_base.h"
|
||||
#include "api/scoped_refptr.h"
|
||||
#include "api/stats/rtc_stats.h"
|
||||
#include "api/units/timestamp.h"
|
||||
// TODO(tommi): Remove this include after fixing iwyu issue in chromium.
|
||||
// See: third_party/blink/renderer/platform/peerconnection/rtc_stats.cc
|
||||
#include "rtc_base/ref_counted_object.h"
|
||||
@ -59,15 +60,21 @@ class RTC_EXPORT RTCStatsReport final
|
||||
StatsMap::const_iterator it_;
|
||||
};
|
||||
|
||||
// TODO(hbos): Remove "= 0" once Chromium unittest has been updated to call
|
||||
// with a parameter. crbug.com/627816
|
||||
// TODO(bugs.webrtc.org/13756): deprecate this in favor of Timestamp.
|
||||
// TODO(hbos): Remove "= 0" once downstream has been updated to call with a
|
||||
// parameter.
|
||||
static rtc::scoped_refptr<RTCStatsReport> Create(int64_t timestamp_us = 0);
|
||||
static rtc::scoped_refptr<RTCStatsReport> Create(Timestamp timestamp);
|
||||
|
||||
// TODO(bugs.webrtc.org/13756): deprecate this in favor of Timestamp.
|
||||
explicit RTCStatsReport(int64_t timestamp_us);
|
||||
explicit RTCStatsReport(Timestamp timestamp);
|
||||
|
||||
RTCStatsReport(const RTCStatsReport& other) = delete;
|
||||
rtc::scoped_refptr<RTCStatsReport> Copy() const;
|
||||
|
||||
int64_t timestamp_us() const { return timestamp_us_; }
|
||||
int64_t timestamp_us() const { return timestamp_.us_or(-1); }
|
||||
Timestamp timestamp() const { return timestamp_; }
|
||||
void AddStats(std::unique_ptr<const RTCStats> stats);
|
||||
// On success, returns a non-owning pointer to `stats`. If the stats ID is not
|
||||
// unique, `stats` is not inserted and nullptr is returned.
|
||||
@ -128,7 +135,7 @@ class RTC_EXPORT RTCStatsReport final
|
||||
~RTCStatsReport() = default;
|
||||
|
||||
private:
|
||||
int64_t timestamp_us_;
|
||||
Timestamp timestamp_;
|
||||
StatsMap stats_;
|
||||
};
|
||||
|
||||
|
||||
@ -1307,7 +1307,7 @@ rtc::scoped_refptr<RTCStatsReport> CreateReportFilteredBySelector(
|
||||
}
|
||||
}
|
||||
if (rtpstream_ids.empty())
|
||||
return RTCStatsReport::Create(report->timestamp_us());
|
||||
return RTCStatsReport::Create(report->timestamp());
|
||||
return TakeReferencedStats(report->Copy(), rtpstream_ids);
|
||||
}
|
||||
|
||||
@ -1469,7 +1469,7 @@ void RTCStatsCollector::ProducePartialResultsOnSignalingThread(
|
||||
RTC_DCHECK_RUN_ON(signaling_thread_);
|
||||
rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls;
|
||||
|
||||
partial_report_ = RTCStatsReport::Create(timestamp_us);
|
||||
partial_report_ = RTCStatsReport::Create(Timestamp::Micros(timestamp_us));
|
||||
|
||||
ProducePartialResultsOnSignalingThreadImpl(timestamp_us,
|
||||
partial_report_.get());
|
||||
@ -1505,7 +1505,7 @@ void RTCStatsCollector::ProducePartialResultsOnNetworkThread(
|
||||
|
||||
// Touching `network_report_` on this thread is safe by this method because
|
||||
// `network_report_event_` is reset before this method is invoked.
|
||||
network_report_ = RTCStatsReport::Create(timestamp_us);
|
||||
network_report_ = RTCStatsReport::Create(Timestamp::Micros(timestamp_us));
|
||||
|
||||
std::set<std::string> transport_names;
|
||||
if (sctp_transport_name) {
|
||||
|
||||
@ -62,7 +62,7 @@ rtc::scoped_refptr<RTCStatsReport> TakeReferencedStats(
|
||||
rtc::scoped_refptr<RTCStatsReport> report,
|
||||
const std::vector<std::string>& ids) {
|
||||
rtc::scoped_refptr<RTCStatsReport> result =
|
||||
RTCStatsReport::Create(report->timestamp_us());
|
||||
RTCStatsReport::Create(report->timestamp());
|
||||
for (const auto& id : ids) {
|
||||
TraverseAndTakeVisitedStats(report.get(), result.get(), id);
|
||||
}
|
||||
|
||||
@ -28,14 +28,14 @@ class RTCStatsTraversalTest : public ::testing::Test {
|
||||
candidate_pair_ = new RTCIceCandidatePairStats("candidate-pair", 0);
|
||||
local_candidate_ = new RTCLocalIceCandidateStats("local-candidate", 0);
|
||||
remote_candidate_ = new RTCRemoteIceCandidateStats("remote-candidate", 0);
|
||||
initial_report_ = RTCStatsReport::Create(0);
|
||||
initial_report_ = RTCStatsReport::Create(Timestamp::Zero());
|
||||
initial_report_->AddStats(std::unique_ptr<const RTCStats>(transport_));
|
||||
initial_report_->AddStats(std::unique_ptr<const RTCStats>(candidate_pair_));
|
||||
initial_report_->AddStats(
|
||||
std::unique_ptr<const RTCStats>(local_candidate_));
|
||||
initial_report_->AddStats(
|
||||
std::unique_ptr<const RTCStats>(remote_candidate_));
|
||||
result_ = RTCStatsReport::Create(0);
|
||||
result_ = RTCStatsReport::Create(Timestamp::Zero());
|
||||
}
|
||||
|
||||
void TakeReferencedStats(std::vector<const RTCStats*> start_nodes) {
|
||||
|
||||
@ -59,11 +59,17 @@ rtc::scoped_refptr<RTCStatsReport> RTCStatsReport::Create(
|
||||
return rtc::scoped_refptr<RTCStatsReport>(new RTCStatsReport(timestamp_us));
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<RTCStatsReport> RTCStatsReport::Create(Timestamp timestamp) {
|
||||
return rtc::scoped_refptr<RTCStatsReport>(new RTCStatsReport(timestamp));
|
||||
}
|
||||
|
||||
RTCStatsReport::RTCStatsReport(int64_t timestamp_us)
|
||||
: timestamp_us_(timestamp_us) {}
|
||||
: RTCStatsReport(Timestamp::Micros(timestamp_us)) {}
|
||||
|
||||
RTCStatsReport::RTCStatsReport(Timestamp timestamp) : timestamp_(timestamp) {}
|
||||
|
||||
rtc::scoped_refptr<RTCStatsReport> RTCStatsReport::Copy() const {
|
||||
rtc::scoped_refptr<RTCStatsReport> copy = Create(timestamp_us_);
|
||||
rtc::scoped_refptr<RTCStatsReport> copy = Create(timestamp_);
|
||||
for (auto it = stats_.begin(); it != stats_.end(); ++it) {
|
||||
copy->AddStats(it->second->copy());
|
||||
}
|
||||
|
||||
@ -53,8 +53,10 @@ class RTCTestStats3 : public RTCStats {
|
||||
WEBRTC_RTCSTATS_IMPL(RTCTestStats3, RTCStats, "test-stats-3", &string)
|
||||
|
||||
TEST(RTCStatsReport, AddAndGetStats) {
|
||||
rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(1337);
|
||||
rtc::scoped_refptr<RTCStatsReport> report =
|
||||
RTCStatsReport::Create(Timestamp::Micros(1337));
|
||||
EXPECT_EQ(report->timestamp_us(), 1337u);
|
||||
EXPECT_EQ(report->timestamp().us_or(-1), 1337u);
|
||||
EXPECT_EQ(report->size(), static_cast<size_t>(0));
|
||||
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("a0", 1)));
|
||||
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("a1", 2)));
|
||||
@ -87,8 +89,10 @@ TEST(RTCStatsReport, AddAndGetStats) {
|
||||
}
|
||||
|
||||
TEST(RTCStatsReport, StatsOrder) {
|
||||
rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(1337);
|
||||
rtc::scoped_refptr<RTCStatsReport> report =
|
||||
RTCStatsReport::Create(Timestamp::Micros(1337));
|
||||
EXPECT_EQ(report->timestamp_us(), 1337u);
|
||||
EXPECT_EQ(report->timestamp().us_or(-1), 1337u);
|
||||
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("C", 2)));
|
||||
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("D", 3)));
|
||||
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("B", 1)));
|
||||
@ -105,7 +109,8 @@ TEST(RTCStatsReport, StatsOrder) {
|
||||
}
|
||||
|
||||
TEST(RTCStatsReport, Take) {
|
||||
rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(0);
|
||||
rtc::scoped_refptr<RTCStatsReport> report =
|
||||
RTCStatsReport::Create(Timestamp::Zero());
|
||||
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("A", 1)));
|
||||
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("B", 2)));
|
||||
EXPECT_TRUE(report->Get("A"));
|
||||
@ -118,13 +123,17 @@ TEST(RTCStatsReport, Take) {
|
||||
}
|
||||
|
||||
TEST(RTCStatsReport, TakeMembersFrom) {
|
||||
rtc::scoped_refptr<RTCStatsReport> a = RTCStatsReport::Create(1337);
|
||||
rtc::scoped_refptr<RTCStatsReport> a =
|
||||
RTCStatsReport::Create(Timestamp::Micros(1337));
|
||||
EXPECT_EQ(a->timestamp_us(), 1337u);
|
||||
EXPECT_EQ(a->timestamp().us_or(-1), 1337u);
|
||||
a->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("B", 1)));
|
||||
a->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("C", 2)));
|
||||
a->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("E", 4)));
|
||||
rtc::scoped_refptr<RTCStatsReport> b = RTCStatsReport::Create(1338);
|
||||
rtc::scoped_refptr<RTCStatsReport> b =
|
||||
RTCStatsReport::Create(Timestamp::Micros(1338));
|
||||
EXPECT_EQ(b->timestamp_us(), 1338u);
|
||||
EXPECT_EQ(b->timestamp().us_or(-1), 1338u);
|
||||
b->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("A", 0)));
|
||||
b->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("D", 3)));
|
||||
b->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("F", 5)));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user