summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen D. Huston <shuston@apache.org>2011-05-07 22:03:42 +0000
committerStephen D. Huston <shuston@apache.org>2011-05-07 22:03:42 +0000
commitd0778f0048ad5705102220b17b26d32c550f8f9b (patch)
tree90849fb4d451dbc2eadb869e512789475e33472f
parent2e00ce309340f9f32fc82ee7dba7143f470a2e10 (diff)
downloadqpid-python-d0778f0048ad5705102220b17b26d32c550f8f9b.tar.gz
Added Windows high-res timer output. Resolves QPID-3236
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1100638 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/cpp/src/qpid/sys/windows/Time.cpp35
1 files changed, 29 insertions, 6 deletions
diff --git a/qpid/cpp/src/qpid/sys/windows/Time.cpp b/qpid/cpp/src/qpid/sys/windows/Time.cpp
index 56eade651a..fe937bd2de 100644
--- a/qpid/cpp/src/qpid/sys/windows/Time.cpp
+++ b/qpid/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<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 ";
}
}}