From 8cf7163ec07e9d97fe48d6dc4a29d6dc338eef9d Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Fri, 11 Mar 2016 09:38:08 +0100 Subject: [PATCH] Add crude congestion window debug trace Allows us to compare our computed congestion window with the underlying one used by the TCP layer. --- common/rfb/Congestion.cxx | 38 +++++++++++++++++++++++++++++++++ common/rfb/Congestion.h | 5 +++++ common/rfb/VNCSConnectionST.cxx | 1 + 3 files changed, 44 insertions(+) diff --git a/common/rfb/Congestion.cxx b/common/rfb/Congestion.cxx index c7d6f710..a2f7a256 100644 --- a/common/rfb/Congestion.cxx +++ b/common/rfb/Congestion.cxx @@ -36,6 +36,14 @@ #include #include +#ifdef __linux__ +#include +#include +#include +#include +#include +#endif + #include #include #include @@ -43,6 +51,9 @@ // Debug output on what the congestion control is up to #undef CONGESTION_DEBUG +// Dump socket congestion window debug trace to disk +#undef CONGESTION_TRACE + using namespace rfb; // This window should get us going fairly fast on a decent bandwidth network. @@ -273,6 +284,33 @@ int Congestion::getUncongestedETA() } } +void Congestion::debugTrace(const char* filename, int fd) +{ +#ifdef CONGESTION_TRACE +#ifdef __linux__ + FILE *f; + f = fopen(filename, "ab"); + if (f != NULL) { + struct tcp_info info; + int buffered; + socklen_t len; + len = sizeof(info); + if ((getsockopt(fd, IPPROTO_TCP, + TCP_INFO, &info, &len) == 0) && + (ioctl(fd, SIOCOUTQ, &buffered) == 0)) { + struct timeval now; + gettimeofday(&now, NULL); + fprintf(f, "%u.%06u,%u,%u,%u,%u\n", + (unsigned)now.tv_sec, (unsigned)now.tv_usec, + congWindow, info.tcpi_snd_cwnd * info.tcpi_snd_mss, + getInFlight(), buffered); + } + fclose(f); + } +#endif +#endif +} + unsigned Congestion::getExtraBuffer() { unsigned elapsed; diff --git a/common/rfb/Congestion.h b/common/rfb/Congestion.h index 5feea65e..fd57c22e 100644 --- a/common/rfb/Congestion.h +++ b/common/rfb/Congestion.h @@ -47,6 +47,11 @@ namespace rfb { // longer be congested. int getUncongestedETA(); + // debugTrace() writes the current congestion window, as well as the + // congestion window of the underlying TCP layer, to the specified + // file + void debugTrace(const char* filename, int fd); + protected: unsigned getExtraBuffer(); unsigned getInFlight(); diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx index b2ceb7d2..5b9152c2 100644 --- a/common/rfb/VNCSConnectionST.cxx +++ b/common/rfb/VNCSConnectionST.cxx @@ -764,6 +764,7 @@ bool VNCSConnectionST::isCongested() // Stuff still waiting in the send buffer? sock->outStream().flush(); + congestion.debugTrace("congestion-trace.csv", sock->getFd()); if (sock->outStream().bufferUsage() > 0) return true; -- 2.39.5