diff --git a/libraries/networking/src/udt/Connection.cpp b/libraries/networking/src/udt/Connection.cpp index 41bdb36c98..1786f7558e 100644 --- a/libraries/networking/src/udt/Connection.cpp +++ b/libraries/networking/src/udt/Connection.cpp @@ -95,7 +95,7 @@ void Connection::recordSentPackets(int dataSize, int payloadSize) { } void Connection::recordRetransmission() { - _stats.recordRetransmission(); + _stats.record(ConnectionStats::Stats::Retransmission); } void Connection::sendACK(bool wasCausedBySyncTimeout) { @@ -175,7 +175,7 @@ void Connection::sendACK(bool wasCausedBySyncTimeout) { // reset the number of data packets received since last ACK _packetsSinceACK = 0; - _stats.recordSentACK(); + _stats.record(ConnectionStats::Stats::SentACK); } void Connection::sendLightACK() { @@ -199,7 +199,7 @@ void Connection::sendLightACK() { // have the socket send off our packet immediately _parentSocket->writeBasePacket(*lightACKPacket, _destination); - _stats.recordSentLightACK(); + _stats.record(ConnectionStats::Stats::SentLightACK); } void Connection::sendACK2(SequenceNumber currentACKSubSequenceNumber) { @@ -219,7 +219,7 @@ void Connection::sendACK2(SequenceNumber currentACKSubSequenceNumber) { // update the last sent ACK2 and the last ACK2 send time _lastSentACK2 = currentACKSubSequenceNumber; - _stats.recordSentACK2(); + _stats.record(ConnectionStats::Stats::SentACK2); } void Connection::sendNAK(SequenceNumber sequenceNumberRecieved) { @@ -240,7 +240,7 @@ void Connection::sendNAK(SequenceNumber sequenceNumberRecieved) { // record our last NAK time _lastNAKTime = high_resolution_clock::now(); - _stats.recordSentNAK(); + _stats.record(ConnectionStats::Stats::SentNAK); } void Connection::sendTimeoutNAK() { @@ -257,7 +257,7 @@ void Connection::sendTimeoutNAK() { // record this as the last NAK time _lastNAKTime = high_resolution_clock::now(); - _stats.recordSentTimeoutNAK(); + _stats.record(ConnectionStats::Stats::SentTimeoutNAK); } } @@ -332,7 +332,7 @@ bool Connection::processReceivedSequenceNumber(SequenceNumber sequenceNumber, in } if (wasDuplicate) { - _stats.recordDuplicates(); + _stats.record(ConnectionStats::Stats::Duplicate); } else { _stats.recordReceivedPackets(payloadSize, packetSize); } @@ -386,6 +386,9 @@ void Connection::processACK(std::unique_ptr controlPacket) { SequenceNumber ack; controlPacket->readPrimitive(&ack); + // update the total count of received ACKs + _stats.record(ConnectionStats::Stats::ReceivedACK); + // validate that this isn't a BS ACK if (ack > getSendQueue().getCurrentSequenceNumber()) { // in UDT they specifically break the connection here - do we want to do anything? @@ -449,8 +452,7 @@ void Connection::processACK(std::unique_ptr controlPacket) { _congestionControl->onACK(ack); }); - // update the total count of received ACKs - _stats.recordReceivedACK(); + _stats.record(ConnectionStats::Stats::ProcessedACK); } void Connection::processLightACK(std::unique_ptr controlPacket) { @@ -470,7 +472,7 @@ void Connection::processLightACK(std::unique_ptr controlPacket) { getSendQueue().ack(ack); } - _stats.recordReceivedLightACK(); + _stats.record(ConnectionStats::Stats::ReceivedLightACK); } void Connection::processACK2(std::unique_ptr controlPacket) { @@ -508,7 +510,7 @@ void Connection::processACK2(std::unique_ptr controlPacket) { // erase this sub-sequence number and anything below it now that we've gotten our timing information _sentACKs.erase(_sentACKs.begin(), it); - _stats.recordReceivedACK2(); + _stats.record(ConnectionStats::Stats::ReceivedACK2); } void Connection::processNAK(std::unique_ptr controlPacket) { @@ -530,7 +532,7 @@ void Connection::processNAK(std::unique_ptr controlPacket) { _congestionControl->onLoss(start, end); }); - _stats.recordReceivedNAK(); + _stats.record(ConnectionStats::Stats::ReceivedNAK); } void Connection::processTimeoutNAK(std::unique_ptr controlPacket) { @@ -540,7 +542,7 @@ void Connection::processTimeoutNAK(std::unique_ptr controlPacket) // we don't tell the congestion control object there was loss here - this matches UDTs implementation // a possible improvement would be to tell it which new loss this timeout packet told us about - _stats.recordReceivedTimeoutNAK(); + _stats.record(ConnectionStats::Stats::ReceivedTimeoutNAK); } void Connection::updateRTT(int rtt) { diff --git a/libraries/networking/src/udt/ConnectionStats.cpp b/libraries/networking/src/udt/ConnectionStats.cpp index 26112eb24f..91eeb6d49c 100644 --- a/libraries/networking/src/udt/ConnectionStats.cpp +++ b/libraries/networking/src/udt/ConnectionStats.cpp @@ -31,57 +31,11 @@ ConnectionStats::Stats ConnectionStats::sample() { return sample; } -void ConnectionStats::recordSentACK() { - ++_currentSample.sentACKs; - ++_total.sentACKs; +void ConnectionStats::record(Stats::Event event) { + ++_currentSample.events[(int) event]; + ++_total.events[(int) event]; } -void ConnectionStats::recordReceivedACK() { - ++_currentSample.receivedACKs; - ++_total.receivedACKs; -} - -void ConnectionStats::recordSentLightACK() { - ++_currentSample.sentLightACKs; - ++_total.sentLightACKs; -} - -void ConnectionStats::recordReceivedLightACK() { - ++_currentSample.receivedLightACKs; - ++_total.receivedLightACKs; -} - -void ConnectionStats::recordSentACK2() { - ++_currentSample.sentACK2s; - ++_total.sentACK2s; -} - -void ConnectionStats::recordReceivedACK2() { - ++_currentSample.receivedACK2s; - ++_total.receivedACK2s; -} - -void ConnectionStats::recordSentNAK() { - ++_currentSample.sentNAKs; - ++_total.sentNAKs; -} - -void ConnectionStats::recordReceivedNAK() { - ++_currentSample.receivedNAKs; - ++_total.receivedNAKs; -} - -void ConnectionStats::recordSentTimeoutNAK() { - ++_currentSample.sentTimeoutNAKs; - ++_total.sentTimeoutNAKs; -} - -void ConnectionStats::recordReceivedTimeoutNAK() { - ++_currentSample.receivedTimeoutNAKs; - ++_total.receivedTimeoutNAKs; -} - - void ConnectionStats::recordSentPackets(int payload, int total) { ++_currentSample.sentPackets; ++_total.sentPackets; @@ -126,16 +80,6 @@ void ConnectionStats::recordUnreliableReceivedPackets(int payload, int total) { _total.recievedUnreliableBytes += total; } -void ConnectionStats::recordRetransmission() { - ++_currentSample.retransmissions; - ++_total.retransmissions; -} - -void ConnectionStats::recordDuplicates() { - ++_currentSample.duplicates; - ++_total.duplicates; -} - static const double EWMA_CURRENT_SAMPLE_WEIGHT = 0.125; static const double EWMA_PREVIOUS_SAMPLES_WEIGHT = 1 - 0.125; diff --git a/libraries/networking/src/udt/ConnectionStats.h b/libraries/networking/src/udt/ConnectionStats.h index 27d8bbd7a1..2800db7720 100644 --- a/libraries/networking/src/udt/ConnectionStats.h +++ b/libraries/networking/src/udt/ConnectionStats.h @@ -13,6 +13,7 @@ #define hifi_ConnectionStats_h #include +#include namespace udt { @@ -22,18 +23,26 @@ public: std::chrono::microseconds startTime; std::chrono::microseconds endTime; - // Control Packet stat collection - int sentACKs { 0 }; - int receivedACKs { 0 }; - int sentLightACKs { 0 }; - int receivedLightACKs { 0 }; - int sentACK2s { 0 }; - int receivedACK2s { 0 }; - int sentNAKs { 0 }; - int receivedNAKs { 0 }; - int sentTimeoutNAKs { 0 }; - int receivedTimeoutNAKs { 0 }; + enum Event { + SentACK, + ReceivedACK, + ProcessedACK, + SentLightACK, + ReceivedLightACK, + SentACK2, + ReceivedACK2, + SentNAK, + ReceivedNAK, + SentTimeoutNAK, + ReceivedTimeoutNAK, + Retransmission, + Duplicate + }; + // construct a vector for the events of the size of our Enum - default value is zero + std::vector events = std::vector((int) Event::Duplicate + 1, 0); + + // packet counts and sizes int sentPackets { 0 }; int recievedPackets { 0 }; int sentUtilBytes { 0 }; @@ -47,9 +56,6 @@ public: int recievedUnreliableUtilBytes { 0 }; int sentUnreliableBytes { 0 }; int recievedUnreliableBytes { 0 }; - - int retransmissions { 0 }; - int duplicates { 0 }; // the following stats are trailing averages in the result, not totals int sendRate { 0 }; @@ -65,16 +71,7 @@ public: Stats sample(); Stats getTotalStats(); - void recordSentACK(); - void recordReceivedACK(); - void recordSentLightACK(); - void recordReceivedLightACK(); - void recordSentACK2(); - void recordReceivedACK2(); - void recordSentNAK(); - void recordReceivedNAK(); - void recordSentTimeoutNAK(); - void recordReceivedTimeoutNAK(); + void record(Stats::Event event); void recordSentPackets(int payload, int total); void recordReceivedPackets(int payload, int total); @@ -82,9 +79,6 @@ public: void recordUnreliableSentPackets(int payload, int total); void recordUnreliableReceivedPackets(int payload, int total); - void recordRetransmission(); - void recordDuplicates(); - void recordSendRate(int sample); void recordReceiveRate(int sample); void recordEstimatedBandwidth(int sample); diff --git a/tools/udt-test/src/UDTTest.cpp b/tools/udt-test/src/UDTTest.cpp index babf4b8c25..340c6a16a4 100644 --- a/tools/udt-test/src/UDTTest.cpp +++ b/tools/udt-test/src/UDTTest.cpp @@ -43,7 +43,7 @@ const QCommandLineOption UNRELIABLE_PACKETS { const QStringList STATS_TABLE_HEADERS { "Send Rate (P/s)", "RTT(ms)", "CW (P)", "Send Period (us)", - "Received ACK", "Received LACK", "Received NAK", "Received TNAK", + "Received ACK", "Processed ACK", "Received LACK", "Received NAK", "Received TNAK", "Sent ACK2", "Re-sent Packets" }; @@ -228,12 +228,13 @@ void UDTTest::sampleStats() { QString::number(stats.rtt / USECS_PER_MSEC).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), QString::number(stats.congestionWindowSize).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), QString::number(stats.packetSendPeriod).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), - QString::number(stats.receivedACKs).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), - QString::number(stats.receivedLightACKs).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), - QString::number(stats.receivedNAKs).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), - QString::number(stats.receivedTimeoutNAKs).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), - QString::number(stats.sentACK2s).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), - QString::number(stats.retransmissions).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()) + QString::number(stats.events[udt::ConnectionStats::Stats::ReceivedACK]).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), + QString::number(stats.events[udt::ConnectionStats::Stats::ProcessedACK]).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), + QString::number(stats.events[udt::ConnectionStats::Stats::ReceivedLightACK]).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), + QString::number(stats.events[udt::ConnectionStats::Stats::ReceivedNAK]).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), + QString::number(stats.events[udt::ConnectionStats::Stats::ReceivedTimeoutNAK]).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), + QString::number(stats.events[udt::ConnectionStats::Stats::SentACK2]).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), + QString::number(stats.events[udt::ConnectionStats::Stats::Retransmission]).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()) }; // output this line of values