Skip to content

Commit

Permalink
Reland "Implement packets_(sent | received) for RTCTransportStats"
Browse files Browse the repository at this point in the history
This is a reland of fb6f975. Related
issue in chromium is fixed here:
https://chromium-review.googlesource.com/c/chromium/src/+/2287294

Original change's description:
> 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 <[email protected]>
> Reviewed-by: Henrik Boström <[email protected]>
> Commit-Queue: Artem Titov <[email protected]>
> Cr-Commit-Position: refs/heads/master@{#31643}

Bug: webrtc:11756
Change-Id: I1e310e3d23248500eb7dabd23d0ce6c4ec4cb8c6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178871
Reviewed-by: Henrik Boström <[email protected]>
Reviewed-by: Tommi <[email protected]>
Commit-Queue: Artem Titov <[email protected]>
Cr-Commit-Position: refs/heads/master@{#31700}
  • Loading branch information
titov-artem authored and Commit Bot committed Jul 10, 2020
1 parent 76ad2e0 commit edacbd5
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/stats/rtcstats_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,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;
Expand Down
1 change: 1 addition & 0 deletions p2p/base/connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions p2p/base/connection_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions p2p/base/connection_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions p2p/base/p2p_transport_channel_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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();
}

Expand Down
5 changes: 5 additions & 0 deletions pc/rtc_stats_collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1812,15 +1812,20 @@ 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 =
channel_stats.ice_transport_stats.selected_candidate_pair_changes;
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);
Expand Down
15 changes: 15 additions & 0 deletions pc/rtc_stats_collector_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2171,6 +2171,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(
Expand All @@ -2188,7 +2191,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;

Expand All @@ -2203,6 +2208,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;
Expand All @@ -2220,7 +2228,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;

Expand Down Expand Up @@ -2314,6 +2324,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(
Expand All @@ -2336,7 +2349,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
Expand Down
2 changes: 2 additions & 0 deletions pc/rtc_stats_integrationtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,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);
Expand Down
6 changes: 6 additions & 0 deletions stats/rtcstats_objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,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,
Expand All @@ -977,7 +979,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"),
Expand All @@ -991,7 +995,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),
Expand Down

0 comments on commit edacbd5

Please sign in to comment.