Implement packets_(sent | received) for RTCTransportStats

Bug: webrtc:11756
Change-Id: Ic0caad6d4675969ef3ae886f50326e4a2e1cbfe7
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178741
Reviewed-by: Tommi <tommi@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31643}
This commit is contained in:
Artem Titov
2020-07-06 16:06:37 +02:00
committed by Commit Bot
parent 3444a49d77
commit fb6f975401
9 changed files with 35 additions and 0 deletions

View File

@ -602,7 +602,9 @@ class RTC_EXPORT RTCTransportStats final : public RTCStats {
~RTCTransportStats() override;
RTCStatsMember<uint64_t> bytes_sent;
RTCStatsMember<uint64_t> packets_sent;
RTCStatsMember<uint64_t> bytes_received;
RTCStatsMember<uint64_t> packets_received;
RTCStatsMember<std::string> rtcp_transport_stats_id;
// TODO(hbos): Support enum types? "RTCStatsMember<RTCDtlsTransportState>"?
RTCStatsMember<std::string> dtls_state;

View File

@ -461,6 +461,7 @@ void Connection::OnReadPacket(const char* data,
last_data_received_ = rtc::TimeMillis();
UpdateReceiving(last_data_received_);
recv_rate_tracker_.AddSamples(size);
stats_.packets_received++;
SignalReadPacket(this, data, size, packet_time_us);
// If timed out sending writability checks, start up again

View File

@ -28,6 +28,7 @@ ConnectionInfo::ConnectionInfo()
sent_ping_responses(0),
recv_total_bytes(0),
recv_bytes_second(0),
packets_received(0),
recv_ping_requests(0),
recv_ping_responses(0),
key(nullptr),

View File

@ -54,6 +54,7 @@ struct ConnectionInfo {
size_t recv_total_bytes; // Total bytes received on this connection.
size_t recv_bytes_second; // Bps over the last measurement interval.
size_t packets_received; // Number of packets that were received.
size_t recv_ping_requests; // Number of STUN ping request received.
size_t recv_ping_responses; // Number of STUN ping response received.
Candidate local_candidate; // The local candidate for this connection.

View File

@ -1284,6 +1284,7 @@ TEST_F(P2PTransportChannelTest, GetStats) {
ep2_ch1()->receiving() &&
ep2_ch1()->writable(),
kMediumTimeout, clock);
// Sends and receives 10 packets.
TestSendRecv(&clock);
IceTransportStats ice_transport_stats;
ASSERT_TRUE(ep1_ch1()->GetStats(&ice_transport_stats));
@ -1306,6 +1307,7 @@ TEST_F(P2PTransportChannelTest, GetStats) {
EXPECT_EQ(0U, best_conn_info->sent_discarded_packets);
EXPECT_EQ(10 * 36U, best_conn_info->sent_total_bytes);
EXPECT_EQ(10 * 36U, best_conn_info->recv_total_bytes);
EXPECT_EQ(10U, best_conn_info->packets_received);
DestroyChannels();
}

View File

@ -1744,7 +1744,9 @@ void RTCStatsCollector::ProduceTransportStats_n(
transport_name, channel_stats.component),
timestamp_us));
transport_stats->bytes_sent = 0;
transport_stats->packets_sent = 0;
transport_stats->bytes_received = 0;
transport_stats->packets_received = 0;
transport_stats->dtls_state =
DtlsTransportStateToRTCDtlsTransportState(channel_stats.dtls_state);
transport_stats->selected_candidate_pair_changes =
@ -1752,7 +1754,10 @@ void RTCStatsCollector::ProduceTransportStats_n(
for (const cricket::ConnectionInfo& info :
channel_stats.ice_transport_stats.connection_infos) {
*transport_stats->bytes_sent += info.sent_total_bytes;
*transport_stats->packets_sent +=
info.sent_total_packets - info.sent_discarded_packets;
*transport_stats->bytes_received += info.recv_total_bytes;
*transport_stats->packets_received += info.packets_received;
if (info.best_connection) {
transport_stats->selected_candidate_pair_id =
RTCIceCandidatePairStatsIDFromConnectionInfo(info);

View File

@ -2139,6 +2139,9 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStats) {
rtp_connection_info.remote_candidate = *rtp_remote_candidate.get();
rtp_connection_info.sent_total_bytes = 42;
rtp_connection_info.recv_total_bytes = 1337;
rtp_connection_info.sent_total_packets = 3;
rtp_connection_info.sent_discarded_packets = 2;
rtp_connection_info.packets_received = 4;
cricket::TransportChannelStats rtp_transport_channel_stats;
rtp_transport_channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP;
rtp_transport_channel_stats.ice_transport_stats.connection_infos.push_back(
@ -2156,7 +2159,9 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStats) {
rtc::ToString(cricket::ICE_CANDIDATE_COMPONENT_RTP),
report->timestamp_us());
expected_rtp_transport.bytes_sent = 42;
expected_rtp_transport.packets_sent = 1;
expected_rtp_transport.bytes_received = 1337;
expected_rtp_transport.packets_received = 4;
expected_rtp_transport.dtls_state = RTCDtlsTransportState::kNew;
expected_rtp_transport.selected_candidate_pair_changes = 1;
@ -2171,6 +2176,9 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStats) {
rtcp_connection_info.remote_candidate = *rtcp_remote_candidate.get();
rtcp_connection_info.sent_total_bytes = 1337;
rtcp_connection_info.recv_total_bytes = 42;
rtcp_connection_info.sent_total_packets = 3;
rtcp_connection_info.sent_discarded_packets = 2;
rtcp_connection_info.packets_received = 4;
cricket::TransportChannelStats rtcp_transport_channel_stats;
rtcp_transport_channel_stats.component =
cricket::ICE_CANDIDATE_COMPONENT_RTCP;
@ -2188,7 +2196,9 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStats) {
rtc::ToString(cricket::ICE_CANDIDATE_COMPONENT_RTCP),
report->timestamp_us());
expected_rtcp_transport.bytes_sent = 1337;
expected_rtcp_transport.packets_sent = 1;
expected_rtcp_transport.bytes_received = 42;
expected_rtcp_transport.packets_received = 4;
expected_rtcp_transport.dtls_state = RTCDtlsTransportState::kConnecting;
expected_rtcp_transport.selected_candidate_pair_changes = 0;
@ -2282,6 +2292,9 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStatsWithCrypto) {
rtp_connection_info.remote_candidate = *rtp_remote_candidate.get();
rtp_connection_info.sent_total_bytes = 42;
rtp_connection_info.recv_total_bytes = 1337;
rtp_connection_info.sent_total_packets = 3;
rtp_connection_info.sent_discarded_packets = 2;
rtp_connection_info.packets_received = 4;
cricket::TransportChannelStats rtp_transport_channel_stats;
rtp_transport_channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP;
rtp_transport_channel_stats.ice_transport_stats.connection_infos.push_back(
@ -2304,7 +2317,9 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStatsWithCrypto) {
rtc::ToString(cricket::ICE_CANDIDATE_COMPONENT_RTP),
report->timestamp_us());
expected_rtp_transport.bytes_sent = 42;
expected_rtp_transport.packets_sent = 1;
expected_rtp_transport.bytes_received = 1337;
expected_rtp_transport.packets_received = 4;
expected_rtp_transport.dtls_state = RTCDtlsTransportState::kConnected;
expected_rtp_transport.selected_candidate_pair_changes = 1;
// Crypto parameters

View File

@ -1014,7 +1014,9 @@ class RTCStatsReportVerifier {
bool VerifyRTCTransportStats(const RTCTransportStats& transport) {
RTCStatsVerifier verifier(report_, &transport);
verifier.TestMemberIsNonNegative<uint64_t>(transport.bytes_sent);
verifier.TestMemberIsNonNegative<uint64_t>(transport.packets_sent);
verifier.TestMemberIsNonNegative<uint64_t>(transport.bytes_received);
verifier.TestMemberIsNonNegative<uint64_t>(transport.packets_received);
verifier.TestMemberIsOptionalIDReference(transport.rtcp_transport_stats_id,
RTCTransportStats::kType);
verifier.TestMemberIsDefined(transport.dtls_state);

View File

@ -906,7 +906,9 @@ RTCVideoSourceStats::~RTCVideoSourceStats() {}
// clang-format off
WEBRTC_RTCSTATS_IMPL(RTCTransportStats, RTCStats, "transport",
&bytes_sent,
&packets_sent,
&bytes_received,
&packets_received,
&rtcp_transport_stats_id,
&dtls_state,
&selected_candidate_pair_id,
@ -925,7 +927,9 @@ RTCTransportStats::RTCTransportStats(const std::string& id,
RTCTransportStats::RTCTransportStats(std::string&& id, int64_t timestamp_us)
: RTCStats(std::move(id), timestamp_us),
bytes_sent("bytesSent"),
packets_sent("packetsSent"),
bytes_received("bytesReceived"),
packets_received("packetsReceived"),
rtcp_transport_stats_id("rtcpTransportStatsId"),
dtls_state("dtlsState"),
selected_candidate_pair_id("selectedCandidatePairId"),
@ -939,7 +943,9 @@ RTCTransportStats::RTCTransportStats(std::string&& id, int64_t timestamp_us)
RTCTransportStats::RTCTransportStats(const RTCTransportStats& other)
: RTCStats(other.id(), other.timestamp_us()),
bytes_sent(other.bytes_sent),
packets_sent(other.packets_sent),
bytes_received(other.bytes_received),
packets_received(other.packets_received),
rtcp_transport_stats_id(other.rtcp_transport_stats_id),
dtls_state(other.dtls_state),
selected_candidate_pair_id(other.selected_candidate_pair_id),