Revert "stats: migrate to Timestamp"

This reverts commit 2235776597e2f47ec353ac911428eb9a54d64a10.

Reason for revert: Breaks compile.

RTCStatsReport::Create(timestamp) needs default value.

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: I7eba2bb510af73be50397bd92f730bc6de1ce676
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/279044
Auto-Submit: Mirko Bonadei <mbonadei@webrtc.org>
Owners-Override: Mirko Bonadei <mbonadei@webrtc.org>
Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38369}
This commit is contained in:
Mirko Bonadei 2022-10-12 14:22:09 +00:00 committed by WebRTC LUCI CQ
parent 2068d0daa7
commit c0794c23ff
7 changed files with 18 additions and 39 deletions

View File

@ -706,7 +706,6 @@ rtc_source_set("rtc_stats_api") {
"../rtc_base:checks", "../rtc_base:checks",
"../rtc_base:refcount", "../rtc_base:refcount",
"../rtc_base/system:rtc_export", "../rtc_base/system:rtc_export",
"units:timestamp",
] ]
} }

View File

@ -23,7 +23,6 @@
#include "api/ref_counted_base.h" #include "api/ref_counted_base.h"
#include "api/scoped_refptr.h" #include "api/scoped_refptr.h"
#include "api/stats/rtc_stats.h" #include "api/stats/rtc_stats.h"
#include "api/units/timestamp.h"
// TODO(tommi): Remove this include after fixing iwyu issue in chromium. // TODO(tommi): Remove this include after fixing iwyu issue in chromium.
// See: third_party/blink/renderer/platform/peerconnection/rtc_stats.cc // See: third_party/blink/renderer/platform/peerconnection/rtc_stats.cc
#include "rtc_base/ref_counted_object.h" #include "rtc_base/ref_counted_object.h"
@ -60,19 +59,15 @@ class RTC_EXPORT RTCStatsReport final
StatsMap::const_iterator it_; StatsMap::const_iterator it_;
}; };
// TODO(bugs.webrtc.org/13756): deprecate this in favor of Timestamp. // TODO(hbos): Remove "= 0" once Chromium unittest has been updated to call
static rtc::scoped_refptr<RTCStatsReport> Create(int64_t timestamp_us); // with a parameter. crbug.com/627816
static rtc::scoped_refptr<RTCStatsReport> Create(Timestamp timestamp); static rtc::scoped_refptr<RTCStatsReport> Create(int64_t timestamp_us = 0);
// TODO(bugs.webrtc.org/13756): deprecate this in favor of Timestamp.
explicit RTCStatsReport(int64_t timestamp_us); explicit RTCStatsReport(int64_t timestamp_us);
explicit RTCStatsReport(Timestamp timestamp);
RTCStatsReport(const RTCStatsReport& other) = delete; RTCStatsReport(const RTCStatsReport& other) = delete;
rtc::scoped_refptr<RTCStatsReport> Copy() const; rtc::scoped_refptr<RTCStatsReport> Copy() const;
int64_t timestamp_us() const { return timestamp_.us_or(-1); } int64_t timestamp_us() const { return timestamp_us_; }
Timestamp timestamp() const { return timestamp_; }
void AddStats(std::unique_ptr<const RTCStats> stats); void AddStats(std::unique_ptr<const RTCStats> stats);
// On success, returns a non-owning pointer to `stats`. If the stats ID is not // On success, returns a non-owning pointer to `stats`. If the stats ID is not
// unique, `stats` is not inserted and nullptr is returned. // unique, `stats` is not inserted and nullptr is returned.
@ -133,7 +128,7 @@ class RTC_EXPORT RTCStatsReport final
~RTCStatsReport() = default; ~RTCStatsReport() = default;
private: private:
Timestamp timestamp_; int64_t timestamp_us_;
StatsMap stats_; StatsMap stats_;
}; };

View File

@ -1307,7 +1307,7 @@ rtc::scoped_refptr<RTCStatsReport> CreateReportFilteredBySelector(
} }
} }
if (rtpstream_ids.empty()) if (rtpstream_ids.empty())
return RTCStatsReport::Create(report->timestamp()); return RTCStatsReport::Create(report->timestamp_us());
return TakeReferencedStats(report->Copy(), rtpstream_ids); return TakeReferencedStats(report->Copy(), rtpstream_ids);
} }
@ -1469,7 +1469,7 @@ void RTCStatsCollector::ProducePartialResultsOnSignalingThread(
RTC_DCHECK_RUN_ON(signaling_thread_); RTC_DCHECK_RUN_ON(signaling_thread_);
rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls;
partial_report_ = RTCStatsReport::Create(Timestamp::Micros(timestamp_us)); partial_report_ = RTCStatsReport::Create(timestamp_us);
ProducePartialResultsOnSignalingThreadImpl(timestamp_us, ProducePartialResultsOnSignalingThreadImpl(timestamp_us,
partial_report_.get()); partial_report_.get());
@ -1505,7 +1505,7 @@ void RTCStatsCollector::ProducePartialResultsOnNetworkThread(
// Touching `network_report_` on this thread is safe by this method because // Touching `network_report_` on this thread is safe by this method because
// `network_report_event_` is reset before this method is invoked. // `network_report_event_` is reset before this method is invoked.
network_report_ = RTCStatsReport::Create(Timestamp::Micros(timestamp_us)); network_report_ = RTCStatsReport::Create(timestamp_us);
std::set<std::string> transport_names; std::set<std::string> transport_names;
if (sctp_transport_name) { if (sctp_transport_name) {

View File

@ -62,7 +62,7 @@ rtc::scoped_refptr<RTCStatsReport> TakeReferencedStats(
rtc::scoped_refptr<RTCStatsReport> report, rtc::scoped_refptr<RTCStatsReport> report,
const std::vector<std::string>& ids) { const std::vector<std::string>& ids) {
rtc::scoped_refptr<RTCStatsReport> result = rtc::scoped_refptr<RTCStatsReport> result =
RTCStatsReport::Create(report->timestamp()); RTCStatsReport::Create(report->timestamp_us());
for (const auto& id : ids) { for (const auto& id : ids) {
TraverseAndTakeVisitedStats(report.get(), result.get(), id); TraverseAndTakeVisitedStats(report.get(), result.get(), id);
} }

View File

@ -28,14 +28,14 @@ class RTCStatsTraversalTest : public ::testing::Test {
candidate_pair_ = new RTCIceCandidatePairStats("candidate-pair", 0); candidate_pair_ = new RTCIceCandidatePairStats("candidate-pair", 0);
local_candidate_ = new RTCLocalIceCandidateStats("local-candidate", 0); local_candidate_ = new RTCLocalIceCandidateStats("local-candidate", 0);
remote_candidate_ = new RTCRemoteIceCandidateStats("remote-candidate", 0); remote_candidate_ = new RTCRemoteIceCandidateStats("remote-candidate", 0);
initial_report_ = RTCStatsReport::Create(Timestamp::Zero()); initial_report_ = RTCStatsReport::Create(0);
initial_report_->AddStats(std::unique_ptr<const RTCStats>(transport_)); 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>(candidate_pair_));
initial_report_->AddStats( initial_report_->AddStats(
std::unique_ptr<const RTCStats>(local_candidate_)); std::unique_ptr<const RTCStats>(local_candidate_));
initial_report_->AddStats( initial_report_->AddStats(
std::unique_ptr<const RTCStats>(remote_candidate_)); std::unique_ptr<const RTCStats>(remote_candidate_));
result_ = RTCStatsReport::Create(Timestamp::Zero()); result_ = RTCStatsReport::Create(0);
} }
void TakeReferencedStats(std::vector<const RTCStats*> start_nodes) { void TakeReferencedStats(std::vector<const RTCStats*> start_nodes) {

View File

@ -59,17 +59,11 @@ rtc::scoped_refptr<RTCStatsReport> RTCStatsReport::Create(
return rtc::scoped_refptr<RTCStatsReport>(new RTCStatsReport(timestamp_us)); 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) RTCStatsReport::RTCStatsReport(int64_t timestamp_us)
: RTCStatsReport(Timestamp::Micros(timestamp_us)) {} : timestamp_us_(timestamp_us) {}
RTCStatsReport::RTCStatsReport(Timestamp timestamp) : timestamp_(timestamp) {}
rtc::scoped_refptr<RTCStatsReport> RTCStatsReport::Copy() const { rtc::scoped_refptr<RTCStatsReport> RTCStatsReport::Copy() const {
rtc::scoped_refptr<RTCStatsReport> copy = Create(timestamp_); rtc::scoped_refptr<RTCStatsReport> copy = Create(timestamp_us_);
for (auto it = stats_.begin(); it != stats_.end(); ++it) { for (auto it = stats_.begin(); it != stats_.end(); ++it) {
copy->AddStats(it->second->copy()); copy->AddStats(it->second->copy());
} }

View File

@ -53,10 +53,8 @@ class RTCTestStats3 : public RTCStats {
WEBRTC_RTCSTATS_IMPL(RTCTestStats3, RTCStats, "test-stats-3", &string) WEBRTC_RTCSTATS_IMPL(RTCTestStats3, RTCStats, "test-stats-3", &string)
TEST(RTCStatsReport, AddAndGetStats) { TEST(RTCStatsReport, AddAndGetStats) {
rtc::scoped_refptr<RTCStatsReport> report = rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(1337);
RTCStatsReport::Create(Timestamp::Micros(1337));
EXPECT_EQ(report->timestamp_us(), 1337u); EXPECT_EQ(report->timestamp_us(), 1337u);
EXPECT_EQ(report->timestamp().us_or(-1), 1337u);
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))); report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("a0", 1)));
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("a1", 2))); report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("a1", 2)));
@ -89,10 +87,8 @@ TEST(RTCStatsReport, AddAndGetStats) {
} }
TEST(RTCStatsReport, StatsOrder) { TEST(RTCStatsReport, StatsOrder) {
rtc::scoped_refptr<RTCStatsReport> report = rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(1337);
RTCStatsReport::Create(Timestamp::Micros(1337));
EXPECT_EQ(report->timestamp_us(), 1337u); 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("C", 2)));
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("D", 3))); report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("D", 3)));
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("B", 1))); report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("B", 1)));
@ -109,8 +105,7 @@ TEST(RTCStatsReport, StatsOrder) {
} }
TEST(RTCStatsReport, Take) { TEST(RTCStatsReport, Take) {
rtc::scoped_refptr<RTCStatsReport> report = rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(0);
RTCStatsReport::Create(Timestamp::Zero());
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("A", 1))); report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("A", 1)));
report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("B", 2))); report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("B", 2)));
EXPECT_TRUE(report->Get("A")); EXPECT_TRUE(report->Get("A"));
@ -123,17 +118,13 @@ TEST(RTCStatsReport, Take) {
} }
TEST(RTCStatsReport, TakeMembersFrom) { TEST(RTCStatsReport, TakeMembersFrom) {
rtc::scoped_refptr<RTCStatsReport> a = rtc::scoped_refptr<RTCStatsReport> a = RTCStatsReport::Create(1337);
RTCStatsReport::Create(Timestamp::Micros(1337));
EXPECT_EQ(a->timestamp_us(), 1337u); 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("B", 1)));
a->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("C", 2))); a->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("C", 2)));
a->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("E", 4))); a->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("E", 4)));
rtc::scoped_refptr<RTCStatsReport> b = rtc::scoped_refptr<RTCStatsReport> b = RTCStatsReport::Create(1338);
RTCStatsReport::Create(Timestamp::Micros(1338));
EXPECT_EQ(b->timestamp_us(), 1338u); 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("A", 0)));
b->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("D", 3))); b->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("D", 3)));
b->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("F", 5))); b->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("F", 5)));