Migrate CallSimulator to the new perf metrics logging API
Bug: b/246095034 Change-Id: I613f702d2f469b6bc8d1634f8dda40d444ff7cf2 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/276632 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Per Åhgren <peah@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/main@{#38213}
This commit is contained in:
parent
e2f2cae3fb
commit
7fee2f7908
@ -19,6 +19,10 @@
|
|||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
SamplesStatsCounter::SamplesStatsCounter() = default;
|
SamplesStatsCounter::SamplesStatsCounter() = default;
|
||||||
|
SamplesStatsCounter::SamplesStatsCounter(size_t expected_samples_count) {
|
||||||
|
samples_.reserve(expected_samples_count);
|
||||||
|
}
|
||||||
|
|
||||||
SamplesStatsCounter::~SamplesStatsCounter() = default;
|
SamplesStatsCounter::~SamplesStatsCounter() = default;
|
||||||
SamplesStatsCounter::SamplesStatsCounter(const SamplesStatsCounter&) = default;
|
SamplesStatsCounter::SamplesStatsCounter(const SamplesStatsCounter&) = default;
|
||||||
SamplesStatsCounter& SamplesStatsCounter::operator=(
|
SamplesStatsCounter& SamplesStatsCounter::operator=(
|
||||||
|
|||||||
@ -34,6 +34,7 @@ class SamplesStatsCounter {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SamplesStatsCounter();
|
SamplesStatsCounter();
|
||||||
|
explicit SamplesStatsCounter(size_t expected_samples_count);
|
||||||
~SamplesStatsCounter();
|
~SamplesStatsCounter();
|
||||||
SamplesStatsCounter(const SamplesStatsCounter&);
|
SamplesStatsCounter(const SamplesStatsCounter&);
|
||||||
SamplesStatsCounter& operator=(const SamplesStatsCounter&);
|
SamplesStatsCounter& operator=(const SamplesStatsCounter&);
|
||||||
|
|||||||
@ -498,13 +498,15 @@ if (rtc_include_tests) {
|
|||||||
":audio_processing",
|
":audio_processing",
|
||||||
":audioproc_test_utils",
|
":audioproc_test_utils",
|
||||||
"../../api:array_view",
|
"../../api:array_view",
|
||||||
|
"../../api/numerics",
|
||||||
|
"../../api/test/metrics:global_metrics_logger_and_exporter",
|
||||||
|
"../../api/test/metrics:metric",
|
||||||
"../../rtc_base:platform_thread",
|
"../../rtc_base:platform_thread",
|
||||||
"../../rtc_base:protobuf_utils",
|
"../../rtc_base:protobuf_utils",
|
||||||
"../../rtc_base:random",
|
"../../rtc_base:random",
|
||||||
"../../rtc_base:rtc_event",
|
"../../rtc_base:rtc_event",
|
||||||
"../../rtc_base:safe_conversions",
|
"../../rtc_base:safe_conversions",
|
||||||
"../../system_wrappers",
|
"../../system_wrappers",
|
||||||
"../../test:perf_test",
|
|
||||||
"../../test:test_support",
|
"../../test:test_support",
|
||||||
]
|
]
|
||||||
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
|
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
|
||||||
|
|||||||
@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
#include "absl/strings/string_view.h"
|
#include "absl/strings/string_view.h"
|
||||||
#include "api/array_view.h"
|
#include "api/array_view.h"
|
||||||
|
#include "api/numerics/samples_stats_counter.h"
|
||||||
|
#include "api/test/metrics/global_metrics_logger_and_exporter.h"
|
||||||
|
#include "api/test/metrics/metric.h"
|
||||||
#include "modules/audio_processing/audio_processing_impl.h"
|
#include "modules/audio_processing/audio_processing_impl.h"
|
||||||
#include "modules/audio_processing/test/audio_processing_builder_for_testing.h"
|
#include "modules/audio_processing/test/audio_processing_builder_for_testing.h"
|
||||||
#include "modules/audio_processing/test/test_utils.h"
|
#include "modules/audio_processing/test/test_utils.h"
|
||||||
@ -25,13 +28,14 @@
|
|||||||
#include "rtc_base/random.h"
|
#include "rtc_base/random.h"
|
||||||
#include "system_wrappers/include/clock.h"
|
#include "system_wrappers/include/clock.h"
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
#include "test/testsupport/perf_test.h"
|
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
static const bool kPrintAllDurations = false;
|
using ::webrtc::test::GetGlobalMetricsLogger;
|
||||||
|
using ::webrtc::test::ImprovementDirection;
|
||||||
|
using ::webrtc::test::Metric;
|
||||||
|
using ::webrtc::test::Unit;
|
||||||
|
|
||||||
class CallSimulator;
|
class CallSimulator;
|
||||||
|
|
||||||
@ -203,11 +207,11 @@ class TimedThreadApiProcessor {
|
|||||||
frame_data_(kMaxFrameSize),
|
frame_data_(kMaxFrameSize),
|
||||||
clock_(webrtc::Clock::GetRealTimeClock()),
|
clock_(webrtc::Clock::GetRealTimeClock()),
|
||||||
num_durations_to_store_(num_durations_to_store),
|
num_durations_to_store_(num_durations_to_store),
|
||||||
|
api_call_durations_(num_durations_to_store_ - kNumInitializationFrames),
|
||||||
|
samples_count_(0),
|
||||||
input_level_(input_level),
|
input_level_(input_level),
|
||||||
processor_type_(processor_type),
|
processor_type_(processor_type),
|
||||||
num_channels_(num_channels) {
|
num_channels_(num_channels) {}
|
||||||
api_call_durations_.reserve(num_durations_to_store_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implements the callback functionality for the threads.
|
// Implements the callback functionality for the threads.
|
||||||
bool Process();
|
bool Process();
|
||||||
@ -219,21 +223,17 @@ class TimedThreadApiProcessor {
|
|||||||
const std::string sample_rate_name =
|
const std::string sample_rate_name =
|
||||||
"_" + std::to_string(simulation_config_->sample_rate_hz) + "Hz";
|
"_" + std::to_string(simulation_config_->sample_rate_hz) + "Hz";
|
||||||
|
|
||||||
webrtc::test::PrintResultMeanAndError(
|
GetGlobalMetricsLogger()->LogMetric(
|
||||||
"apm_timing", sample_rate_name, processor_name, GetDurationAverage(),
|
"apm_timing" + sample_rate_name, processor_name, api_call_durations_,
|
||||||
GetDurationStandardDeviation(), "us", false);
|
Unit::kMilliseconds, ImprovementDirection::kNeitherIsBetter);
|
||||||
|
|
||||||
if (kPrintAllDurations) {
|
|
||||||
webrtc::test::PrintResultList("apm_call_durations", sample_rate_name,
|
|
||||||
processor_name, api_call_durations_, "us",
|
|
||||||
false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddDuration(int64_t duration) {
|
void AddDuration(int64_t duration) {
|
||||||
if (api_call_durations_.size() < num_durations_to_store_) {
|
if (samples_count_ >= kNumInitializationFrames &&
|
||||||
api_call_durations_.push_back(duration);
|
samples_count_ < num_durations_to_store_) {
|
||||||
|
api_call_durations_.AddSample(duration);
|
||||||
}
|
}
|
||||||
|
samples_count_++;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -241,32 +241,6 @@ class TimedThreadApiProcessor {
|
|||||||
static const int kMaxFrameSize = 480;
|
static const int kMaxFrameSize = 480;
|
||||||
static const int kNumInitializationFrames = 5;
|
static const int kNumInitializationFrames = 5;
|
||||||
|
|
||||||
int64_t GetDurationStandardDeviation() const {
|
|
||||||
double variance = 0;
|
|
||||||
const int64_t average_duration = GetDurationAverage();
|
|
||||||
for (size_t k = kNumInitializationFrames; k < api_call_durations_.size();
|
|
||||||
k++) {
|
|
||||||
int64_t tmp = api_call_durations_[k] - average_duration;
|
|
||||||
variance += static_cast<double>(tmp * tmp);
|
|
||||||
}
|
|
||||||
const int denominator = rtc::checked_cast<int>(api_call_durations_.size()) -
|
|
||||||
kNumInitializationFrames;
|
|
||||||
return (denominator > 0
|
|
||||||
? rtc::checked_cast<int64_t>(sqrt(variance / denominator))
|
|
||||||
: -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t GetDurationAverage() const {
|
|
||||||
int64_t average_duration = 0;
|
|
||||||
for (size_t k = kNumInitializationFrames; k < api_call_durations_.size();
|
|
||||||
k++) {
|
|
||||||
average_duration += api_call_durations_[k];
|
|
||||||
}
|
|
||||||
const int denominator = rtc::checked_cast<int>(api_call_durations_.size()) -
|
|
||||||
kNumInitializationFrames;
|
|
||||||
return (denominator > 0 ? average_duration / denominator : -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ProcessCapture() {
|
int ProcessCapture() {
|
||||||
// Set the stream delay.
|
// Set the stream delay.
|
||||||
apm_->set_stream_delay_ms(30);
|
apm_->set_stream_delay_ms(30);
|
||||||
@ -382,7 +356,8 @@ class TimedThreadApiProcessor {
|
|||||||
AudioFrameData frame_data_;
|
AudioFrameData frame_data_;
|
||||||
webrtc::Clock* clock_;
|
webrtc::Clock* clock_;
|
||||||
const size_t num_durations_to_store_;
|
const size_t num_durations_to_store_;
|
||||||
std::vector<double> api_call_durations_;
|
SamplesStatsCounter api_call_durations_;
|
||||||
|
size_t samples_count_ = 0;
|
||||||
const float input_level_;
|
const float input_level_;
|
||||||
bool first_process_call_ = true;
|
bool first_process_call_ = true;
|
||||||
const ProcessorType processor_type_;
|
const ProcessorType processor_type_;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user