]> source.dussan.org Git - tigervnc.git/commitdiff
Add crude congestion window debug trace 442/head
authorPierre Ossman <ossman@cendio.se>
Fri, 11 Mar 2016 08:38:08 +0000 (09:38 +0100)
committerPierre Ossman <ossman@cendio.se>
Fri, 17 Nov 2017 13:40:47 +0000 (14:40 +0100)
Allows us to compare our computed congestion window with the
underlying one used by the TCP layer.

common/rfb/Congestion.cxx
common/rfb/Congestion.h
common/rfb/VNCSConnectionST.cxx

index c7d6f710cb9e628a7eed1e98a43ca681ba9157b5..a2f7a256c622582831deae28e12cb5039ba42df3 100644 (file)
 #include <assert.h>
 #include <sys/time.h>
 
+#ifdef __linux__
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <linux/sockios.h>
+#endif
+
 #include <rfb/Congestion.h>
 #include <rfb/LogWriter.h>
 #include <rfb/util.h>
@@ -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;
index 5feea65ec121798068e1b0a19f0ff998d2ffd31d..fd57c22e55f23594cc3a4318241d8aa1e86ab652 100644 (file)
@@ -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();
index b2ceb7d29361fcbb8a02b5771fb930e6d7bcfca3..5b9152c2183a8d44e5f86fbbf82d2056d05de4d9 100644 (file)
@@ -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;