]> source.dussan.org Git - tigervnc.git/commitdiff
Improvements in the debugging code for measuring performance.
authorConstantin Kaplinsky <const@tightvnc.com>
Wed, 15 Feb 2006 16:14:07 +0000 (16:14 +0000)
committerConstantin Kaplinsky <const@tightvnc.com>
Wed, 15 Feb 2006 16:14:07 +0000 (16:14 +0000)
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@488 3789f03b-4d11-0410-bbf8-ca57d06f2519

x0vncserver/PollingManager.cxx
x0vncserver/PollingManager.h
x0vncserver/x0vncserver.cxx

index 0c972dd348cc1254a443f55af23f8763fbcaae55..f131e7e8c88815b9bdc2758547867ff7819deee9 100644 (file)
@@ -26,7 +26,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <time.h>
-#include <sys/time.h>
 #include <X11/Xlib.h>
 #include <rfb/VNCServer.h>
 #include <rfb/Configuration.h>
@@ -96,6 +95,10 @@ PollingManager::PollingManager(Display *dpy, Image *image,
   memset(m_rateMatrix, 0, numTiles);
   memset(m_videoFlags, 0, numTiles);
   memset(m_changedFlags, 0, numTiles);
+
+#ifdef DEBUG
+  memset(&m_timeSaved, 0, sizeof(m_timeSaved));
+#endif
 }
 
 PollingManager::~PollingManager()
@@ -142,33 +145,45 @@ void PollingManager::unsetPointerPos()
 }
 
 //
-// DEBUG: a version of poll() measuring time spent in the function.
+// DEBUG: Measuring time spent in the poll() function,
+//        as well as time intervals between poll() calls.
 //
 
-void PollingManager::pollDebug()
+#ifdef DEBUG
+void PollingManager::debugBeforePoll()
 {
-  struct timeval timeSaved, timeNow;
+  struct timeval timeNow;
   struct timezone tz;
-  timeSaved.tv_sec = 0;
-  timeSaved.tv_usec = 0;
-  gettimeofday(&timeSaved, &tz);
-  int step = m_pollingStep;
-
-  poll();
+  gettimeofday(&timeNow, &tz);
+  int diff = (int)((timeNow.tv_usec - m_timeSaved.tv_usec + 500) / 1000 +
+                   (timeNow.tv_sec - m_timeSaved.tv_sec) * 1000);
+  fprintf(stderr, "[wait%4dms]\t[step %2d]\t", diff, m_pollingStep % 32);
+  m_timeSaved = timeNow;
+}
 
+void PollingManager::debugAfterPoll()
+{
+  struct timeval timeNow;
+  struct timezone tz;
   gettimeofday(&timeNow, &tz);
-  int diff = (int)((timeNow.tv_usec - timeSaved.tv_usec + 500) / 1000 +
-                   (timeNow.tv_sec - timeSaved.tv_sec) * 1000);
-  if (diff != 0)
-    fprintf(stderr, "DEBUG: poll(): %4d ms [step %2d]\n", diff, step % 32);
+  int diff = (int)((timeNow.tv_usec - m_timeSaved.tv_usec + 500) / 1000 +
+                   (timeNow.tv_sec - m_timeSaved.tv_sec) * 1000);
+  fprintf(stderr, "[poll%4dms]\n", diff);
+  m_timeSaved = timeNow;
 }
 
+#endif
+
 //
 // Search for changed rectangles on the screen.
 //
 
 void PollingManager::poll()
 {
+#ifdef DEBUG
+  debugBeforePoll();
+#endif
+
   // First step: full-screen polling.
 
   bool changes1 = false;
@@ -206,6 +221,10 @@ void PollingManager::poll()
 
   if (changes1 || changes2)
     m_server->tryUpdate();
+
+#ifdef DEBUG
+  debugAfterPoll();
+#endif
 }
 
 bool PollingManager::poll_DetectVideo()
index 04cc767d6f0974a0389ba1b8aa9f85c80baa6102..a56d2e40016b7e36c2875f2f0bc759c8cd7b6a8d 100644 (file)
@@ -23,6 +23,8 @@
 #ifndef __POLLINGMANAGER_H__
 #define __POLLINGMANAGER_H__
 
+#include <sys/time.h>
+
 #include <X11/Xlib.h>
 #include <rfb/VNCServer.h>
 
@@ -42,7 +44,6 @@ public:
   void setPointerPos(const Point &pos);
   void unsetPointerPos();
 
-  void pollDebug();
   void poll();
 
   // Configurable parameters.
@@ -96,6 +97,15 @@ private:
   unsigned int m_pollingStep;
   static const int m_pollingOrder[];
 
+#ifdef DEBUG
+private:
+
+  void debugBeforePoll();
+  void debugAfterPoll();
+
+  struct timeval m_timeSaved;
+#endif
+
 };
 
 #endif // __POLLINGMANAGER_H__
index 1ea2e8171a728b811fdba2c4185079b75f63deb8..e69fa938357219344aaa680e92ccb76ced3bf186 100644 (file)
@@ -443,16 +443,19 @@ int main(int argc, char** argv)
           int coeff = cpumon.check();
           if (coeff < 90 || coeff > 110) {
             // Adjust polling cycle to satisfy MaxProcessorUsage setting
+#ifdef DEBUG
+            int oldPollingCycle = dynPollingCycle;
+#endif
             dynPollingCycle = (dynPollingCycle * 100 + coeff/2) / coeff;
             if (dynPollingCycle < (int)pollingCycle) {
               dynPollingCycle = (int)pollingCycle;
             } else if (dynPollingCycle > (int)pollingCycle * 32) {
               dynPollingCycle = (int)pollingCycle * 32;
             }
-            // DEBUG:
-            // if (dynPollingCycle != old) {
-            //   fprintf(stderr, "[%dms]\t", dynPollingCycle);
-            // }
+#ifdef DEBUG
+            if (dynPollingCycle != oldPollingCycle)
+              fprintf(stderr, "\t[new cycle %dms]\n", dynPollingCycle);
+#endif
           }
           desktop.poll();
         }