From 1448f3959ebe541fe9457e70b2aae0e0598e6b04 Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Thu, 26 Apr 2018 17:11:17 -0700 Subject: [PATCH] Add a utility function to dump ConnectionStats --- .../networking/src/udt/ConnectionStats.cpp | 29 +++++++++++++++++++ .../networking/src/udt/ConnectionStats.h | 3 ++ 2 files changed, 32 insertions(+) diff --git a/libraries/networking/src/udt/ConnectionStats.cpp b/libraries/networking/src/udt/ConnectionStats.cpp index e7efe3d5af..46d88e680f 100644 --- a/libraries/networking/src/udt/ConnectionStats.cpp +++ b/libraries/networking/src/udt/ConnectionStats.cpp @@ -9,6 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include #include "ConnectionStats.h" using namespace udt; @@ -112,3 +113,31 @@ void ConnectionStats::recordPacketSendPeriod(int sample) { _currentSample.packetSendPeriod = sample; _total.packetSendPeriod = (int)((_total.packetSendPeriod * EWMA_PREVIOUS_SAMPLES_WEIGHT) + (sample * EWMA_CURRENT_SAMPLE_WEIGHT)); } + +QDebug& operator<<(QDebug&& debug, const udt::ConnectionStats::Stats& stats) { + debug << "Connection stats:\n"; +#define HIFI_LOG_EVENT(x) << " " #x " events: " << stats.events[ConnectionStats::Stats::Event::x] << "\n" + debug + HIFI_LOG_EVENT(SentACK) + HIFI_LOG_EVENT(ReceivedACK) + HIFI_LOG_EVENT(ProcessedACK) + HIFI_LOG_EVENT(SentLightACK) + HIFI_LOG_EVENT(ReceivedLightACK) + HIFI_LOG_EVENT(SentACK2) + HIFI_LOG_EVENT(ReceivedACK2) + HIFI_LOG_EVENT(SentNAK) + HIFI_LOG_EVENT(ReceivedNAK) + HIFI_LOG_EVENT(SentTimeoutNAK) + HIFI_LOG_EVENT(ReceivedTimeoutNAK) + HIFI_LOG_EVENT(Retransmission) + HIFI_LOG_EVENT(Duplicate) + ; +#undef HIFI_LOG_EVENT + + debug << " Sent packets: " << stats.sentPackets; + debug << "\n Received packets: " << stats.receivedPackets; + debug << "\n Sent util bytes: " << stats.sentUtilBytes; + debug << "\n Sent bytes: " << stats.sentBytes; + debug << "\n Received bytes: " << stats.receivedBytes << "\n"; + return debug; +} diff --git a/libraries/networking/src/udt/ConnectionStats.h b/libraries/networking/src/udt/ConnectionStats.h index 84cd6b2486..7ec7b163ee 100644 --- a/libraries/networking/src/udt/ConnectionStats.h +++ b/libraries/networking/src/udt/ConnectionStats.h @@ -101,4 +101,7 @@ private: } +class QDebug; +QDebug& operator<<(QDebug&& debug, const udt::ConnectionStats::Stats& stats); + #endif // hifi_ConnectionStats_h