[poppler] goo/GooTimer.cc goo/GooTimer.h poppler/Gfx.cc

Krzysztof Kowalczyk kjk at kemper.freedesktop.org
Mon Sep 24 19:14:42 PDT 2007


 goo/GooTimer.cc |   69 ++++++++++++++++++++++++++++++++++++++------------------
 goo/GooTimer.h  |   28 +++++++++++++---------
 poppler/Gfx.cc  |   11 +-------
 3 files changed, 66 insertions(+), 42 deletions(-)

New commits:
diff-tree 05fbce5b6657e883ece9054c79576b25271a05a4 (from 6347915085a487da08d39a859f4261fa812dab09)
Author: Krzysztof Kowalczyk <kkowalczyk at gmail.com>
Date:   Mon Sep 24 08:01:11 2007 -0700

    Make GooTimer work for Windows/msvc build.

diff --git a/goo/GooTimer.cc b/goo/GooTimer.cc
index e9ae2e6..0f97480 100644
--- a/goo/GooTimer.cc
+++ b/goo/GooTimer.cc
@@ -9,58 +9,83 @@
 
 #include <config.h>
 
-#ifdef HAVE_GETTIMEOFDAY
-
 #ifdef USE_GCC_PRAGMAS
 #pragma implementation
 #endif
 
-#include <string.h>
 #include "GooTimer.h"
+#include <string.h>
+
+#define USEC_PER_SEC 1000000
 
 //------------------------------------------------------------------------
 // GooTimer
 //------------------------------------------------------------------------
 
-
 GooTimer::GooTimer() {
-  gettimeofday (&start, NULL);
-  active = true;
+  start();
 }
 
+void GooTimer::start() {
+#ifdef HAVE_GETTIMEOFDAY
+  gettimeofday(&start_time, NULL);
+#elif defined(_MSC_VER)
+  QueryPerformanceCounter(&start_time);
+#endif
+  active = true;
+}
 
-void
-GooTimer::stop() {
-  gettimeofday (&end, NULL);
+void GooTimer::stop() {
+#ifdef HAVE_GETTIMEOFDAY
+  gettimeofday(&end_time, NULL);
+#elif defined(_MSC_VER)
+  QueryPerformanceCounter(&end_time);
+#endif
   active = false;
 }
 
-#define USEC_PER_SEC 1000000
-double
-GooTimer::getElapsed ()
+#ifdef HAVE_GETTIMEOFDAY
+double GooTimer::getElapsed()
 {
   double total;
   struct timeval elapsed;
 
   if (active)
-    gettimeofday (&end, NULL);
+    gettimeofday(&end_time, NULL);
 
-  if (start.tv_usec > end.tv_usec)
-    {
-      end.tv_usec += USEC_PER_SEC;
-      end.tv_sec--;
-    }
+  if (start_time.tv_usec > end_time.tv_usec) {
+      end_time.tv_usec += USEC_PER_SEC;
+      end_time.tv_sec--;
+  }
 
-  elapsed.tv_usec = end.tv_usec - start.tv_usec;
-  elapsed.tv_sec = end.tv_sec - start.tv_sec;
+  elapsed.tv_usec = end_time.tv_usec - start_time.tv_usec;
+  elapsed.tv_sec = end_time.tv_sec - start_time.tv_sec;
 
   total = elapsed.tv_sec + ((double) elapsed.tv_usec / 1e6);
   if (total < 0)
-    {
       total = 0;
-    }
 
   return total;
 }
+#elif defined(_MSC_VER)
+double GooTimer::getElapsed()
+{
+  LARGE_INTEGER   freq;
+  double          time_in_secs;
+  QueryPerformanceFrequency(&freq);
+
+  if (active)
+    QueryPerformanceCounter(&end_time);
+
+  time_in_secs = (double)(end_time.QuadPart-start_time.QuadPart)/(double)freq.QuadPart;
+  return time_in_secs * 1000.0;
 
+}
+#else
+double GooTimer::getElapsed()
+{
+#warning "no support for GooTimer"
+  return 0;
+}
 #endif
+
diff --git a/goo/GooTimer.h b/goo/GooTimer.h
index 86bc42f..d5847cb 100644
--- a/goo/GooTimer.h
+++ b/goo/GooTimer.h
@@ -1,13 +1,11 @@
 //========================================================================
 //
-// GooList.h
+// GooTimer.h
 //
 // Copyright 2001-2003 Glyph & Cog, LLC
 //
 //========================================================================
 
-#ifdef HAVE_GETTIMEOFDAY
-
 #ifndef GOOTIMER_H
 #define GOOTIMER_H
 
@@ -16,7 +14,13 @@
 #endif
 
 #include "gtypes.h"
+#ifdef HAVE_GETTIMEOFDAY
 #include <sys/time.h>
+#endif
+
+#ifdef _MSC_VER
+#include <windows.h>
+#endif
 
 //------------------------------------------------------------------------
 // GooList
@@ -28,17 +32,19 @@ public:
   // Create a new timer.
   GooTimer();
 
-  void stop ();
+  void start();
+  void stop();
   double getElapsed();
 
-
 private:
-
-	struct timeval start;
-	struct timeval end;
-	GBool active;
-};
-
+#ifdef HAVE_GETTIMEOFDAY
+  struct timeval start_time;
+  struct timeval end_time;
+#elif defined(_MSC_VER)
+  LARGE_INTEGER start_time;
+  LARGE_INTEGER end_time;
 #endif
+  GBool active;
+};
 
 #endif
diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc
index 63b7732..b86ab10 100644
--- a/poppler/Gfx.cc
+++ b/poppler/Gfx.cc
@@ -582,16 +582,11 @@ void Gfx::go(GBool topLevel) {
 	printf("\n");
 	fflush(stdout);
       }
-#ifdef HAVE_GETTIMEOFDAY
-      GooTimer *timer = NULL;
-      if (profileCommands) 
-	timer = new GooTimer ();
-#endif
+      GooTimer timer;
 
       // Run the operation
       execOp(&obj, args, numArgs);
 
-#ifdef HAVE_GETTIMEOFDAY
       // Update the profile information
       if (profileCommands) {
 	GooHash *hash;
@@ -608,11 +603,9 @@ void Gfx::go(GBool topLevel) {
 	    hash->add (cmd_g, data_p);
 	  }
 	  
-	  data_p->addElement (timer->getElapsed ());
+	  data_p->addElement(timer.getElapsed ());
 	}
-        delete timer;
       }
-#endif
       obj.free();
       for (i = 0; i < numArgs; ++i)
 	args[i].free();


More information about the poppler mailing list