Start integrating StatsCounter class.
SampleCounter replaced with AvgCounter for metric WebRTC.Video.SendDelayInMs (removes duplicated code of SampleCounter). BUG=webrtc:5283 Review-Url: https://codereview.webrtc.org/2013403002 Cr-Commit-Position: refs/heads/master@{#13081}
This commit is contained in:
parent
fc22e03eb8
commit
40f54003d6
@ -22,7 +22,7 @@ const size_t kMaxPacketMapSize = 2000;
|
||||
|
||||
// Limit for the maximum number of streams to calculate stats for.
|
||||
const size_t kMaxSsrcMapSize = 50;
|
||||
const int kMinRequiredSamples = 200;
|
||||
const int kMinRequiredPeriodicSamples = 5;
|
||||
} // namespace
|
||||
|
||||
SendDelayStats::SendDelayStats(Clock* clock)
|
||||
@ -40,10 +40,10 @@ SendDelayStats::~SendDelayStats() {
|
||||
void SendDelayStats::UpdateHistograms() {
|
||||
rtc::CritScope lock(&crit_);
|
||||
for (const auto& it : send_delay_counters_) {
|
||||
int send_delay_ms = it.second.Avg(kMinRequiredSamples);
|
||||
if (send_delay_ms != -1) {
|
||||
AggregatedStats stats = it.second->GetStats();
|
||||
if (stats.num_samples >= kMinRequiredPeriodicSamples) {
|
||||
RTC_LOGGED_HISTOGRAM_COUNTS_10000("WebRTC.Video.SendDelayInMs",
|
||||
send_delay_ms);
|
||||
stats.average);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -56,6 +56,16 @@ void SendDelayStats::AddSsrcs(const VideoSendStream::Config& config) {
|
||||
ssrcs_.insert(ssrc);
|
||||
}
|
||||
|
||||
AvgCounter* SendDelayStats::GetSendDelayCounter(uint32_t ssrc) {
|
||||
const auto& it = send_delay_counters_.find(ssrc);
|
||||
if (it != send_delay_counters_.end())
|
||||
return it->second.get();
|
||||
|
||||
AvgCounter* counter = new AvgCounter(clock_, nullptr);
|
||||
send_delay_counters_[ssrc].reset(counter);
|
||||
return counter;
|
||||
}
|
||||
|
||||
void SendDelayStats::OnSendPacket(uint16_t packet_id,
|
||||
int64_t capture_time_ms,
|
||||
uint32_t ssrc) {
|
||||
@ -88,7 +98,7 @@ bool SendDelayStats::OnSentPacket(int packet_id, int64_t time_ms) {
|
||||
// TODO(asapersson): Remove SendSideDelayUpdated(), use capture -> sent.
|
||||
// Elapsed time from send (to transport) -> sent (leaving socket).
|
||||
int diff_ms = time_ms - it->second.send_time_ms;
|
||||
send_delay_counters_[it->second.ssrc].Add(diff_ms);
|
||||
GetSendDelayCounter(it->second.ssrc)->Add(diff_ms);
|
||||
packets_.erase(it);
|
||||
return true;
|
||||
}
|
||||
@ -104,15 +114,4 @@ void SendDelayStats::RemoveOld(int64_t now, PacketMap* packets) {
|
||||
}
|
||||
}
|
||||
|
||||
void SendDelayStats::SampleCounter::Add(int sample) {
|
||||
sum += sample;
|
||||
++num_samples;
|
||||
}
|
||||
|
||||
int SendDelayStats::SampleCounter::Avg(int min_required_samples) const {
|
||||
if (num_samples < min_required_samples || num_samples == 0)
|
||||
return -1;
|
||||
return (sum + (num_samples / 2)) / num_samples;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
#include "webrtc/common_types.h"
|
||||
#include "webrtc/modules/include/module_common_types.h"
|
||||
#include "webrtc/system_wrappers/include/clock.h"
|
||||
#include "webrtc/video/stats_counter.h"
|
||||
#include "webrtc/video_send_stream.h"
|
||||
|
||||
namespace webrtc {
|
||||
@ -61,21 +62,11 @@ class SendDelayStats : public SendPacketObserver {
|
||||
};
|
||||
typedef std::map<uint16_t, Packet, SequenceNumberOlderThan> PacketMap;
|
||||
|
||||
class SampleCounter {
|
||||
public:
|
||||
SampleCounter() : sum(0), num_samples(0) {}
|
||||
~SampleCounter() {}
|
||||
void Add(int sample);
|
||||
int Avg(int min_required_samples) const;
|
||||
|
||||
private:
|
||||
int sum;
|
||||
int num_samples;
|
||||
};
|
||||
|
||||
void UpdateHistograms();
|
||||
void RemoveOld(int64_t now, PacketMap* packets)
|
||||
EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
||||
AvgCounter* GetSendDelayCounter(uint32_t ssrc)
|
||||
EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
||||
|
||||
Clock* const clock_;
|
||||
rtc::CriticalSection crit_;
|
||||
@ -85,8 +76,10 @@ class SendDelayStats : public SendPacketObserver {
|
||||
size_t num_skipped_packets_ GUARDED_BY(crit_);
|
||||
|
||||
std::set<uint32_t> ssrcs_ GUARDED_BY(crit_);
|
||||
std::map<uint32_t, SampleCounter> send_delay_counters_
|
||||
GUARDED_BY(crit_); // Mapped by SSRC.
|
||||
|
||||
// Mapped by SSRC.
|
||||
std::map<uint32_t, std::unique_ptr<AvgCounter>> send_delay_counters_
|
||||
GUARDED_BY(crit_);
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -22,7 +22,8 @@ const uint32_t kRtxSsrc1 = 18;
|
||||
const uint32_t kRtxSsrc2 = 43;
|
||||
const uint16_t kPacketId = 2345;
|
||||
const int64_t kMaxPacketDelayMs = 11000;
|
||||
const int kMinRequiredSamples = 200;
|
||||
const int kMinRequiredPeriodicSamples = 5;
|
||||
const int kProcessIntervalMs = 2000;
|
||||
} // namespace
|
||||
|
||||
class SendDelayStatsTest : public ::testing::Test {
|
||||
@ -104,9 +105,12 @@ TEST_F(SendDelayStatsTest, OldPacketsRemoved) {
|
||||
TEST_F(SendDelayStatsTest, HistogramsAreUpdated) {
|
||||
metrics::Reset();
|
||||
const int64_t kDelayMs1 = 5;
|
||||
const int64_t kDelayMs2 = 10;
|
||||
const int64_t kDelayMs2 = 15;
|
||||
const int kNumSamples = kMinRequiredPeriodicSamples * kProcessIntervalMs /
|
||||
(kDelayMs1 + kDelayMs2) + 1;
|
||||
|
||||
uint16_t id = 0;
|
||||
for (int i = 0; i < kMinRequiredSamples; ++i) {
|
||||
for (int i = 0; i < kNumSamples; ++i) {
|
||||
OnSendPacket(++id, kSsrc1);
|
||||
clock_.AdvanceTimeMilliseconds(kDelayMs1);
|
||||
EXPECT_TRUE(OnSentPacket(id));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user