From a12b9a2c58a03e69631266e15e54d491a1df4943 Mon Sep 17 00:00:00 2001 From: "Stephen D. Huston" Date: Sat, 7 May 2011 22:03:42 +0000 Subject: Added Windows high-res timer output. Resolves QPID-3236 git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1100638 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/sys/windows/Time.cpp | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/cpp/src/qpid/sys/windows/Time.cpp b/cpp/src/qpid/sys/windows/Time.cpp index 56eade651a..fe937bd2de 100644 --- a/cpp/src/qpid/sys/windows/Time.cpp +++ b/cpp/src/qpid/sys/windows/Time.cpp @@ -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(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(iNow.QuadPart); + now /= freq; // now is seconds after this + o << std::fixed << std::setprecision(8) << std::setw(16) << std::setfill('0') << now << "s "; } }} -- cgit v1.2.1