Migrate audio perf tests on new perf metrics export API

Bug: b/246095034
Change-Id: Id659e43c116428cab47d334c93a6036f74dbb8e1
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/276626
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Ivo Creusen <ivoc@webrtc.org>
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38192}
This commit is contained in:
Artem Titov
2022-09-25 00:29:43 +02:00
committed by WebRTC LUCI CQ
parent cc6aae7a4c
commit e39115a0ca
3 changed files with 43 additions and 23 deletions

View File

@ -1431,12 +1431,13 @@ if (rtc_include_tests) {
":neteq_test_support", ":neteq_test_support",
":neteq_test_tools", ":neteq_test_tools",
"../../api/audio_codecs/opus:audio_encoder_opus", "../../api/audio_codecs/opus:audio_encoder_opus",
"../../api/test/metrics:global_metrics_logger_and_exporter",
"../../api/test/metrics:metric",
"../../rtc_base:macromagic", "../../rtc_base:macromagic",
"../../rtc_base:timeutils", "../../rtc_base:timeutils",
"../../system_wrappers", "../../system_wrappers",
"../../system_wrappers:field_trial", "../../system_wrappers:field_trial",
"../../test:fileutils", "../../test:fileutils",
"../../test:perf_test",
"../../test:test_support", "../../test:test_support",
] ]
} }

View File

@ -9,15 +9,20 @@
*/ */
#include "api/audio_codecs/opus/audio_encoder_opus.h" #include "api/audio_codecs/opus/audio_encoder_opus.h"
#include "api/test/metrics/global_metrics_logger_and_exporter.h"
#include "api/test/metrics/metric.h"
#include "modules/audio_coding/neteq/tools/audio_loop.h" #include "modules/audio_coding/neteq/tools/audio_loop.h"
#include "rtc_base/time_utils.h" #include "rtc_base/time_utils.h"
#include "test/gtest.h" #include "test/gtest.h"
#include "test/testsupport/file_utils.h" #include "test/testsupport/file_utils.h"
#include "test/testsupport/perf_test.h"
namespace webrtc { namespace webrtc {
namespace { namespace {
using ::webrtc::test::GetGlobalMetricsLogger;
using ::webrtc::test::ImprovementDirection;
using ::webrtc::test::Unit;
int64_t RunComplexityTest(const AudioEncoderOpusConfig& config) { int64_t RunComplexityTest(const AudioEncoderOpusConfig& config) {
// Create encoder. // Create encoder.
constexpr int payload_type = 17; constexpr int payload_type = 17;
@ -46,7 +51,6 @@ int64_t RunComplexityTest(const AudioEncoderOpusConfig& config) {
} }
return rtc::TimeMillis() - start_time_ms; return rtc::TimeMillis() - start_time_ms;
} }
} // namespace
// This test encodes an audio file using Opus twice with different bitrates // This test encodes an audio file using Opus twice with different bitrates
// (~11 kbps and 15.5 kbps). The runtime for each is measured, and the ratio // (~11 kbps and 15.5 kbps). The runtime for each is measured, and the ratio
@ -70,9 +74,10 @@ TEST(AudioEncoderOpusComplexityAdaptationTest, Adaptation_On) {
config.bitrate_bps = 15500; config.bitrate_bps = 15500;
int64_t runtime_15500bps = RunComplexityTest(config); int64_t runtime_15500bps = RunComplexityTest(config);
test::PrintResult("opus_encoding_complexity_ratio", "", "adaptation_on", GetGlobalMetricsLogger()->LogSingleValueMetric(
100.0 * runtime_10999bps / runtime_15500bps, "percent", "opus_encoding_complexity_ratio", "adaptation_on",
true); 100.0 * runtime_10999bps / runtime_15500bps, Unit::kPercent,
ImprovementDirection::kNeitherIsBetter);
} }
// This test is identical to the one above, but without the complexity // This test is identical to the one above, but without the complexity
@ -90,8 +95,11 @@ TEST(AudioEncoderOpusComplexityAdaptationTest, Adaptation_Off) {
config.bitrate_bps = 15500; config.bitrate_bps = 15500;
int64_t runtime_15500bps = RunComplexityTest(config); int64_t runtime_15500bps = RunComplexityTest(config);
test::PrintResult("opus_encoding_complexity_ratio", "", "adaptation_off", GetGlobalMetricsLogger()->LogSingleValueMetric(
100.0 * runtime_10999bps / runtime_15500bps, "percent", "opus_encoding_complexity_ratio", "adaptation_off",
true); 100.0 * runtime_10999bps / runtime_15500bps, Unit::kPercent,
ImprovementDirection::kNeitherIsBetter);
} }
} // namespace
} // namespace webrtc } // namespace webrtc

View File

@ -8,10 +8,18 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include "api/test/metrics/global_metrics_logger_and_exporter.h"
#include "api/test/metrics/metric.h"
#include "modules/audio_coding/neteq/tools/neteq_performance_test.h" #include "modules/audio_coding/neteq/tools/neteq_performance_test.h"
#include "system_wrappers/include/field_trial.h" #include "system_wrappers/include/field_trial.h"
#include "test/gtest.h" #include "test/gtest.h"
#include "test/testsupport/perf_test.h"
namespace webrtc {
namespace {
using ::webrtc::test::GetGlobalMetricsLogger;
using ::webrtc::test::ImprovementDirection;
using ::webrtc::test::Unit;
// Runs a test with 10% packet losses and 10% clock drift, to exercise // Runs a test with 10% packet losses and 10% clock drift, to exercise
// both loss concealment and time-stretching code. // both loss concealment and time-stretching code.
@ -20,14 +28,14 @@ TEST(NetEqPerformanceTest, 10_Pl_10_Drift) {
const int kQuickSimulationTimeMs = 100000; const int kQuickSimulationTimeMs = 100000;
const int kLossPeriod = 10; // Drop every 10th packet. const int kLossPeriod = 10; // Drop every 10th packet.
const double kDriftFactor = 0.1; const double kDriftFactor = 0.1;
int64_t runtime = webrtc::test::NetEqPerformanceTest::Run( int64_t runtime = test::NetEqPerformanceTest::Run(
webrtc::field_trial::IsEnabled("WebRTC-QuickPerfTest") field_trial::IsEnabled("WebRTC-QuickPerfTest") ? kQuickSimulationTimeMs
? kQuickSimulationTimeMs : kSimulationTimeMs,
: kSimulationTimeMs,
kLossPeriod, kDriftFactor); kLossPeriod, kDriftFactor);
ASSERT_GT(runtime, 0); ASSERT_GT(runtime, 0);
webrtc::test::PrintResult("neteq_performance", "", "10_pl_10_drift", runtime, GetGlobalMetricsLogger()->LogSingleValueMetric(
"ms", true); "neteq_performance", "10_pl_10_drift", runtime, Unit::kMilliseconds,
ImprovementDirection::kNeitherIsBetter);
} }
// Runs a test with neither packet losses nor clock drift, to put // Runs a test with neither packet losses nor clock drift, to put
@ -38,12 +46,15 @@ TEST(NetEqPerformanceTest, 0_Pl_0_Drift) {
const int kQuickSimulationTimeMs = 100000; const int kQuickSimulationTimeMs = 100000;
const int kLossPeriod = 0; // No losses. const int kLossPeriod = 0; // No losses.
const double kDriftFactor = 0.0; // No clock drift. const double kDriftFactor = 0.0; // No clock drift.
int64_t runtime = webrtc::test::NetEqPerformanceTest::Run( int64_t runtime = test::NetEqPerformanceTest::Run(
webrtc::field_trial::IsEnabled("WebRTC-QuickPerfTest") field_trial::IsEnabled("WebRTC-QuickPerfTest") ? kQuickSimulationTimeMs
? kQuickSimulationTimeMs : kSimulationTimeMs,
: kSimulationTimeMs,
kLossPeriod, kDriftFactor); kLossPeriod, kDriftFactor);
ASSERT_GT(runtime, 0); ASSERT_GT(runtime, 0);
webrtc::test::PrintResult("neteq_performance", "", "0_pl_0_drift", runtime, GetGlobalMetricsLogger()->LogSingleValueMetric(
"ms", true); "neteq_performance", "0_pl_0_drift", runtime, Unit::kMilliseconds,
ImprovementDirection::kNeitherIsBetter);
} }
} // namespace
} // namespace webrtc