Add a default implementation in metrics_default.cc of histograms methods in system_wrappers/interface/metrics.h.

Updated tests to use the default implementation and removed the test implementation (webrtc/test/histograms.h).

BUG=

Review-Url: https://codereview.webrtc.org/1915523002
Cr-Commit-Position: refs/heads/master@{#12829}
This commit is contained in:
asapersson
2016-05-20 06:29:46 -07:00
committed by Commit bot
parent 7268f28520
commit 01d70a3978
20 changed files with 827 additions and 517 deletions

View File

@ -26,6 +26,7 @@
#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
#include "webrtc/system_wrappers/include/metrics_default.h"
#include "webrtc/system_wrappers/include/rtp_to_ntp.h"
#include "webrtc/test/call_test.h"
#include "webrtc/test/direct_transport.h"
@ -36,7 +37,6 @@
#include "webrtc/test/fake_encoder.h"
#include "webrtc/test/frame_generator.h"
#include "webrtc/test/frame_generator_capturer.h"
#include "webrtc/test/histogram.h"
#include "webrtc/test/rtp_rtcp_observer.h"
#include "webrtc/test/testsupport/fileutils.h"
#include "webrtc/test/testsupport/perf_test.h"
@ -150,7 +150,7 @@ void CallPerfTest::TestAudioVideoSync(FecMode fec,
const uint32_t kAudioSendSsrc = 1234;
const uint32_t kAudioRecvSsrc = 5678;
test::ClearHistograms();
metrics::Reset();
VoiceEngine* voice_engine = VoiceEngine::Create();
VoEBase* voe_base = VoEBase::GetInterface(voice_engine);
VoECodec* voe_codec = VoECodec::GetInterface(voice_engine);
@ -300,7 +300,7 @@ void CallPerfTest::TestAudioVideoSync(FecMode fec,
VoiceEngine::Delete(voice_engine);
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.AVSyncOffsetInMs"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.AVSyncOffsetInMs"));
}
TEST_F(CallPerfTest, PlaysOutAudioAndVideoInSyncWithVideoNtpDrift) {

View File

@ -19,7 +19,7 @@
#include "webrtc/modules/video_coding/utility/mock/mock_frame_dropper.h"
#include "webrtc/system_wrappers/include/clock.h"
#include "webrtc/system_wrappers/include/metrics.h"
#include "webrtc/test/histogram.h"
#include "webrtc/system_wrappers/include/metrics_default.h"
using ::testing::_;
using ::testing::NiceMock;
@ -474,6 +474,7 @@ TEST_F(ScreenshareLayerTest, RespectsMaxIntervalBetweenFrames) {
}
TEST_F(ScreenshareLayerTest, UpdatesHistograms) {
metrics::Reset();
ConfigureBitrates();
vpx_codec_enc_cfg_t cfg = GetConfig();
bool trigger_drop = false;
@ -519,42 +520,35 @@ TEST_F(ScreenshareLayerTest, UpdatesHistograms) {
layers_.reset(); // Histograms are reported on destruction.
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.Screenshare.Layer0.FrameRate"));
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.Screenshare.Layer1.FrameRate"));
EXPECT_EQ(1,
metrics::NumSamples("WebRTC.Video.Screenshare.Layer0.FrameRate"));
EXPECT_EQ(1,
metrics::NumSamples("WebRTC.Video.Screenshare.Layer1.FrameRate"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Screenshare.FramesPerDrop"));
EXPECT_EQ(1,
metrics::NumSamples("WebRTC.Video.Screenshare.FramesPerOvershoot"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Screenshare.Layer0.Qp"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Screenshare.Layer1.Qp"));
EXPECT_EQ(
1, test::NumHistogramSamples("WebRTC.Video.Screenshare.FramesPerDrop"));
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.Screenshare.FramesPerOvershoot"));
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.Screenshare.Layer0.Qp"));
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.Screenshare.Layer1.Qp"));
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.Screenshare.Layer0.TargetBitrate"));
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.Screenshare.Layer1.TargetBitrate"));
1, metrics::NumSamples("WebRTC.Video.Screenshare.Layer0.TargetBitrate"));
EXPECT_EQ(
1, metrics::NumSamples("WebRTC.Video.Screenshare.Layer1.TargetBitrate"));
EXPECT_GT(
test::LastHistogramSample("WebRTC.Video.Screenshare.Layer0.FrameRate"),
EXPECT_GT(metrics::MinSample("WebRTC.Video.Screenshare.Layer0.FrameRate"), 1);
EXPECT_GT(metrics::MinSample("WebRTC.Video.Screenshare.Layer1.FrameRate"), 1);
EXPECT_GT(metrics::MinSample("WebRTC.Video.Screenshare.FramesPerDrop"), 1);
EXPECT_GT(metrics::MinSample("WebRTC.Video.Screenshare.FramesPerOvershoot"),
1);
EXPECT_GT(
test::LastHistogramSample("WebRTC.Video.Screenshare.Layer1.FrameRate"),
1);
EXPECT_GT(test::LastHistogramSample("WebRTC.Video.Screenshare.FramesPerDrop"),
1);
EXPECT_GT(
test::LastHistogramSample("WebRTC.Video.Screenshare.FramesPerOvershoot"),
1);
EXPECT_EQ(kTl0Qp,
test::LastHistogramSample("WebRTC.Video.Screenshare.Layer0.Qp"));
EXPECT_EQ(kTl1Qp,
test::LastHistogramSample("WebRTC.Video.Screenshare.Layer1.Qp"));
EXPECT_EQ(kDefaultTl0BitrateKbps,
test::LastHistogramSample(
"WebRTC.Video.Screenshare.Layer0.TargetBitrate"));
EXPECT_EQ(kDefaultTl1BitrateKbps,
test::LastHistogramSample(
"WebRTC.Video.Screenshare.Layer1.TargetBitrate"));
EXPECT_EQ(1,
metrics::NumEvents("WebRTC.Video.Screenshare.Layer0.Qp", kTl0Qp));
EXPECT_EQ(1,
metrics::NumEvents("WebRTC.Video.Screenshare.Layer1.Qp", kTl1Qp));
EXPECT_EQ(1,
metrics::NumEvents("WebRTC.Video.Screenshare.Layer0.TargetBitrate",
kDefaultTl0BitrateKbps));
EXPECT_EQ(1,
metrics::NumEvents("WebRTC.Video.Screenshare.Layer1.TargetBitrate",
kDefaultTl1BitrateKbps));
}
} // namespace webrtc

View File

@ -24,8 +24,8 @@
#include "webrtc/system_wrappers/include/clock.h"
#include "webrtc/system_wrappers/include/field_trial.h"
#include "webrtc/system_wrappers/include/metrics.h"
#include "webrtc/system_wrappers/include/metrics_default.h"
#include "webrtc/test/field_trial.h"
#include "webrtc/test/histogram.h"
namespace webrtc {
@ -498,7 +498,7 @@ TEST_P(TestBasicJitterBuffer, SinglePacketFrame) {
}
TEST_P(TestBasicJitterBuffer, VerifyHistogramStats) {
test::ClearHistograms();
metrics::Reset();
// Always start with a complete key frame when not allowing errors.
jitter_buffer_->SetDecodeErrorMode(kNoErrors);
packet_->frameType = kVideoFrameKey;
@ -518,25 +518,21 @@ TEST_P(TestBasicJitterBuffer, VerifyHistogramStats) {
// Verify that histograms are updated when the jitter buffer is stopped.
clock_->AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
jitter_buffer_->Stop();
EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.DiscardedPacketsInPercent", 0));
EXPECT_EQ(1,
metrics::NumEvents("WebRTC.Video.DuplicatedPacketsInPercent", 0));
EXPECT_EQ(
0, test::LastHistogramSample("WebRTC.Video.DiscardedPacketsInPercent"));
1, metrics::NumSamples("WebRTC.Video.CompleteFramesReceivedPerSecond"));
EXPECT_EQ(
0, test::LastHistogramSample("WebRTC.Video.DuplicatedPacketsInPercent"));
EXPECT_NE(-1, test::LastHistogramSample(
"WebRTC.Video.CompleteFramesReceivedPerSecond"));
EXPECT_EQ(1000, test::LastHistogramSample(
"WebRTC.Video.KeyFramesReceivedInPermille"));
1, metrics::NumEvents("WebRTC.Video.KeyFramesReceivedInPermille", 1000));
// Verify that histograms are not updated if stop is called again.
jitter_buffer_->Stop();
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.DiscardedPacketsInPercent"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.DuplicatedPacketsInPercent"));
EXPECT_EQ(
1, test::NumHistogramSamples("WebRTC.Video.DiscardedPacketsInPercent"));
EXPECT_EQ(
1, test::NumHistogramSamples("WebRTC.Video.DuplicatedPacketsInPercent"));
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.CompleteFramesReceivedPerSecond"));
EXPECT_EQ(
1, test::NumHistogramSamples("WebRTC.Video.KeyFramesReceivedInPermille"));
1, metrics::NumSamples("WebRTC.Video.CompleteFramesReceivedPerSecond"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.KeyFramesReceivedInPermille"));
}
TEST_P(TestBasicJitterBuffer, DualPacketFrame) {

View File

@ -148,6 +148,7 @@ source_set("field_trial_default") {
source_set("metrics_default") {
sources = [
"include/metrics_default.h",
"source/metrics_default.cc",
]

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_METRICS_DEFAULT_H_
#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_METRICS_DEFAULT_H_
#include <map>
#include <memory>
#include <string>
namespace webrtc {
namespace metrics {
struct SampleInfo {
SampleInfo(const std::string& name, int min, int max, size_t bucket_count);
~SampleInfo();
const std::string name;
const int min;
const int max;
const size_t bucket_count;
std::map<int, int> samples; // <value, # of events>
};
// Enables collection of samples.
// This method should be called before any other call into webrtc.
void Enable();
// Gets histograms and clears all samples.
void GetAndReset(
std::map<std::string, std::unique_ptr<SampleInfo>>* histograms);
// Functions below are mainly for testing.
// Clears all samples.
void Reset();
// Returns the number of times the |sample| has been added to the histogram.
int NumEvents(const std::string& name, int sample);
// Returns the total number of added samples to the histogram.
int NumSamples(const std::string& name);
// Returns the minimum sample value (or -1 if the histogram has no samples).
int MinSample(const std::string& name);
} // namespace metrics
} // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_METRICS_DEFAULT_H_

View File

@ -7,6 +7,10 @@
// be found in the AUTHORS file in the root of the source tree.
//
#include "webrtc/system_wrappers/include/metrics_default.h"
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/thread_annotations.h"
#include "webrtc/system_wrappers/include/metrics.h"
// Default implementation of histogram methods for WebRTC clients that do not
@ -14,16 +18,277 @@
namespace webrtc {
namespace metrics {
class Histogram;
Histogram* HistogramFactoryGetCounts(const std::string& name, int min, int max,
int bucket_count) { return NULL; }
namespace {
// Limit for the maximum number of sample values that can be stored.
// TODO(asapersson): Consider using bucket count (and set up
// linearly/exponentially spaced buckets) if samples are logged more frequently.
const int kMaxSampleMapSize = 2000;
class RtcHistogram {
public:
RtcHistogram(const std::string& name, int min, int max, int bucket_count)
: min_(min), max_(max), info_(name, min, max, bucket_count) {
RTC_DCHECK_GT(bucket_count, 0);
}
void Add(int sample) {
if (sample < min_)
sample = min_ - 1; // Underflow bucket.
if (sample > max_)
sample = max_;
rtc::CritScope cs(&crit_);
if (info_.samples.size() == kMaxSampleMapSize &&
info_.samples.find(sample) == info_.samples.end()) {
return;
}
++info_.samples[sample];
}
// Returns a copy (or nullptr if there are no samples) and clears samples.
std::unique_ptr<SampleInfo> GetAndReset() {
rtc::CritScope cs(&crit_);
if (info_.samples.empty())
return nullptr;
SampleInfo* copy =
new SampleInfo(info_.name, info_.min, info_.max, info_.bucket_count);
copy->samples = info_.samples;
info_.samples.clear();
return std::unique_ptr<SampleInfo>(copy);
}
const std::string& name() const { return info_.name; }
// Functions only for testing.
void Reset() {
rtc::CritScope cs(&crit_);
info_.samples.clear();
}
int NumEvents(int sample) const {
rtc::CritScope cs(&crit_);
const auto it = info_.samples.find(sample);
return (it == info_.samples.end()) ? 0 : it->second;
}
int NumSamples() const {
int num_samples = 0;
rtc::CritScope cs(&crit_);
for (const auto& sample : info_.samples) {
num_samples += sample.second;
}
return num_samples;
}
int MinSample() const {
rtc::CritScope cs(&crit_);
return (info_.samples.empty()) ? -1 : info_.samples.begin()->first;
}
private:
rtc::CriticalSection crit_;
const int min_;
const int max_;
SampleInfo info_ GUARDED_BY(crit_);
RTC_DISALLOW_COPY_AND_ASSIGN(RtcHistogram);
};
class RtcHistogramMap {
public:
RtcHistogramMap() {}
~RtcHistogramMap() {}
Histogram* GetCountsHistogram(const std::string& name,
int min,
int max,
int bucket_count) {
rtc::CritScope cs(&crit_);
const auto& it = map_.find(name);
if (it != map_.end())
return reinterpret_cast<Histogram*>(it->second.get());
RtcHistogram* hist = new RtcHistogram(name, min, max, bucket_count);
map_[name].reset(hist);
return reinterpret_cast<Histogram*>(hist);
}
Histogram* GetEnumerationHistogram(const std::string& name, int boundary) {
rtc::CritScope cs(&crit_);
const auto& it = map_.find(name);
if (it != map_.end())
return reinterpret_cast<Histogram*>(it->second.get());
RtcHistogram* hist = new RtcHistogram(name, 1, boundary, boundary + 1);
map_[name].reset(hist);
return reinterpret_cast<Histogram*>(hist);
}
void GetAndReset(
std::map<std::string, std::unique_ptr<SampleInfo>>* histograms) {
rtc::CritScope cs(&crit_);
for (const auto& kv : map_) {
std::unique_ptr<SampleInfo> info = kv.second->GetAndReset();
if (info)
histograms->insert(std::make_pair(kv.first, std::move(info)));
}
}
// Functions only for testing.
void Reset() {
rtc::CritScope cs(&crit_);
for (const auto& kv : map_)
kv.second->Reset();
}
int NumEvents(const std::string& name, int sample) const {
rtc::CritScope cs(&crit_);
const auto& it = map_.find(name);
return (it == map_.end()) ? 0 : it->second->NumEvents(sample);
}
int NumSamples(const std::string& name) const {
rtc::CritScope cs(&crit_);
const auto& it = map_.find(name);
return (it == map_.end()) ? 0 : it->second->NumSamples();
}
int MinSample(const std::string& name) const {
rtc::CritScope cs(&crit_);
const auto& it = map_.find(name);
return (it == map_.end()) ? -1 : it->second->MinSample();
}
private:
rtc::CriticalSection crit_;
std::map<std::string, std::unique_ptr<RtcHistogram>> map_ GUARDED_BY(crit_);
RTC_DISALLOW_COPY_AND_ASSIGN(RtcHistogramMap);
};
// RtcHistogramMap is allocated upon call to Enable().
// The histogram getter functions, which return pointer values to the histograms
// in the map, are cached in WebRTC. Therefore, this memory is not freed by the
// application (the memory will be reclaimed by the OS).
static RtcHistogramMap* volatile g_rtc_histogram_map = nullptr;
void CreateMap() {
RtcHistogramMap* map = rtc::AtomicOps::AcquireLoadPtr(&g_rtc_histogram_map);
if (map == nullptr) {
RtcHistogramMap* new_map = new RtcHistogramMap();
RtcHistogramMap* old_map = rtc::AtomicOps::CompareAndSwapPtr(
&g_rtc_histogram_map, static_cast<RtcHistogramMap*>(nullptr), new_map);
if (old_map != nullptr)
delete new_map;
}
}
// Set the first time we start using histograms. Used to make sure Enable() is
// not called thereafter.
#if RTC_DCHECK_IS_ON
static volatile int g_rtc_histogram_called = 0;
#endif
// Gets the map (or nullptr).
RtcHistogramMap* GetMap() {
#if RTC_DCHECK_IS_ON
rtc::AtomicOps::ReleaseStore(&g_rtc_histogram_called, 1);
#endif
return g_rtc_histogram_map;
}
} // namespace
// Implementation of histogram methods in
// webrtc/system_wrappers/interface/metrics.h.
// Histogram with exponentially spaced buckets.
// Creates (or finds) histogram.
// The returned histogram pointer is cached (and used for adding samples in
// subsequent calls).
Histogram* HistogramFactoryGetCounts(const std::string& name,
int min,
int max,
int bucket_count) {
RtcHistogramMap* map = GetMap();
if (!map)
return nullptr;
return map->GetCountsHistogram(name, min, max, bucket_count);
}
// Histogram with linearly spaced buckets.
// Creates (or finds) histogram.
// The returned histogram pointer is cached (and used for adding samples in
// subsequent calls).
Histogram* HistogramFactoryGetEnumeration(const std::string& name,
int boundary) { return NULL; }
int boundary) {
RtcHistogramMap* map = GetMap();
if (!map)
return nullptr;
void HistogramAdd(
Histogram* histogram_pointer, const std::string& name, int sample) {}
return map->GetEnumerationHistogram(name, boundary);
}
// Fast path. Adds |sample| to cached |histogram_pointer|.
void HistogramAdd(Histogram* histogram_pointer,
const std::string& name,
int sample) {
if (!histogram_pointer)
return;
RtcHistogram* ptr = reinterpret_cast<RtcHistogram*>(histogram_pointer);
RTC_DCHECK_EQ(name, ptr->name()) << "The name should not vary.";
ptr->Add(sample);
}
SampleInfo::SampleInfo(const std::string& name,
int min,
int max,
size_t bucket_count)
: name(name), min(min), max(max), bucket_count(bucket_count) {}
SampleInfo::~SampleInfo() {}
// Implementation of global functions in metrics_default.h.
void Enable() {
RTC_DCHECK(g_rtc_histogram_map == nullptr);
#if RTC_DCHECK_IS_ON
RTC_DCHECK_EQ(0, rtc::AtomicOps::AcquireLoad(&g_rtc_histogram_called));
#endif
CreateMap();
}
void GetAndReset(
std::map<std::string, std::unique_ptr<SampleInfo>>* histograms) {
histograms->clear();
RtcHistogramMap* map = GetMap();
if (map)
map->GetAndReset(histograms);
}
void Reset() {
RtcHistogramMap* map = GetMap();
if (map)
map->Reset();
}
int NumEvents(const std::string& name, int sample) {
RtcHistogramMap* map = GetMap();
return map ? map->NumEvents(name, sample) : 0;
}
int NumSamples(const std::string& name) {
RtcHistogramMap* map = GetMap();
return map ? map->NumSamples(name) : 0;
}
int MinSample(const std::string& name) {
RtcHistogramMap* map = GetMap();
return map ? map->MinSample(name) : -1;
}
} // namespace metrics
} // namespace webrtc

View File

@ -0,0 +1,154 @@
/*
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/system_wrappers/include/metrics.h"
#include "webrtc/system_wrappers/include/metrics_default.h"
namespace webrtc {
namespace {
const int kSample = 22;
const char kName[] = "Name";
int NumSamples(
const std::string& name,
const std::map<std::string, std::unique_ptr<metrics::SampleInfo>>&
histograms) {
const auto it = histograms.find(name);
if (it == histograms.end())
return 0;
int num_samples = 0;
for (const auto& sample : it->second->samples)
num_samples += sample.second;
return num_samples;
}
int NumEvents(const std::string& name,
int sample,
const std::map<std::string, std::unique_ptr<metrics::SampleInfo>>&
histograms) {
const auto it = histograms.find(name);
if (it == histograms.end())
return 0;
const auto it_sample = it->second->samples.find(sample);
if (it_sample == it->second->samples.end())
return 0;
return it_sample->second;
}
} // namespace
class MetricsDefaultTest : public ::testing::Test {
public:
MetricsDefaultTest() {}
protected:
virtual void SetUp() {
metrics::Reset();
}
};
TEST_F(MetricsDefaultTest, Reset) {
RTC_HISTOGRAM_PERCENTAGE(kName, kSample);
EXPECT_EQ(1, metrics::NumSamples(kName));
metrics::Reset();
EXPECT_EQ(0, metrics::NumSamples(kName));
}
TEST_F(MetricsDefaultTest, NumSamples) {
RTC_HISTOGRAM_PERCENTAGE(kName, 5);
RTC_HISTOGRAM_PERCENTAGE(kName, 5);
RTC_HISTOGRAM_PERCENTAGE(kName, 10);
EXPECT_EQ(3, metrics::NumSamples(kName));
EXPECT_EQ(0, metrics::NumSamples("NonExisting"));
}
TEST_F(MetricsDefaultTest, NumEvents) {
RTC_HISTOGRAM_PERCENTAGE(kName, 5);
RTC_HISTOGRAM_PERCENTAGE(kName, 5);
RTC_HISTOGRAM_PERCENTAGE(kName, 10);
EXPECT_EQ(2, metrics::NumEvents(kName, 5));
EXPECT_EQ(1, metrics::NumEvents(kName, 10));
EXPECT_EQ(0, metrics::NumEvents(kName, 11));
EXPECT_EQ(0, metrics::NumEvents("NonExisting", 5));
}
TEST_F(MetricsDefaultTest, MinSample) {
RTC_HISTOGRAM_PERCENTAGE(kName, kSample);
RTC_HISTOGRAM_PERCENTAGE(kName, kSample + 1);
EXPECT_EQ(kSample, metrics::MinSample(kName));
EXPECT_EQ(-1, metrics::MinSample("NonExisting"));
}
TEST_F(MetricsDefaultTest, Overflow) {
const std::string kName = "Overflow";
// Samples should end up in overflow bucket.
RTC_HISTOGRAM_PERCENTAGE(kName, 101);
EXPECT_EQ(1, metrics::NumSamples(kName));
EXPECT_EQ(1, metrics::NumEvents(kName, 101));
RTC_HISTOGRAM_PERCENTAGE(kName, 102);
EXPECT_EQ(2, metrics::NumSamples(kName));
EXPECT_EQ(2, metrics::NumEvents(kName, 101));
}
TEST_F(MetricsDefaultTest, Underflow) {
const std::string kName = "Underflow";
// Samples should end up in underflow bucket.
RTC_HISTOGRAM_COUNTS_10000(kName, 0);
EXPECT_EQ(1, metrics::NumSamples(kName));
EXPECT_EQ(1, metrics::NumEvents(kName, 0));
RTC_HISTOGRAM_COUNTS_10000(kName, -1);
EXPECT_EQ(2, metrics::NumSamples(kName));
EXPECT_EQ(2, metrics::NumEvents(kName, 0));
}
TEST_F(MetricsDefaultTest, GetAndReset) {
std::map<std::string, std::unique_ptr<metrics::SampleInfo>> histograms;
metrics::GetAndReset(&histograms);
EXPECT_EQ(0u, histograms.size());
RTC_HISTOGRAM_PERCENTAGE("Histogram1", 4);
RTC_HISTOGRAM_PERCENTAGE("Histogram1", 5);
RTC_HISTOGRAM_PERCENTAGE("Histogram1", 5);
RTC_HISTOGRAM_PERCENTAGE("Histogram2", 10);
EXPECT_EQ(3, metrics::NumSamples("Histogram1"));
EXPECT_EQ(1, metrics::NumSamples("Histogram2"));
metrics::GetAndReset(&histograms);
EXPECT_EQ(2u, histograms.size());
EXPECT_EQ(0, metrics::NumSamples("Histogram1"));
EXPECT_EQ(0, metrics::NumSamples("Histogram2"));
EXPECT_EQ(3, NumSamples("Histogram1", histograms));
EXPECT_EQ(1, NumSamples("Histogram2", histograms));
EXPECT_EQ(1, NumEvents("Histogram1", 4, histograms));
EXPECT_EQ(2, NumEvents("Histogram1", 5, histograms));
EXPECT_EQ(1, NumEvents("Histogram2", 10, histograms));
}
TEST_F(MetricsDefaultTest, TestMinMaxBucket) {
const std::string kName = "MinMaxCounts100";
RTC_HISTOGRAM_COUNTS_100(kName, 4);
std::map<std::string, std::unique_ptr<metrics::SampleInfo>> histograms;
metrics::GetAndReset(&histograms);
EXPECT_EQ(1u, histograms.size());
EXPECT_EQ(kName, histograms.begin()->second->name);
EXPECT_EQ(1, histograms.begin()->second->min);
EXPECT_EQ(100, histograms.begin()->second->max);
EXPECT_EQ(50u, histograms.begin()->second->bucket_count);
EXPECT_EQ(1u, histograms.begin()->second->samples.size());
}
} // namespace webrtc

View File

@ -11,12 +11,11 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/system_wrappers/include/metrics.h"
#include "webrtc/test/histogram.h"
#include "webrtc/system_wrappers/include/metrics_default.h"
namespace webrtc {
namespace {
const int kSample = 22;
const std::string kName = "Name";
void AddSparseSample(const std::string& name, int sample) {
RTC_HISTOGRAM_COUNTS_SPARSE_100(name, sample);
@ -24,92 +23,98 @@ void AddSparseSample(const std::string& name, int sample) {
void AddSampleWithVaryingName(int index, const std::string& name, int sample) {
RTC_HISTOGRAMS_COUNTS_100(index, name, sample);
}
#if GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
void AddSample(const std::string& name, int sample) {
RTC_HISTOGRAM_COUNTS_100(name, sample);
}
#endif // GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
#endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
} // namespace
TEST(MetricsTest, InitiallyNoSamples) {
test::ClearHistograms();
EXPECT_EQ(0, test::NumHistogramSamples(kName));
EXPECT_EQ(-1, test::LastHistogramSample(kName));
}
class MetricsTest : public ::testing::Test {
public:
MetricsTest() {}
TEST(MetricsTest, RtcHistogramPercent_AddSample) {
test::ClearHistograms();
RTC_HISTOGRAM_PERCENTAGE(kName, kSample);
EXPECT_EQ(1, test::NumHistogramSamples(kName));
EXPECT_EQ(kSample, test::LastHistogramSample(kName));
}
TEST(MetricsTest, RtcHistogramEnumeration_AddSample) {
test::ClearHistograms();
RTC_HISTOGRAM_ENUMERATION(kName, kSample, kSample + 1);
EXPECT_EQ(1, test::NumHistogramSamples(kName));
EXPECT_EQ(kSample, test::LastHistogramSample(kName));
}
TEST(MetricsTest, RtcHistogramCountsSparse_AddSample) {
test::ClearHistograms();
RTC_HISTOGRAM_COUNTS_SPARSE_100(kName, kSample);
EXPECT_EQ(1, test::NumHistogramSamples(kName));
EXPECT_EQ(kSample, test::LastHistogramSample(kName));
}
TEST(MetricsTest, RtcHistogramCounts_AddSample) {
test::ClearHistograms();
RTC_HISTOGRAM_COUNTS_100(kName, kSample);
EXPECT_EQ(1, test::NumHistogramSamples(kName));
EXPECT_EQ(kSample, test::LastHistogramSample(kName));
}
TEST(MetricsTest, RtcHistogramCounts_AddMultipleSamples) {
test::ClearHistograms();
const int kNumSamples = 10;
for (int i = 0; i < kNumSamples; ++i) {
RTC_HISTOGRAM_COUNTS_100(kName, i);
protected:
virtual void SetUp() {
metrics::Reset();
}
EXPECT_EQ(kNumSamples, test::NumHistogramSamples(kName));
EXPECT_EQ(kNumSamples - 1, test::LastHistogramSample(kName));
};
TEST_F(MetricsTest, InitiallyNoSamples) {
EXPECT_EQ(0, metrics::NumSamples("NonExisting"));
EXPECT_EQ(0, metrics::NumEvents("NonExisting", kSample));
}
TEST(MetricsTest, RtcHistogramsCounts_AddSample) {
test::ClearHistograms();
TEST_F(MetricsTest, RtcHistogramPercent_AddSample) {
const std::string kName = "Percentage";
RTC_HISTOGRAM_PERCENTAGE(kName, kSample);
EXPECT_EQ(1, metrics::NumSamples(kName));
EXPECT_EQ(1, metrics::NumEvents(kName, kSample));
}
TEST_F(MetricsTest, RtcHistogramEnumeration_AddSample) {
const std::string kName = "Enumeration";
RTC_HISTOGRAM_ENUMERATION(kName, kSample, kSample + 1);
EXPECT_EQ(1, metrics::NumSamples(kName));
EXPECT_EQ(1, metrics::NumEvents(kName, kSample));
}
TEST_F(MetricsTest, RtcHistogramCountsSparse_AddSample) {
const std::string kName = "CountsSparse100";
RTC_HISTOGRAM_COUNTS_SPARSE_100(kName, kSample);
EXPECT_EQ(1, metrics::NumSamples(kName));
EXPECT_EQ(1, metrics::NumEvents(kName, kSample));
}
TEST_F(MetricsTest, RtcHistogramCounts_AddSample) {
const std::string kName = "Counts100";
RTC_HISTOGRAM_COUNTS_100(kName, kSample);
EXPECT_EQ(1, metrics::NumSamples(kName));
EXPECT_EQ(1, metrics::NumEvents(kName, kSample));
}
TEST_F(MetricsTest, RtcHistogramCounts_AddMultipleSamples) {
const std::string kName = "Counts200";
const int kNumSamples = 10;
for (int i = 1; i <= kNumSamples; ++i) {
RTC_HISTOGRAM_COUNTS_200(kName, i);
EXPECT_EQ(1, metrics::NumEvents(kName, i));
EXPECT_EQ(i, metrics::NumSamples(kName));
}
}
TEST_F(MetricsTest, RtcHistogramsCounts_AddSample) {
AddSampleWithVaryingName(0, "Name1", kSample);
AddSampleWithVaryingName(1, "Name2", kSample + 1);
AddSampleWithVaryingName(2, "Name3", kSample + 2);
EXPECT_EQ(1, test::NumHistogramSamples("Name1"));
EXPECT_EQ(1, test::NumHistogramSamples("Name2"));
EXPECT_EQ(1, test::NumHistogramSamples("Name3"));
EXPECT_EQ(kSample + 0, test::LastHistogramSample("Name1"));
EXPECT_EQ(kSample + 1, test::LastHistogramSample("Name2"));
EXPECT_EQ(kSample + 2, test::LastHistogramSample("Name3"));
EXPECT_EQ(1, metrics::NumSamples("Name1"));
EXPECT_EQ(1, metrics::NumSamples("Name2"));
EXPECT_EQ(1, metrics::NumSamples("Name3"));
EXPECT_EQ(1, metrics::NumEvents("Name1", kSample + 0));
EXPECT_EQ(1, metrics::NumEvents("Name2", kSample + 1));
EXPECT_EQ(1, metrics::NumEvents("Name3", kSample + 2));
}
#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
TEST(MetricsTest, RtcHistogramsCounts_InvalidIndex) {
EXPECT_DEATH(RTC_HISTOGRAMS_COUNTS_1000(-1, kName, kSample), "");
EXPECT_DEATH(RTC_HISTOGRAMS_COUNTS_1000(3, kName, kSample), "");
EXPECT_DEATH(RTC_HISTOGRAMS_COUNTS_1000(3u, kName, kSample), "");
TEST_F(MetricsTest, RtcHistogramsCounts_InvalidIndex) {
EXPECT_DEATH(RTC_HISTOGRAMS_COUNTS_1000(-1, "Name", kSample), "");
EXPECT_DEATH(RTC_HISTOGRAMS_COUNTS_1000(3, "Name", kSample), "");
EXPECT_DEATH(RTC_HISTOGRAMS_COUNTS_1000(3u, "Name", kSample), "");
}
#endif
TEST(MetricsTest, RtcHistogramSparse_NonConstantNameWorks) {
test::ClearHistograms();
AddSparseSample("Name1", kSample);
AddSparseSample("Name2", kSample);
EXPECT_EQ(1, test::NumHistogramSamples("Name1"));
EXPECT_EQ(1, test::NumHistogramSamples("Name2"));
TEST_F(MetricsTest, RtcHistogramSparse_NonConstantNameWorks) {
AddSparseSample("Sparse1", kSample);
AddSparseSample("Sparse2", kSample);
EXPECT_EQ(1, metrics::NumSamples("Sparse1"));
EXPECT_EQ(1, metrics::NumSamples("Sparse2"));
}
#if GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
TEST(MetricsTest, RtcHistogram_FailsForNonConstantName) {
test::ClearHistograms();
AddSample("Name1", kSample);
EXPECT_DEATH(AddSample("Name2", kSample), "");
#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
TEST_F(MetricsTest, RtcHistogram_FailsForNonConstantName) {
AddSample("ConstantName1", kSample);
EXPECT_DEATH(AddSample("NotConstantName1", kSample), "");
}
#endif // GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
#endif
} // namespace webrtc

View File

@ -180,6 +180,7 @@
'target_name': 'metrics_default',
'type': 'static_library',
'sources': [
'include/metrics_default.h',
'source/metrics_default.cc',
],
}, {

View File

@ -14,8 +14,8 @@
'type': '<(gtest_target_type)',
'dependencies': [
'<(DEPTH)/testing/gtest.gyp:gtest',
'<(webrtc_root)/system_wrappers/system_wrappers.gyp:metrics_default',
'<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers',
'<(webrtc_root)/test/test.gyp:histogram',
'<(webrtc_root)/test/test.gyp:test_support_main',
],
'sources': [
@ -31,6 +31,7 @@
'source/data_log_c_helpers_unittest.c',
'source/data_log_c_helpers_unittest.h',
'source/event_timer_posix_unittest.cc',
'source/metrics_default_unittest.cc',
'source/metrics_unittest.cc',
'source/ntp_time_unittest.cc',
'source/rtp_to_ntp_unittest.cc',

View File

@ -34,21 +34,6 @@ source_set("field_trial") {
public_configs = [ "..:common_inherited_config" ]
}
source_set("histogram") {
sources = [
"histogram.cc",
"histogram.h",
]
deps = [
"..:webrtc_common",
"../system_wrappers",
]
configs += [ "..:common_config" ]
public_configs = [ "..:common_inherited_config" ]
}
source_set("test_support") {
testonly = true
@ -100,8 +85,8 @@ source_set("test_support_main") {
deps = [
":field_trial",
":histogram",
":test_support",
"../system_wrappers:metrics_default",
"//testing/gmock",
"//testing/gtest",
"//third_party/gflags",

View File

@ -1,97 +0,0 @@
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/test/histogram.h"
#include <map>
#include "webrtc/base/checks.h"
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/thread_annotations.h"
#include "webrtc/system_wrappers/include/metrics.h"
// Test implementation of histogram methods in
// webrtc/system_wrappers/include/metrics.h.
namespace webrtc {
namespace {
struct SampleInfo {
SampleInfo(const std::string& name) : name_(name), last_(-1), total_(0) {}
const std::string name_;
int last_; // Last added sample.
int total_; // Total number of added samples.
};
rtc::CriticalSection histogram_crit_;
// Map holding info about added samples to a histogram (mapped by the histogram
// name).
std::map<std::string, SampleInfo> histograms_ GUARDED_BY(histogram_crit_);
} // namespace
namespace metrics {
Histogram* HistogramFactoryGetCounts(const std::string& name, int min, int max,
int bucket_count) {
rtc::CritScope cs(&histogram_crit_);
if (histograms_.find(name) == histograms_.end()) {
histograms_.insert(std::make_pair(name, SampleInfo(name)));
}
auto it = histograms_.find(name);
return reinterpret_cast<Histogram*>(&it->second);
}
Histogram* HistogramFactoryGetEnumeration(const std::string& name,
int boundary) {
rtc::CritScope cs(&histogram_crit_);
if (histograms_.find(name) == histograms_.end()) {
histograms_.insert(std::make_pair(name, SampleInfo(name)));
}
auto it = histograms_.find(name);
return reinterpret_cast<Histogram*>(&it->second);
}
void HistogramAdd(
Histogram* histogram_pointer, const std::string& name, int sample) {
rtc::CritScope cs(&histogram_crit_);
SampleInfo* ptr = reinterpret_cast<SampleInfo*>(histogram_pointer);
// The name should not vary.
RTC_CHECK(ptr->name_ == name);
ptr->last_ = sample;
++ptr->total_;
}
} // namespace metrics
namespace test {
int LastHistogramSample(const std::string& name) {
rtc::CritScope cs(&histogram_crit_);
const auto it = histograms_.find(name);
if (it == histograms_.end()) {
return -1;
}
return it->second.last_;
}
int NumHistogramSamples(const std::string& name) {
rtc::CritScope cs(&histogram_crit_);
const auto it = histograms_.find(name);
if (it == histograms_.end()) {
return 0;
}
return it->second.total_;
}
void ClearHistograms() {
rtc::CritScope cs(&histogram_crit_);
for (auto& it : histograms_) {
it.second.last_ = -1;
it.second.total_ = 0;
}
}
} // namespace test
} // namespace webrtc

View File

@ -1,33 +0,0 @@
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_TEST_HISTOGRAM_H_
#define WEBRTC_TEST_HISTOGRAM_H_
#include <string>
namespace webrtc {
namespace test {
// Returns the last added sample to a histogram (or -1 if the histogram is not
// found).
int LastHistogramSample(const std::string& name);
// Returns the number of added samples to a histogram.
int NumHistogramSamples(const std::string& name);
// Removes all histogram samples.
void ClearHistograms();
} // namespace test
} // namespace webrtc
#endif // WEBRTC_TEST_HISTOGRAM_H_

View File

@ -106,18 +106,6 @@
'<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers',
],
},
{
'target_name': 'histogram',
'type': 'static_library',
'sources': [
'histogram.cc',
'histogram.h',
],
'dependencies': [
'<(webrtc_root)/common.gyp:webrtc_common',
'<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers',
],
},
{
'target_name': 'test_main',
'type': 'static_library',
@ -126,10 +114,10 @@
],
'dependencies': [
'field_trial',
'histogram',
'test_support',
'<(DEPTH)/testing/gtest.gyp:gtest',
'<(DEPTH)/third_party/gflags/gflags.gyp:gflags',
'<(webrtc_root)/system_wrappers/system_wrappers.gyp:metrics_default',
],
},
{
@ -178,11 +166,11 @@
'type': 'static_library',
'dependencies': [
'field_trial',
'histogram',
'test_support',
'<(DEPTH)/testing/gmock.gyp:gmock',
'<(DEPTH)/testing/gtest.gyp:gtest',
'<(DEPTH)/third_party/gflags/gflags.gyp:gflags',
'<(webrtc_root)/system_wrappers/system_wrappers.gyp:metrics_default',
],
'sources': [
'run_all_unittests.cc',

View File

@ -11,6 +11,7 @@
#include "gflags/gflags.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/base/logging.h"
#include "webrtc/system_wrappers/include/metrics_default.h"
#include "webrtc/test/field_trial.h"
#include "webrtc/test/testsupport/fileutils.h"
@ -34,5 +35,6 @@ int main(int argc, char* argv[]) {
webrtc::test::SetExecutablePath(argv[0]);
webrtc::test::InitFieldTrialsFromString(FLAGS_force_fieldtrials);
webrtc::metrics::Enable();
return RUN_ALL_TESTS();
}

View File

@ -14,6 +14,7 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/base/logging.h"
#include "webrtc/system_wrappers/include/metrics_default.h"
#include "webrtc/test/testsupport/fileutils.h"
#include "webrtc/test/testsupport/trace_to_stderr.h"
#include "webrtc/test/field_trial.h"
@ -37,6 +38,7 @@ TestSuite::TestSuite(int argc, char** argv) {
google::ParseCommandLineFlags(&argc, &argv, true);
webrtc::test::InitFieldTrialsFromString(FLAGS_force_fieldtrials);
webrtc::metrics::Enable();
}
TestSuite::~TestSuite() {

View File

@ -15,7 +15,7 @@
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "webrtc/system_wrappers/include/metrics.h"
#include "webrtc/test/histogram.h"
#include "webrtc/system_wrappers/include/metrics_default.h"
#include "webrtc/video/call_stats.h"
using ::testing::_;
@ -204,6 +204,7 @@ TEST_F(CallStatsTest, LastProcessedRtt) {
}
TEST_F(CallStatsTest, ProducesHistogramMetrics) {
metrics::Reset();
const int64_t kRtt = 123;
RtcpRttStats* rtcp_rtt_stats = call_stats_->rtcp_rtt_stats();
rtcp_rtt_stats->OnRttUpdate(kRtt);
@ -212,10 +213,10 @@ TEST_F(CallStatsTest, ProducesHistogramMetrics) {
call_stats_->Process();
call_stats_.reset();
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.AverageRoundTripTimeInMilliseconds"));
EXPECT_EQ(kRtt, test::LastHistogramSample(
EXPECT_EQ(1, metrics::NumSamples(
"WebRTC.Video.AverageRoundTripTimeInMilliseconds"));
EXPECT_EQ(1, metrics::NumEvents(
"WebRTC.Video.AverageRoundTripTimeInMilliseconds", kRtt));
}
} // namespace webrtc

View File

@ -31,6 +31,7 @@
#include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h"
#include "webrtc/modules/video_coding/include/video_coding_defines.h"
#include "webrtc/system_wrappers/include/metrics.h"
#include "webrtc/system_wrappers/include/metrics_default.h"
#include "webrtc/system_wrappers/include/sleep.h"
#include "webrtc/test/call_test.h"
#include "webrtc/test/direct_transport.h"
@ -39,7 +40,6 @@
#include "webrtc/test/fake_encoder.h"
#include "webrtc/test/frame_generator.h"
#include "webrtc/test/frame_generator_capturer.h"
#include "webrtc/test/histogram.h"
#include "webrtc/test/null_transport.h"
#include "webrtc/test/rtcp_packet_parser.h"
#include "webrtc/test/rtp_rtcp_observer.h"
@ -1979,17 +1979,14 @@ TEST_F(EndToEndTest, VerifyNackStats) {
int64_t start_runtime_ms_;
} test;
test::ClearHistograms();
metrics::Reset();
RunBaseTest(&test);
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.UniqueNackRequestsSentInPercent"));
EXPECT_EQ(1, test::NumHistogramSamples(
EXPECT_EQ(
1, metrics::NumSamples("WebRTC.Video.UniqueNackRequestsSentInPercent"));
EXPECT_EQ(1, metrics::NumSamples(
"WebRTC.Video.UniqueNackRequestsReceivedInPercent"));
EXPECT_GT(test::LastHistogramSample(
"WebRTC.Video.NackPacketsSentPerMinute"), 0);
EXPECT_GT(test::LastHistogramSample(
"WebRTC.Video.NackPacketsReceivedPerMinute"), 0);
EXPECT_GT(metrics::MinSample("WebRTC.Video.NackPacketsSentPerMinute"), 0);
}
void EndToEndTest::VerifyHistogramStats(bool use_rtx,
@ -2077,7 +2074,7 @@ void EndToEndTest::VerifyHistogramStats(bool use_rtx,
int64_t start_runtime_ms_;
} test(use_rtx, use_red, screenshare);
test::ClearHistograms();
metrics::Reset();
RunBaseTest(&test);
// Delete the call for Call stats to be reported.
@ -2088,110 +2085,99 @@ void EndToEndTest::VerifyHistogramStats(bool use_rtx,
screenshare ? "WebRTC.Video.Screenshare." : "WebRTC.Video.";
// Verify that stats have been updated once.
EXPECT_EQ(
1, test::NumHistogramSamples("WebRTC.Call.VideoBitrateReceivedInKbps"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Call.VideoBitrateReceivedInKbps"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Call.RtcpBitrateReceivedInBps"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Call.BitrateReceivedInKbps"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Call.EstimatedSendBitrateInKbps"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Call.PacerBitrateInKbps"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.NackPacketsSentPerMinute"));
EXPECT_EQ(1,
test::NumHistogramSamples("WebRTC.Call.RtcpBitrateReceivedInBps"));
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Call.BitrateReceivedInKbps"));
EXPECT_EQ(
1, test::NumHistogramSamples("WebRTC.Call.EstimatedSendBitrateInKbps"));
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Call.PacerBitrateInKbps"));
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.NackPacketsSentPerMinute"));
EXPECT_EQ(1, test::NumHistogramSamples(video_prefix +
"NackPacketsReceivedPerMinute"));
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.FirPacketsSentPerMinute"));
EXPECT_EQ(1, test::NumHistogramSamples(video_prefix +
"FirPacketsReceivedPerMinute"));
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.PliPacketsSentPerMinute"));
EXPECT_EQ(1, test::NumHistogramSamples(video_prefix +
"PliPacketsReceivedPerMinute"));
EXPECT_EQ(
1, test::NumHistogramSamples(video_prefix + "KeyFramesSentInPermille"));
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.KeyFramesReceivedInPermille"));
EXPECT_EQ(
1, test::NumHistogramSamples(video_prefix + "SentPacketsLostInPercent"));
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.ReceivedPacketsLostInPercent"));
EXPECT_EQ(1, test::NumHistogramSamples(video_prefix + "InputWidthInPixels"));
EXPECT_EQ(1, test::NumHistogramSamples(video_prefix + "InputHeightInPixels"));
EXPECT_EQ(1, test::NumHistogramSamples(video_prefix + "SentWidthInPixels"));
EXPECT_EQ(1, test::NumHistogramSamples(video_prefix + "SentHeightInPixels"));
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.ReceivedWidthInPixels"));
metrics::NumSamples(video_prefix + "NackPacketsReceivedPerMinute"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.FirPacketsSentPerMinute"));
EXPECT_EQ(1,
test::NumHistogramSamples("WebRTC.Video.ReceivedHeightInPixels"));
EXPECT_EQ(static_cast<int>(video_encoder_config_.streams[0].width),
test::LastHistogramSample(video_prefix + "InputWidthInPixels"));
EXPECT_EQ(static_cast<int>(video_encoder_config_.streams[0].height),
test::LastHistogramSample(video_prefix + "InputHeightInPixels"));
EXPECT_EQ(static_cast<int>(video_encoder_config_.streams[0].width),
test::LastHistogramSample(video_prefix + "SentWidthInPixels"));
EXPECT_EQ(static_cast<int>(video_encoder_config_.streams[0].height),
test::LastHistogramSample(video_prefix + "SentHeightInPixels"));
EXPECT_EQ(static_cast<int>(video_encoder_config_.streams[0].width),
test::LastHistogramSample("WebRTC.Video.ReceivedWidthInPixels"));
EXPECT_EQ(static_cast<int>(video_encoder_config_.streams[0].height),
test::LastHistogramSample("WebRTC.Video.ReceivedHeightInPixels"));
metrics::NumSamples(video_prefix + "FirPacketsReceivedPerMinute"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PliPacketsSentPerMinute"));
EXPECT_EQ(1,
test::NumHistogramSamples(video_prefix + "InputFramesPerSecond"));
EXPECT_EQ(1, test::NumHistogramSamples(video_prefix + "SentFramesPerSecond"));
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.DecodedFramesPerSecond"));
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.RenderFramesPerSecond"));
metrics::NumSamples(video_prefix + "PliPacketsReceivedPerMinute"));
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.JitterBufferDelayInMs"));
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.TargetDelayInMs"));
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.CurrentDelayInMs"));
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.OnewayDelayInMs"));
EXPECT_EQ(
1, test::NumHistogramSamples("WebRTC.Video.RenderSqrtPixelsPerSecond"));
EXPECT_EQ(1, metrics::NumSamples(video_prefix + "KeyFramesSentInPermille"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.KeyFramesReceivedInPermille"));
EXPECT_EQ(1, test::NumHistogramSamples(video_prefix + "EncodeTimeInMs"));
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.DecodeTimeInMs"));
EXPECT_EQ(1, test::NumHistogramSamples(video_prefix + "BitrateSentInKbps"));
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.BitrateReceivedInKbps"));
EXPECT_EQ(1, metrics::NumSamples(video_prefix + "SentPacketsLostInPercent"));
EXPECT_EQ(1,
test::NumHistogramSamples(video_prefix + "MediaBitrateSentInKbps"));
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.MediaBitrateReceivedInKbps"));
metrics::NumSamples("WebRTC.Video.ReceivedPacketsLostInPercent"));
EXPECT_EQ(1, metrics::NumSamples(video_prefix + "InputWidthInPixels"));
EXPECT_EQ(1, metrics::NumSamples(video_prefix + "InputHeightInPixels"));
EXPECT_EQ(1, metrics::NumSamples(video_prefix + "SentWidthInPixels"));
EXPECT_EQ(1, metrics::NumSamples(video_prefix + "SentHeightInPixels"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.ReceivedWidthInPixels"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.ReceivedHeightInPixels"));
EXPECT_EQ(1, metrics::NumEvents(
video_prefix + "InputWidthInPixels",
static_cast<int>(video_encoder_config_.streams[0].width)));
EXPECT_EQ(1, metrics::NumEvents(
video_prefix + "InputHeightInPixels",
static_cast<int>(video_encoder_config_.streams[0].height)));
EXPECT_EQ(1, metrics::NumEvents(
video_prefix + "SentWidthInPixels",
static_cast<int>(video_encoder_config_.streams[0].width)));
EXPECT_EQ(1, metrics::NumEvents(
video_prefix + "SentHeightInPixels",
static_cast<int>(video_encoder_config_.streams[0].height)));
EXPECT_EQ(1, metrics::NumEvents(
"WebRTC.Video.ReceivedWidthInPixels",
static_cast<int>(video_encoder_config_.streams[0].width)));
EXPECT_EQ(1, metrics::NumEvents(
"WebRTC.Video.ReceivedHeightInPixels",
static_cast<int>(video_encoder_config_.streams[0].height)));
EXPECT_EQ(1, metrics::NumSamples(video_prefix + "InputFramesPerSecond"));
EXPECT_EQ(1, metrics::NumSamples(video_prefix + "SentFramesPerSecond"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.DecodedFramesPerSecond"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RenderFramesPerSecond"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.JitterBufferDelayInMs"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.TargetDelayInMs"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.CurrentDelayInMs"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.OnewayDelayInMs"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RenderSqrtPixelsPerSecond"));
EXPECT_EQ(1, metrics::NumSamples(video_prefix + "EncodeTimeInMs"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.DecodeTimeInMs"));
EXPECT_EQ(1, metrics::NumSamples(video_prefix + "BitrateSentInKbps"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.BitrateReceivedInKbps"));
EXPECT_EQ(1, metrics::NumSamples(video_prefix + "MediaBitrateSentInKbps"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.MediaBitrateReceivedInKbps"));
EXPECT_EQ(1, metrics::NumSamples(video_prefix + "PaddingBitrateSentInKbps"));
EXPECT_EQ(1,
metrics::NumSamples("WebRTC.Video.PaddingBitrateReceivedInKbps"));
EXPECT_EQ(
1, test::NumHistogramSamples(video_prefix + "PaddingBitrateSentInKbps"));
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.PaddingBitrateReceivedInKbps"));
EXPECT_EQ(1, test::NumHistogramSamples(video_prefix +
"RetransmittedBitrateSentInKbps"));
EXPECT_EQ(1, test::NumHistogramSamples(
1, metrics::NumSamples(video_prefix + "RetransmittedBitrateSentInKbps"));
EXPECT_EQ(1, metrics::NumSamples(
"WebRTC.Video.RetransmittedBitrateReceivedInKbps"));
EXPECT_EQ(1, test::NumHistogramSamples(video_prefix + "SendSideDelayInMs"));
EXPECT_EQ(1,
test::NumHistogramSamples(video_prefix + "SendSideDelayMaxInMs"));
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.SendDelayInMs"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.SendDelayInMs"));
EXPECT_EQ(1, metrics::NumSamples(video_prefix + "SendSideDelayInMs"));
EXPECT_EQ(1, metrics::NumSamples(video_prefix + "SendSideDelayMaxInMs"));
int num_rtx_samples = use_rtx ? 1 : 0;
EXPECT_EQ(num_rtx_samples, test::NumHistogramSamples(
"WebRTC.Video.RtxBitrateSentInKbps"));
EXPECT_EQ(num_rtx_samples, test::NumHistogramSamples(
"WebRTC.Video.RtxBitrateReceivedInKbps"));
EXPECT_EQ(num_rtx_samples,
metrics::NumSamples("WebRTC.Video.RtxBitrateSentInKbps"));
EXPECT_EQ(num_rtx_samples,
metrics::NumSamples("WebRTC.Video.RtxBitrateReceivedInKbps"));
int num_red_samples = use_red ? 1 : 0;
EXPECT_EQ(num_red_samples, test::NumHistogramSamples(
"WebRTC.Video.FecBitrateSentInKbps"));
EXPECT_EQ(num_red_samples, test::NumHistogramSamples(
"WebRTC.Video.FecBitrateReceivedInKbps"));
EXPECT_EQ(num_red_samples, test::NumHistogramSamples(
"WebRTC.Video.ReceivedFecPacketsInPercent"));
EXPECT_EQ(num_red_samples,
metrics::NumSamples("WebRTC.Video.FecBitrateSentInKbps"));
EXPECT_EQ(num_red_samples,
metrics::NumSamples("WebRTC.Video.FecBitrateReceivedInKbps"));
EXPECT_EQ(num_red_samples,
metrics::NumSamples("WebRTC.Video.ReceivedFecPacketsInPercent"));
}
TEST_F(EndToEndTest, VerifyHistogramStatsWithRtx) {

View File

@ -12,7 +12,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/system_wrappers/include/metrics.h"
#include "webrtc/test/histogram.h"
#include "webrtc/system_wrappers/include/metrics_default.h"
namespace webrtc {
namespace {
@ -102,7 +102,7 @@ TEST_F(SendDelayStatsTest, OldPacketsRemoved) {
}
TEST_F(SendDelayStatsTest, HistogramsAreUpdated) {
test::ClearHistograms();
metrics::Reset();
const int64_t kDelayMs1 = 5;
const int64_t kDelayMs2 = 10;
uint16_t id = 0;
@ -115,8 +115,9 @@ TEST_F(SendDelayStatsTest, HistogramsAreUpdated) {
EXPECT_TRUE(OnSentPacket(id));
}
stats_.reset();
EXPECT_EQ(2, test::NumHistogramSamples("WebRTC.Video.SendDelayInMs"));
EXPECT_EQ(kDelayMs2, test::LastHistogramSample("WebRTC.Video.SendDelayInMs"));
EXPECT_EQ(2, metrics::NumSamples("WebRTC.Video.SendDelayInMs"));
EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SendDelayInMs", kDelayMs1));
EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SendDelayInMs", kDelayMs2));
}
} // namespace webrtc

View File

@ -17,7 +17,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/system_wrappers/include/metrics.h"
#include "webrtc/test/histogram.h"
#include "webrtc/system_wrappers/include/metrics_default.h"
namespace webrtc {
namespace {
@ -40,6 +40,7 @@ class SendStatisticsProxyTest : public ::testing::Test {
protected:
virtual void SetUp() {
metrics::Reset();
statistics_proxy_.reset(new SendStatisticsProxy(
&fake_clock_, GetTestConfig(),
VideoEncoderConfig::ContentType::kRealtimeVideo));
@ -285,7 +286,6 @@ TEST_F(SendStatisticsProxyTest, OnEncodedFrameTimeMeasured) {
}
TEST_F(SendStatisticsProxyTest, SwitchContentTypeUpdatesHistograms) {
test::ClearHistograms();
const int kWidth = 640;
const int kHeight = 480;
@ -295,15 +295,14 @@ TEST_F(SendStatisticsProxyTest, SwitchContentTypeUpdatesHistograms) {
// No switch, stats not should be updated.
statistics_proxy_->SetContentType(
VideoEncoderConfig::ContentType::kRealtimeVideo);
EXPECT_EQ(0, test::NumHistogramSamples("WebRTC.Video.InputWidthInPixels"));
EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.InputWidthInPixels"));
// Switch to screenshare, real-time stats should be updated.
statistics_proxy_->SetContentType(VideoEncoderConfig::ContentType::kScreen);
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.InputWidthInPixels"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InputWidthInPixels"));
}
TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp8) {
test::ClearHistograms();
EncodedImage encoded_image;
CodecSpecificInfo codec_info;
codec_info.codecType = kVideoCodecVP8;
@ -317,12 +316,10 @@ TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp8) {
statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
}
statistics_proxy_.reset();
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.Encoded.Qp.Vp8.S0"));
EXPECT_EQ(kQpIdx0,
test::LastHistogramSample("WebRTC.Video.Encoded.Qp.Vp8.S0"));
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.Encoded.Qp.Vp8.S1"));
EXPECT_EQ(kQpIdx1,
test::LastHistogramSample("WebRTC.Video.Encoded.Qp.Vp8.S1"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp8.S0"));
EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp8.S0", kQpIdx0));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp8.S1"));
EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp8.S1", kQpIdx1));
}
TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp8OneSsrc) {
@ -331,7 +328,6 @@ TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp8OneSsrc) {
statistics_proxy_.reset(new SendStatisticsProxy(
&fake_clock_, config, VideoEncoderConfig::ContentType::kRealtimeVideo));
test::ClearHistograms();
EncodedImage encoded_image;
CodecSpecificInfo codec_info;
codec_info.codecType = kVideoCodecVP8;
@ -342,12 +338,11 @@ TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp8OneSsrc) {
statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
}
statistics_proxy_.reset();
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.Encoded.Qp.Vp8"));
EXPECT_EQ(kQpIdx0, test::LastHistogramSample("WebRTC.Video.Encoded.Qp.Vp8"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp8"));
EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp8", kQpIdx0));
}
TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp9) {
test::ClearHistograms();
EncodedImage encoded_image;
CodecSpecificInfo codec_info;
codec_info.codecType = kVideoCodecVP9;
@ -362,12 +357,10 @@ TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp9) {
statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
}
statistics_proxy_.reset();
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.Encoded.Qp.Vp9.S0"));
EXPECT_EQ(kQpIdx0,
test::LastHistogramSample("WebRTC.Video.Encoded.Qp.Vp9.S0"));
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.Encoded.Qp.Vp9.S1"));
EXPECT_EQ(kQpIdx1,
test::LastHistogramSample("WebRTC.Video.Encoded.Qp.Vp9.S1"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp9.S0"));
EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp9.S0", kQpIdx0));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp9.S1"));
EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp9.S1", kQpIdx1));
}
TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp9OneSpatialLayer) {
@ -376,7 +369,6 @@ TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp9OneSpatialLayer) {
statistics_proxy_.reset(new SendStatisticsProxy(
&fake_clock_, config, VideoEncoderConfig::ContentType::kRealtimeVideo));
test::ClearHistograms();
EncodedImage encoded_image;
CodecSpecificInfo codec_info;
codec_info.codecType = kVideoCodecVP9;
@ -388,8 +380,8 @@ TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp9OneSpatialLayer) {
statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
}
statistics_proxy_.reset();
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.Encoded.Qp.Vp9"));
EXPECT_EQ(kQpIdx0, test::LastHistogramSample("WebRTC.Video.Encoded.Qp.Vp9"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp9"));
EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp9", kQpIdx0));
}
TEST_F(SendStatisticsProxyTest, NoSubstreams) {
@ -531,26 +523,24 @@ TEST_F(SendStatisticsProxyTest, ResetsRtcpCountersOnContentChange) {
// Changing content type causes histograms to be reported.
statistics_proxy_->SetContentType(VideoEncoderConfig::ContentType::kScreen);
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.NackPacketsReceivedPerMinute"));
EXPECT_EQ(
1, test::NumHistogramSamples("WebRTC.Video.FirPacketsReceivedPerMinute"));
EXPECT_EQ(
1, test::NumHistogramSamples("WebRTC.Video.PliPacketsReceivedPerMinute"));
EXPECT_EQ(1, test::NumHistogramSamples(
EXPECT_EQ(1,
metrics::NumSamples("WebRTC.Video.NackPacketsReceivedPerMinute"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.FirPacketsReceivedPerMinute"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PliPacketsReceivedPerMinute"));
EXPECT_EQ(1, metrics::NumSamples(
"WebRTC.Video.UniqueNackRequestsReceivedInPercent"));
const int kRate = 60 * 2; // Packets per minute with two streams.
EXPECT_EQ(1 * kRate, test::LastHistogramSample(
"WebRTC.Video.NackPacketsReceivedPerMinute"));
EXPECT_EQ(2 * kRate, test::LastHistogramSample(
"WebRTC.Video.FirPacketsReceivedPerMinute"));
EXPECT_EQ(3 * kRate, test::LastHistogramSample(
"WebRTC.Video.PliPacketsReceivedPerMinute"));
EXPECT_EQ(4 * 100 / 5,
test::LastHistogramSample(
"WebRTC.Video.UniqueNackRequestsReceivedInPercent"));
EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.NackPacketsReceivedPerMinute",
1 * kRate));
EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.FirPacketsReceivedPerMinute",
2 * kRate));
EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.PliPacketsReceivedPerMinute",
3 * kRate));
EXPECT_EQ(
1, metrics::NumEvents("WebRTC.Video.UniqueNackRequestsReceivedInPercent",
4 * 100 / 5));
// New start time but same counter values.
proxy->RtcpPacketTypesCounterUpdated(kFirstSsrc, counters);
@ -569,29 +559,29 @@ TEST_F(SendStatisticsProxyTest, ResetsRtcpCountersOnContentChange) {
SetUp(); // Reset stats proxy also causes histograms to be reported.
EXPECT_EQ(1, test::NumHistogramSamples(
EXPECT_EQ(1, metrics::NumSamples(
"WebRTC.Video.Screenshare.NackPacketsReceivedPerMinute"));
EXPECT_EQ(1, test::NumHistogramSamples(
EXPECT_EQ(1, metrics::NumSamples(
"WebRTC.Video.Screenshare.FirPacketsReceivedPerMinute"));
EXPECT_EQ(1, test::NumHistogramSamples(
EXPECT_EQ(1, metrics::NumSamples(
"WebRTC.Video.Screenshare.PliPacketsReceivedPerMinute"));
EXPECT_EQ(
1, test::NumHistogramSamples(
1, metrics::NumSamples(
"WebRTC.Video.Screenshare.UniqueNackRequestsReceivedInPercent"));
EXPECT_EQ(1 * kRate,
test::LastHistogramSample(
"WebRTC.Video.Screenshare.NackPacketsReceivedPerMinute"));
EXPECT_EQ(2 * kRate,
test::LastHistogramSample(
"WebRTC.Video.Screenshare.FirPacketsReceivedPerMinute"));
EXPECT_EQ(3 * kRate,
test::LastHistogramSample(
"WebRTC.Video.Screenshare.PliPacketsReceivedPerMinute"));
EXPECT_EQ(
4 * 100 / 5,
test::LastHistogramSample(
"WebRTC.Video.Screenshare.UniqueNackRequestsReceivedInPercent"));
EXPECT_EQ(1, metrics::NumEvents(
"WebRTC.Video.Screenshare.NackPacketsReceivedPerMinute",
1 * kRate));
EXPECT_EQ(1, metrics::NumEvents(
"WebRTC.Video.Screenshare.FirPacketsReceivedPerMinute",
2 * kRate));
EXPECT_EQ(1, metrics::NumEvents(
"WebRTC.Video.Screenshare.PliPacketsReceivedPerMinute",
3 * kRate));
EXPECT_EQ(1,
metrics::NumEvents(
"WebRTC.Video.Screenshare.UniqueNackRequestsReceivedInPercent",
4 * 100 / 5));
}
TEST_F(SendStatisticsProxyTest, ResetsRtpCountersOnContentChange) {
@ -628,39 +618,46 @@ TEST_F(SendStatisticsProxyTest, ResetsRtpCountersOnContentChange) {
// Changing content type causes histograms to be reported.
statistics_proxy_->SetContentType(VideoEncoderConfig::ContentType::kScreen);
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.BitrateSentInKbps"));
EXPECT_EQ(static_cast<int>((counters.transmitted.TotalBytes() * 4 * 8) /
metrics::kMinRunTimeInSeconds / 1000),
test::LastHistogramSample("WebRTC.Video.BitrateSentInKbps"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.BitrateSentInKbps"));
EXPECT_EQ(1,
metrics::NumEvents(
"WebRTC.Video.BitrateSentInKbps",
static_cast<int>((counters.transmitted.TotalBytes() * 4 * 8) /
metrics::kMinRunTimeInSeconds / 1000)));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.MediaBitrateSentInKbps"));
EXPECT_EQ(1, metrics::NumEvents(
"WebRTC.Video.MediaBitrateSentInKbps",
static_cast<int>((counters.MediaPayloadBytes() * 2 * 8) /
metrics::kMinRunTimeInSeconds / 1000)));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PaddingBitrateSentInKbps"));
EXPECT_EQ(1,
metrics::NumEvents(
"WebRTC.Video.PaddingBitrateSentInKbps",
static_cast<int>((counters.transmitted.padding_bytes * 4 * 8) /
metrics::kMinRunTimeInSeconds / 1000)));
EXPECT_EQ(1,
test::NumHistogramSamples("WebRTC.Video.MediaBitrateSentInKbps"));
EXPECT_EQ(static_cast<int>((counters.MediaPayloadBytes() * 2 * 8) /
metrics::kMinRunTimeInSeconds / 1000),
test::LastHistogramSample("WebRTC.Video.MediaBitrateSentInKbps"));
metrics::NumSamples("WebRTC.Video.RetransmittedBitrateSentInKbps"));
EXPECT_EQ(1,
test::NumHistogramSamples("WebRTC.Video.PaddingBitrateSentInKbps"));
EXPECT_EQ(static_cast<int>((counters.transmitted.padding_bytes * 4 * 8) /
metrics::kMinRunTimeInSeconds / 1000),
test::LastHistogramSample("WebRTC.Video.PaddingBitrateSentInKbps"));
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.RetransmittedBitrateSentInKbps"));
EXPECT_EQ(
metrics::NumEvents(
"WebRTC.Video.RetransmittedBitrateSentInKbps",
static_cast<int>((counters.retransmitted.TotalBytes() * 2 * 8) /
metrics::kMinRunTimeInSeconds / 1000),
test::LastHistogramSample("WebRTC.Video.RetransmittedBitrateSentInKbps"));
metrics::kMinRunTimeInSeconds / 1000)));
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.RtxBitrateSentInKbps"));
EXPECT_EQ(static_cast<int>((rtx_counters.transmitted.TotalBytes() * 2 * 8) /
metrics::kMinRunTimeInSeconds / 1000),
test::LastHistogramSample("WebRTC.Video.RtxBitrateSentInKbps"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtxBitrateSentInKbps"));
EXPECT_EQ(
1, metrics::NumEvents(
"WebRTC.Video.RtxBitrateSentInKbps",
static_cast<int>((rtx_counters.transmitted.TotalBytes() * 2 * 8) /
metrics::kMinRunTimeInSeconds / 1000)));
EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.FecBitrateSentInKbps"));
EXPECT_EQ(static_cast<int>((rtx_counters.fec.TotalBytes() * 2 * 8) /
metrics::kMinRunTimeInSeconds / 1000),
test::LastHistogramSample("WebRTC.Video.FecBitrateSentInKbps"));
EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.FecBitrateSentInKbps"));
EXPECT_EQ(1, metrics::NumEvents(
"WebRTC.Video.FecBitrateSentInKbps",
static_cast<int>((rtx_counters.fec.TotalBytes() * 2 * 8) /
metrics::kMinRunTimeInSeconds / 1000)));
// New start time but same counter values.
proxy->DataCountersUpdated(counters, kFirstSsrc);
@ -683,47 +680,51 @@ TEST_F(SendStatisticsProxyTest, ResetsRtpCountersOnContentChange) {
SetUp(); // Reset stats proxy also causes histograms to be reported.
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.Screenshare.BitrateSentInKbps"));
EXPECT_EQ(
EXPECT_EQ(1,
metrics::NumSamples("WebRTC.Video.Screenshare.BitrateSentInKbps"));
EXPECT_EQ(1,
metrics::NumEvents(
"WebRTC.Video.Screenshare.BitrateSentInKbps",
static_cast<int>((counters.transmitted.TotalBytes() * 4 * 8) /
metrics::kMinRunTimeInSeconds / 1000),
test::LastHistogramSample("WebRTC.Video.Screenshare.BitrateSentInKbps"));
metrics::kMinRunTimeInSeconds / 1000)));
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.Screenshare.MediaBitrateSentInKbps"));
EXPECT_EQ(static_cast<int>((counters.MediaPayloadBytes() * 2 * 8) /
metrics::kMinRunTimeInSeconds / 1000),
test::LastHistogramSample(
EXPECT_EQ(1, metrics::NumSamples(
"WebRTC.Video.Screenshare.MediaBitrateSentInKbps"));
EXPECT_EQ(1, metrics::NumEvents(
"WebRTC.Video.Screenshare.MediaBitrateSentInKbps",
static_cast<int>((counters.MediaPayloadBytes() * 2 * 8) /
metrics::kMinRunTimeInSeconds / 1000)));
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.Screenshare.PaddingBitrateSentInKbps"));
EXPECT_EQ(static_cast<int>((counters.transmitted.padding_bytes * 4 * 8) /
metrics::kMinRunTimeInSeconds / 1000),
test::LastHistogramSample(
EXPECT_EQ(1, metrics::NumSamples(
"WebRTC.Video.Screenshare.PaddingBitrateSentInKbps"));
EXPECT_EQ(1,
metrics::NumEvents(
"WebRTC.Video.Screenshare.PaddingBitrateSentInKbps",
static_cast<int>((counters.transmitted.padding_bytes * 4 * 8) /
metrics::kMinRunTimeInSeconds / 1000)));
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.Screenshare.RetransmittedBitrateSentInKbps"));
EXPECT_EQ(static_cast<int>((counters.retransmitted.TotalBytes() * 2 * 8) /
metrics::kMinRunTimeInSeconds / 1000),
test::LastHistogramSample(
EXPECT_EQ(1, metrics::NumSamples(
"WebRTC.Video.Screenshare.RetransmittedBitrateSentInKbps"));
EXPECT_EQ(1,
metrics::NumEvents(
"WebRTC.Video.Screenshare.RetransmittedBitrateSentInKbps",
static_cast<int>((counters.retransmitted.TotalBytes() * 2 * 8) /
metrics::kMinRunTimeInSeconds / 1000)));
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.Screenshare.RtxBitrateSentInKbps"));
EXPECT_EQ(static_cast<int>((rtx_counters.transmitted.TotalBytes() * 2 * 8) /
metrics::kMinRunTimeInSeconds / 1000),
test::LastHistogramSample(
"WebRTC.Video.Screenshare.RtxBitrateSentInKbps"));
EXPECT_EQ(
1, metrics::NumSamples("WebRTC.Video.Screenshare.RtxBitrateSentInKbps"));
EXPECT_EQ(
1, metrics::NumEvents(
"WebRTC.Video.Screenshare.RtxBitrateSentInKbps",
static_cast<int>((rtx_counters.transmitted.TotalBytes() * 2 * 8) /
metrics::kMinRunTimeInSeconds / 1000)));
EXPECT_EQ(1, test::NumHistogramSamples(
"WebRTC.Video.Screenshare.FecBitrateSentInKbps"));
EXPECT_EQ(static_cast<int>((rtx_counters.fec.TotalBytes() * 2 * 8) /
metrics::kMinRunTimeInSeconds / 1000),
test::LastHistogramSample(
"WebRTC.Video.Screenshare.FecBitrateSentInKbps"));
EXPECT_EQ(
1, metrics::NumSamples("WebRTC.Video.Screenshare.FecBitrateSentInKbps"));
EXPECT_EQ(1, metrics::NumEvents(
"WebRTC.Video.Screenshare.FecBitrateSentInKbps",
static_cast<int>((rtx_counters.fec.TotalBytes() * 2 * 8) /
metrics::kMinRunTimeInSeconds / 1000)));
}
} // namespace webrtc