summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2010-06-17 16:51:53 +0200
committerMartin Sustrik <sustrik@250bpm.com>2010-06-17 16:51:53 +0200
commit7f01e9970d211235fc8057de6dc41ba8ceafe795 (patch)
tree600dc003c73e15ef965cc97a1abb99d6dfc0a260 /src
parent4777fe4010572d381a2ad8eb63df2fc5fb7e6642 (diff)
stopwatch returned to libzmq
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/zmq.cpp63
2 files changed, 64 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index fa97ca3..9b0ff5d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,7 +3,7 @@ lib_LTLIBRARIES = libzmq.la
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libzmq.pc
-include_HEADERS = ../include/zmq.h ../include/zmq.hpp
+include_HEADERS = ../include/zmq.h ../include/zmq.hpp ../include/zmq_utils.h
if BUILD_PGM
pgm_sources = ../foreign/openpgm/@pgm_basename@/openpgm/pgm/packet.c \
diff --git a/src/zmq.cpp b/src/zmq.cpp
index c8f419a..73a8d65 100644
--- a/src/zmq.cpp
+++ b/src/zmq.cpp
@@ -661,3 +661,66 @@ int zmq_device (int device_, void *insocket_, void *outsocket_)
return EINVAL;
}
}
+
+////////////////////////////////////////////////////////////////////////////////
+// 0MQ utils - to be used by perf tests
+////////////////////////////////////////////////////////////////////////////////
+
+#if defined ZMQ_HAVE_WINDOWS
+
+static uint64_t now ()
+{
+ // Get the high resolution counter's accuracy.
+ LARGE_INTEGER ticksPerSecond;
+ QueryPerformanceFrequency (&ticksPerSecond);
+
+ // What time is it?
+ LARGE_INTEGER tick;
+ QueryPerformanceCounter (&tick);
+
+ // Convert the tick number into the number of seconds
+ // since the system was started.
+ double ticks_div = (double) (ticksPerSecond.QuadPart / 1000000);
+ return (uint64_t) (tick.QuadPart / ticks_div);
+}
+
+void zmq_sleep (int seconds_)
+{
+ Sleep (seconds_ * 1000);
+}
+
+#else
+
+static uint64_t now ()
+{
+ struct timeval tv;
+ int rc;
+
+ rc = gettimeofday (&tv, NULL);
+ assert (rc == 0);
+ return (tv.tv_sec * (uint64_t) 1000000 + tv.tv_usec);
+}
+
+void zmq_sleep (int seconds_)
+{
+ sleep (seconds_);
+}
+
+#endif
+
+void *zmq_stopwatch_start ()
+{
+ uint64_t *watch = (uint64_t*) malloc (sizeof (uint64_t));
+ assert (watch);
+ *watch = now ();
+ return (void*) watch;
+}
+
+unsigned long zmq_stopwatch_stop (void *watch_)
+{
+ uint64_t end = now ();
+ uint64_t start = *(uint64_t*) watch_;
+ free (watch_);
+ return (unsigned long) (end - start);
+}
+