You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by sh...@apache.org on 2011/05/08 00:03:43 UTC

svn commit: r1100638 - /qpid/trunk/qpid/cpp/src/qpid/sys/windows/Time.cpp

Author: shuston
Date: Sat May  7 22:03:42 2011
New Revision: 1100638

URL: http://svn.apache.org/viewvc?rev=1100638&view=rev
Log:
Added Windows high-res timer output. Resolves QPID-3236

Modified:
    qpid/trunk/qpid/cpp/src/qpid/sys/windows/Time.cpp

Modified: qpid/trunk/qpid/cpp/src/qpid/sys/windows/Time.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/windows/Time.cpp?rev=1100638&r1=1100637&r2=1100638&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/windows/Time.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/windows/Time.cpp Sat May  7 22:03:42 2011
@@ -27,6 +27,17 @@
 
 using namespace boost::posix_time;
 
+namespace {
+
+// High-res timing support. This will display times since program start,
+// more or less. Keep track of the start value and the conversion factor to
+// seconds.
+bool timeInitialized = false;
+LARGE_INTEGER start;
+double freq = 1.0;
+
+}
+
 namespace qpid {
 namespace sys {
 
@@ -99,11 +110,23 @@ void outputFormattedNow(std::ostream& o)
 }
 
 void outputHiresNow(std::ostream& o) {
-// TODO: This is a stub - replace with windows code that will do the equivalent
-// of the Linux code commented out below.  (kpvdr)
-//    ::timespec time;
-//    ::clock_gettime(CLOCK_REALTIME, &time);
-//    o << time.tv_sec << "." << std::setw(9) << std::setfill('0') << time.tv_nsec << "s ";
-    o << "XXXXXXXXX.XXXXXXXXXs ";
+    if (!timeInitialized) {
+        start.QuadPart = 0;
+        LARGE_INTEGER iFreq;
+        iFreq.QuadPart = 1;
+        QueryPerformanceCounter(&start);
+        QueryPerformanceFrequency(&iFreq);
+        freq = static_cast<double>(iFreq.QuadPart);
+        timeInitialized = true;
+    }
+    LARGE_INTEGER iNow;
+    iNow.QuadPart = 0;
+    QueryPerformanceCounter(&iNow);
+    iNow.QuadPart -= start.QuadPart;
+    if (iNow.QuadPart < 0)
+        iNow.QuadPart = 0;
+    double now = static_cast<double>(iNow.QuadPart);
+    now /= freq;                 // now is seconds after this
+    o << std::fixed << std::setprecision(8) << std::setw(16) << std::setfill('0') << now << "s ";
 }
 }}



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org