Enhance the error message of QUIC_BUG in QUIC BandwidthSampler. PiperOrigin-RevId: 342096451 Change-Id: Id51f6bf374348a5289d708cf88fe2527d4dca619
diff --git a/quic/core/congestion_control/bandwidth_sampler.cc b/quic/core/congestion_control/bandwidth_sampler.cc index 6eacef3..ee6d6c1 100644 --- a/quic/core/congestion_control/bandwidth_sampler.cc +++ b/quic/core/congestion_control/bandwidth_sampler.cc
@@ -174,9 +174,12 @@ << max_tracked_packets_ << "). First tracked: " << connection_state_map_.first_packet() << "; last tracked: " << connection_state_map_.last_packet() - << "; least unacked: " << unacked_packet_map_->GetLeastUnacked() - << "; packet number: " << packet_number << "; largest observed: " - << unacked_packet_map_->largest_acked(); + << "; entry_slots_used: " + << connection_state_map_.entry_slots_used() + << "; number_of_present_entries: " + << connection_state_map_.number_of_present_entries() + << "; packet number: " << packet_number + << "; unacked_map: " << unacked_packet_map_->DebugString(); } else { QUIC_BUG << "BandwidthSampler in-flight packet map has exceeded maximum " "number of tracked packets.";
diff --git a/quic/core/quic_unacked_packet_map.h b/quic/core/quic_unacked_packet_map.h index 4541351..2e5a64e 100644 --- a/quic/core/quic_unacked_packet_map.h +++ b/quic/core/quic_unacked_packet_map.h
@@ -15,6 +15,7 @@ #include "net/third_party/quiche/src/quic/core/session_notifier_interface.h" #include "net/third_party/quiche/src/quic/platform/api/quic_export.h" #include "net/third_party/quiche/src/quic/platform/api/quic_flags.h" +#include "net/third_party/quiche/src/common/platform/api/quiche_str_cat.h" namespace quic { @@ -318,6 +319,16 @@ } } + std::string DebugString() const { + return quiche::QuicheStringPrintf( + "{size: %zu, least_unacked: %s, largest_sent_packet: %s, " + "largest_acked: %s, bytes_in_flight: %zu, packets_in_flight: %zu}", + unacked_packets_size(), least_unacked_.ToString().c_str(), + largest_sent_packet_.ToString().c_str(), + largest_acked_.ToString().c_str(), bytes_in_flight_, + packets_in_flight_); + } + private: friend class test::QuicUnackedPacketMapPeer;
diff --git a/quic/core/quic_unacked_packet_map_test.cc b/quic/core/quic_unacked_packet_map_test.cc index 0282108..4b598be 100644 --- a/quic/core/quic_unacked_packet_map_test.cc +++ b/quic/core/quic_unacked_packet_map_test.cc
@@ -669,6 +669,32 @@ ASSERT_EQ(QuicUnackedPacketMapPeer::GetCapacity(unacked_packets), 16u); } +TEST_P(QuicUnackedPacketMapTest, DebugString) { + EXPECT_EQ(unacked_packets_.DebugString(), + "{size: 0, least_unacked: 1, largest_sent_packet: uninitialized, " + "largest_acked: uninitialized, bytes_in_flight: 0, " + "packets_in_flight: 0}"); + + SerializedPacket packet1(CreateRetransmittablePacket(1)); + unacked_packets_.AddSentPacket(&packet1, NOT_RETRANSMISSION, now_, true, + true); + EXPECT_EQ( + unacked_packets_.DebugString(), + "{size: 1, least_unacked: 1, largest_sent_packet: 1, largest_acked: " + "uninitialized, bytes_in_flight: 1000, packets_in_flight: 1}"); + + SerializedPacket packet2(CreateRetransmittablePacket(2)); + unacked_packets_.AddSentPacket(&packet2, NOT_RETRANSMISSION, now_, true, + true); + unacked_packets_.RemoveFromInFlight(QuicPacketNumber(1)); + unacked_packets_.IncreaseLargestAcked(QuicPacketNumber(1)); + unacked_packets_.RemoveObsoletePackets(); + EXPECT_EQ( + unacked_packets_.DebugString(), + "{size: 1, least_unacked: 2, largest_sent_packet: 2, largest_acked: 1, " + "bytes_in_flight: 1000, packets_in_flight: 1}"); +} + } // namespace } // namespace test } // namespace quic