From 33664e85ab924b604b684f829f8db9ec8abcac87 Mon Sep 17 00:00:00 2001
From: Ramin Yaghoubzadeh <ryaghoubzadeh@uni-bielefeld.de>
Date: Tue, 1 Mar 2016 17:50:02 +0100
Subject: [PATCH] C++: simple profiling timers

[.. code ...]
IPAACA_SIMPLE_TIMER_BEGIN(blockid1)
[... first code block to time ...]
IPAACA_SIMPLE_TIMER_END(blockid1, "Processing loop 1")
[...]

-> e.g.: "Processing loop - us elapsed: 15" to terminal

Several blocks can be timed in one stack frame using more blockids
(TODO: implement profiling mode that can be turned on/off)
---
 ipaacalib/cpp/include/ipaaca/ipaaca.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/ipaacalib/cpp/include/ipaaca/ipaaca.h b/ipaacalib/cpp/include/ipaaca/ipaaca.h
index d3e9663..16d3844 100644
--- a/ipaacalib/cpp/include/ipaaca/ipaaca.h
+++ b/ipaacalib/cpp/include/ipaaca/ipaaca.h
@@ -223,6 +223,21 @@ IPAACA_MEMBER_VAR_EXPORT Lock& logger_lock();
 #define LOG_IPAACA_CONSOLE(msg) { ipaaca::Locker logging_locker(ipaaca::logger_lock()); timeval logging_tim; gettimeofday(&logging_tim, NULL); double logging_t1=logging_tim.tv_sec+(logging_tim.tv_usec/1000000.0); std::cout << "[LOG] " << std::setprecision(15) << logging_t1 << " : " << msg << std::endl; }
 #endif
 
+#ifdef WIN32
+#define IPAACA_SIMPLE_TIMER_BEGIN(N) ;
+#define IPAACA_SIMPLE_TIMER_END(N, NAME) LOG_IPAACA_CONSOLE(NAME << " - time elapsed: Windows - IMPLEMENT ME")
+#else
+/// use IPAACA_SIMPLE_TIMER_BEGIN(mysymbol) to start time profiling at a line in code
+/// Several blocks can be defined in the same stack frame if different symbols are chosen
+#define IPAACA_SIMPLE_TIMER_BEGIN(N) struct timeval _ipaaca_timer_tvstart_ ## N; \
+	gettimeofday(&_ipaaca_timer_tvstart_ ## N, NULL);
+/// use IPAACA_SIMPLE_TIMER_END(mysymbol, "message") to print time elapsed since correpsonding _BEGIN
+#define IPAACA_SIMPLE_TIMER_END(N, NAME) struct timeval _ipaaca_timer_tvend_ ## N; \
+	gettimeofday(&_ipaaca_timer_tvend_ ## N, NULL); \
+	long _ipaaca_timer_usecs_ ## N = (_ipaaca_timer_tvend_ ## N.tv_sec*1000000 + _ipaaca_timer_tvend_ ## N.tv_usec) - (_ipaaca_timer_tvstart_ ## N.tv_sec*1000000 + _ipaaca_timer_tvstart_ ## N.tv_usec); \
+	LOG_IPAACA_CONSOLE(NAME << " - ̨́us elapsed: " << _ipaaca_timer_usecs_ ## N)
+#endif
+
 #include <ipaaca/ipaaca-payload.h>
 #include <ipaaca/ipaaca-buffers.h>
 #include <ipaaca/ipaaca-ius.h>
-- 
GitLab