[PCLF] Add possibility to use new perf metrics api in NetworkQualityMetricsReporter

Bug: b/246095034
Change-Id: I5198d73aaf2b32b59c9c15504628d0edd2bd9885
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/276201
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38146}
This commit is contained in:
Artem Titov
2022-09-21 09:30:57 +02:00
committed by WebRTC LUCI CQ
parent e11d5e378c
commit 86f2022f0e
3 changed files with 88 additions and 28 deletions

View File

@ -853,6 +853,8 @@ if (!build_with_chromium) {
"../../../api:peer_connection_quality_test_fixture_api", "../../../api:peer_connection_quality_test_fixture_api",
"../../../api:rtc_stats_api", "../../../api:rtc_stats_api",
"../../../api:track_id_stream_info_map", "../../../api:track_id_stream_info_map",
"../../../api/test/metrics:metric",
"../../../api/test/metrics:metrics_logger_and_exporter",
"../../../api/units:data_size", "../../../api/units:data_size",
"../../../rtc_base:criticalsection", "../../../rtc_base:criticalsection",
"../../../rtc_base:rtc_event", "../../../rtc_base:rtc_event",

View File

@ -13,6 +13,7 @@
#include "api/stats/rtc_stats.h" #include "api/stats/rtc_stats.h"
#include "api/stats/rtcstats_objects.h" #include "api/stats/rtcstats_objects.h"
#include "api/test/metrics/metric.h"
#include "rtc_base/event.h" #include "rtc_base/event.h"
#include "system_wrappers/include/field_trial.h" #include "system_wrappers/include/field_trial.h"
#include "test/testsupport/perf_test.h" #include "test/testsupport/perf_test.h"
@ -21,6 +22,9 @@ namespace webrtc {
namespace webrtc_pc_e2e { namespace webrtc_pc_e2e {
namespace { namespace {
using ::webrtc::test::ImprovementDirection;
using ::webrtc::test::Unit;
constexpr TimeDelta kStatsWaitTimeout = TimeDelta::Seconds(1); constexpr TimeDelta kStatsWaitTimeout = TimeDelta::Seconds(1);
// Field trial which controls whether to report standard-compliant bytes // Field trial which controls whether to report standard-compliant bytes
@ -109,35 +113,79 @@ void NetworkQualityMetricsReporter::ReportStats(
const std::string& network_label, const std::string& network_label,
std::unique_ptr<EmulatedNetworkStats> stats, std::unique_ptr<EmulatedNetworkStats> stats,
int64_t packet_loss) { int64_t packet_loss) {
ReportResult("bytes_sent", network_label, stats->BytesSent().bytes(), if (metrics_logger_ == nullptr) {
"sizeInBytes"); ReportResult("bytes_sent", network_label, stats->BytesSent().bytes(),
ReportResult("packets_sent", network_label, stats->PacketsSent(), "unitless"); "sizeInBytes");
ReportResult( ReportResult("packets_sent", network_label, stats->PacketsSent(),
"average_send_rate", network_label, "unitless");
stats->PacketsSent() >= 2 ? stats->AverageSendRate().bytes_per_sec() : 0, ReportResult("average_send_rate", network_label,
"bytesPerSecond"); stats->PacketsSent() >= 2
ReportResult("bytes_discarded_no_receiver", network_label, ? stats->AverageSendRate().bytes_per_sec()
stats->BytesDropped().bytes(), "sizeInBytes"); : 0,
ReportResult("packets_discarded_no_receiver", network_label, "bytesPerSecond");
stats->PacketsDropped(), "unitless"); ReportResult("bytes_discarded_no_receiver", network_label,
ReportResult("bytes_received", network_label, stats->BytesReceived().bytes(), stats->BytesDropped().bytes(), "sizeInBytes");
"sizeInBytes"); ReportResult("packets_discarded_no_receiver", network_label,
ReportResult("packets_received", network_label, stats->PacketsReceived(), stats->PacketsDropped(), "unitless");
"unitless"); ReportResult("bytes_received", network_label,
ReportResult("average_receive_rate", network_label, stats->BytesReceived().bytes(), "sizeInBytes");
stats->PacketsReceived() >= 2 ReportResult("packets_received", network_label, stats->PacketsReceived(),
? stats->AverageReceiveRate().bytes_per_sec() "unitless");
: 0, ReportResult("average_receive_rate", network_label,
"bytesPerSecond"); stats->PacketsReceived() >= 2
ReportResult("sent_packets_loss", network_label, packet_loss, "unitless"); ? stats->AverageReceiveRate().bytes_per_sec()
: 0,
"bytesPerSecond");
ReportResult("sent_packets_loss", network_label, packet_loss, "unitless");
} else {
metrics_logger_->LogSingleValueMetric(
"bytes_sent", network_label, stats->BytesSent().bytes(), Unit::kBytes,
ImprovementDirection::kNeitherIsBetter);
metrics_logger_->LogSingleValueMetric(
"packets_sent", network_label, stats->PacketsSent(), Unit::kUnitless,
ImprovementDirection::kNeitherIsBetter);
metrics_logger_->LogSingleValueMetric(
"average_send_rate", network_label,
stats->PacketsSent() >= 2 ? stats->AverageSendRate().kbps() : 0,
Unit::kKilobitsPerSecond, ImprovementDirection::kNeitherIsBetter);
metrics_logger_->LogSingleValueMetric(
"bytes_discarded_no_receiver", network_label,
stats->BytesDropped().bytes(), Unit::kBytes,
ImprovementDirection::kNeitherIsBetter);
metrics_logger_->LogSingleValueMetric(
"packets_discarded_no_receiver", network_label, stats->PacketsDropped(),
Unit::kUnitless, ImprovementDirection::kNeitherIsBetter);
metrics_logger_->LogSingleValueMetric(
"bytes_received", network_label, stats->BytesReceived().bytes(),
Unit::kBytes, ImprovementDirection::kNeitherIsBetter);
metrics_logger_->LogSingleValueMetric(
"packets_received", network_label, stats->PacketsReceived(),
Unit::kUnitless, ImprovementDirection::kNeitherIsBetter);
metrics_logger_->LogSingleValueMetric(
"average_receive_rate", network_label,
stats->PacketsReceived() >= 2 ? stats->AverageReceiveRate().kbps() : 0,
Unit::kKilobitsPerSecond, ImprovementDirection::kNeitherIsBetter);
metrics_logger_->LogSingleValueMetric(
"sent_packets_loss", network_label, packet_loss, Unit::kUnitless,
ImprovementDirection::kNeitherIsBetter);
}
} }
void NetworkQualityMetricsReporter::ReportPCStats(const std::string& pc_label, void NetworkQualityMetricsReporter::ReportPCStats(const std::string& pc_label,
const PCStats& stats) { const PCStats& stats) {
ReportResult("payload_bytes_received", pc_label, if (metrics_logger_ == nullptr) {
stats.payload_received.bytes(), "sizeInBytes"); ReportResult("payload_bytes_received", pc_label,
ReportResult("payload_bytes_sent", pc_label, stats.payload_sent.bytes(), stats.payload_received.bytes(), "sizeInBytes");
"sizeInBytes"); ReportResult("payload_bytes_sent", pc_label, stats.payload_sent.bytes(),
"sizeInBytes");
} else {
metrics_logger_->LogSingleValueMetric(
"payload_bytes_received", pc_label, stats.payload_received.bytes(),
Unit::kBytes, ImprovementDirection::kNeitherIsBetter);
metrics_logger_->LogSingleValueMetric(
"payload_bytes_sent", pc_label, stats.payload_sent.bytes(),
Unit::kBytes, ImprovementDirection::kNeitherIsBetter);
}
} }
void NetworkQualityMetricsReporter::ReportResult( void NetworkQualityMetricsReporter::ReportResult(

View File

@ -15,6 +15,7 @@
#include <string> #include <string>
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "api/test/metrics/metrics_logger_and_exporter.h"
#include "api/test/network_emulation_manager.h" #include "api/test/network_emulation_manager.h"
#include "api/test/peerconnection_quality_test_fixture.h" #include "api/test/peerconnection_quality_test_fixture.h"
#include "api/test/track_id_stream_info_map.h" #include "api/test/track_id_stream_info_map.h"
@ -29,7 +30,15 @@ class NetworkQualityMetricsReporter
public: public:
NetworkQualityMetricsReporter(EmulatedNetworkManagerInterface* alice_network, NetworkQualityMetricsReporter(EmulatedNetworkManagerInterface* alice_network,
EmulatedNetworkManagerInterface* bob_network) EmulatedNetworkManagerInterface* bob_network)
: alice_network_(alice_network), bob_network_(bob_network) {} : NetworkQualityMetricsReporter(alice_network,
bob_network,
/*metrics_logger=*/nullptr) {}
NetworkQualityMetricsReporter(EmulatedNetworkManagerInterface* alice_network,
EmulatedNetworkManagerInterface* bob_network,
test::MetricsLoggerAndExporter* metrics_logger)
: alice_network_(alice_network),
bob_network_(bob_network),
metrics_logger_(metrics_logger) {}
~NetworkQualityMetricsReporter() override = default; ~NetworkQualityMetricsReporter() override = default;
// Network stats must be empty when this method will be invoked. // Network stats must be empty when this method will be invoked.
@ -62,8 +71,9 @@ class NetworkQualityMetricsReporter
std::string test_case_name_; std::string test_case_name_;
EmulatedNetworkManagerInterface* alice_network_; EmulatedNetworkManagerInterface* const alice_network_;
EmulatedNetworkManagerInterface* bob_network_; EmulatedNetworkManagerInterface* const bob_network_;
test::MetricsLoggerAndExporter* const metrics_logger_;
Mutex lock_; Mutex lock_;
std::map<std::string, PCStats> pc_stats_ RTC_GUARDED_BY(lock_); std::map<std::string, PCStats> pc_stats_ RTC_GUARDED_BY(lock_);
}; };