From 0533b5eafe69b744f10fa178f5a6f9657eaeeb25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Bostr=C3=B6m?= Date: Mon, 3 Feb 2025 14:24:10 +0100 Subject: [PATCH] Add set_timestamp() method to RTCStats. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Useful for when creating aggregate stats objects, seems like an oversight that we don't have it already. Bug: None Change-Id: Ied36afd2122464a81c7d725825353f9af59fe632 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/376220 Auto-Submit: Henrik Boström Commit-Queue: Ilya Nikolaevskiy Reviewed-by: Ilya Nikolaevskiy Cr-Commit-Position: refs/heads/main@{#43844} --- api/stats/rtc_stats.h | 1 + stats/rtc_stats_unittest.cc | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/api/stats/rtc_stats.h b/api/stats/rtc_stats.h index 1310b3ae67..1ffb4316f3 100644 --- a/api/stats/rtc_stats.h +++ b/api/stats/rtc_stats.h @@ -63,6 +63,7 @@ class RTC_EXPORT RTCStats { const std::string& id() const { return id_; } // Time relative to the UNIX epoch (Jan 1, 1970, UTC), in microseconds. Timestamp timestamp() const { return timestamp_; } + void set_timestamp(Timestamp timestamp) { timestamp_ = timestamp; } // Returns the static member variable `kType` of the implementing class. virtual const char* type() const = 0; diff --git a/stats/rtc_stats_unittest.cc b/stats/rtc_stats_unittest.cc index 4918a14eaa..0757fb7940 100644 --- a/stats/rtc_stats_unittest.cc +++ b/stats/rtc_stats_unittest.cc @@ -484,6 +484,12 @@ TEST(RTCStatsTest, AttributeToString) { stats.GetAttribute(stats.m_map_string_double).ToString()); } +TEST(RTCStatsTest, SetTimestamp) { + RTCTestStats test_stats("testId", Timestamp::Micros(123)); + test_stats.set_timestamp(Timestamp::Micros(321)); + EXPECT_EQ(test_stats.timestamp(), Timestamp::Micros(321)); +} + // Death tests. // Disabled on Android because death tests misbehave on Android, see // base/test/gtest_util.h.