diff --git a/libraries/networking/src/udt/Connection.cpp b/libraries/networking/src/udt/Connection.cpp index e141e680c2..5afd3772a0 100644 --- a/libraries/networking/src/udt/Connection.cpp +++ b/libraries/networking/src/udt/Connection.cpp @@ -192,6 +192,9 @@ void Connection::sendACK2(SequenceNumber currentACKSubSequenceNumber) { // write the sub sequence number for this ACK2 ack2Packet->writePrimitive(currentACKSubSequenceNumber); + // send the ACK2 packet + _parentSocket->writeBasePacket(*ack2Packet, _destination); + // update the last sent ACK2 and the last ACK2 send time _lastSentACK2 = currentACKSubSequenceNumber; diff --git a/libraries/networking/src/udt/Socket.cpp b/libraries/networking/src/udt/Socket.cpp index 6bb7bf08d0..25335c99df 100644 --- a/libraries/networking/src/udt/Socket.cpp +++ b/libraries/networking/src/udt/Socket.cpp @@ -215,19 +215,15 @@ void Socket::setCongestionControlFactory(std::unique_ptrsynInterval(); } -void Socket::sampleAndPrintConnectionStats() { - if (thread() != QThread::currentThread()) { - QMetaObject::invokeMethod(this, "sampleAndPrintConnectionStats"); - return; - } +ConnectionStats::Stats Socket::sampleStatsForConnection(const HifiSockAddr& destination) { + Q_ASSERT_X(thread() == QThread::currentThread(), + "Socket::sampleStatsForConnection", + "Stats sampling for connection must be on socket thread"); - for(auto& connection : _connectionsHash) { - ConnectionStats::Stats sampleStats = connection.second->sampleStats(); - - qDebug() << connection.first - << sampleStats.receiveRate << sampleStats.rtt - << sampleStats.congestionWindowSize << sampleStats.packetSendPeriod - << sampleStats.sentPackets - << sampleStats.receivedACKs << sampleStats.receivedLightACKs << sampleStats.receivedNAKs; + auto it = _connectionsHash.find(destination); + if (it != _connectionsHash.end()) { + return it->second->sampleStats(); + } else { + return ConnectionStats::Stats(); } } diff --git a/libraries/networking/src/udt/Socket.h b/libraries/networking/src/udt/Socket.h index 6b798d64d2..0fee52e755 100644 --- a/libraries/networking/src/udt/Socket.h +++ b/libraries/networking/src/udt/Socket.h @@ -64,7 +64,7 @@ public: void connectToSendSignal(const HifiSockAddr& destinationAddr, QObject* receiver, const char* slot); - void sampleAndPrintConnectionStats(); + ConnectionStats::Stats sampleStatsForConnection(const HifiSockAddr& destination); private slots: void readPendingDatagrams(); diff --git a/tools/udt-test/src/UDTTest.cpp b/tools/udt-test/src/UDTTest.cpp index 55a8a78f6f..067a7ec746 100644 --- a/tools/udt-test/src/UDTTest.cpp +++ b/tools/udt-test/src/UDTTest.cpp @@ -41,6 +41,10 @@ const QCommandLineOption UNRELIABLE_PACKETS { "unreliable", "send unreliable packets (default is reliable)" }; +const QStringList STATS_TABLE_HEADERS { + "Send Rate (P/s)", "RTT(ms)", "CW (P)", "Send Period (us)", "Received ACK", "Received NAK", "Sent ACK2" +}; + UDTTest::UDTTest(int& argc, char** argv) : QCoreApplication(argc, argv) { @@ -123,6 +127,9 @@ UDTTest::UDTTest(int& argc, char** argv) : QTimer* statsTimer = new QTimer(this); connect(statsTimer, &QTimer::timeout, this, &UDTTest::sampleStats); statsTimer->start(STATS_SAMPLE_INTERVAL); + + // output the headers for stats for our table + qDebug() << qPrintable(STATS_TABLE_HEADERS.join(" | ")); } } @@ -207,5 +214,21 @@ void UDTTest::sendPacket() { } void UDTTest::sampleStats() { - _socket.sampleAndPrintConnectionStats(); + udt::ConnectionStats::Stats stats = _socket.sampleStatsForConnection(_target); + + int headerIndex = -1; + + // setup a list of left justified values + QStringList values { + QString::number(stats.receiveRate).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), + QString::number(stats.rtt).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.receivedNAKs).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), + QString::number(stats.sentACK2s).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()) + }; + + // output this line of values + qDebug() << qPrintable(values.join(" | ")); }