From ac31d79d6f6438c81c3190abd459d259f264b586 Mon Sep 17 00:00:00 2001 From: telleriam Date: Tue, 7 Aug 2007 10:35:19 +0000 Subject: [PATCH] Adding the possibility to place a timestamp in msecs before any FRSH_TRACE output. git-svn-id: http://www.frescor.org/private/svn/frescor/frsh/trunk/include@639 35b4ef3e-fd22-0410-ab77-dab3279adceb --- frsh_debug.h | 46 +++++++++++++++++++++++++++++++++++++++++-- timespec_operations.h | 40 +++++++++++++++++++++++++------------ 2 files changed, 71 insertions(+), 15 deletions(-) diff --git a/frsh_debug.h b/frsh_debug.h index 0b909a3..03cdb57 100644 --- a/frsh_debug.h +++ b/frsh_debug.h @@ -48,7 +48,7 @@ // Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA. // -// As a special exception, if you include this header file into source +// As a specialhttp://idunno.org/archive/2004/07/14/122.aspx exception, if you include this header file into source // files to be compiled, this header file does not by itself cause // the resulting executable to be covered by the GNU General Public // License. This exception does not however invalidate any other @@ -71,28 +71,70 @@ // 23-Jul-2007 SANGORRIN: create this file for debugging functions // 31-Jul-2007 TELLERIA: Change "debug" for "trace" // ----------------------------------------------------------------------- +#ifndef FRSH_DEBUG_H +#define FRSH_DEBUG_H + #include // for vprintf #include // for bool #include // for va_list, va_start and va_end +#include "timespec_operations.h" +#include "fosa_configuration_parameters.h" /* FOSA_CLOCK_REALTIME */ // Tune the following FLAGS to select the debugging messages to be generated #define FRSH_TRACE_CALLBACKS false +#define FRSH_TRACE_SERVICE_TH false #define FRSH_TRACE_WATCHDOG false #define FRSH_TRACE_TIMEDWAIT false -#define FRSH_TRACE_SERVICE_TH false #define FRSH_TRACE_SPORADIC_SERVER false #define FRSH_TRACE_ROUND_ROBIN false #define FRSH_TRACE_THREAD_INDEX false #define FRSH_TRACE_VRES_INDEX false +#define FRSH_TRACE_TS_MSECS + +/* These variables live defined in frsh_error.c */ +/************************************************/ +extern struct timespec frsh_trace_init_timespec; +extern long frsh_trace_init_timemsec; + + +static inline long int FRSH_GET_TIMESTAMP_MSECS() +{ + int terror = -1; + struct timespec current_time = {-1, -1}; + long int current_time_msec = -1; + long int result = -1; + + PRW( fosa_clock_get_time(FOSA_CLOCK_REALTIME, ¤t_time) ); + timespec2msec(¤t_time, ¤t_time_msec); + + result = current_time_msec - frsh_trace_init_timemsec; + + return result; +} + + static void inline FRSH_TRACE(bool is_active, const char *format, ...) { va_list args; +#ifdef FRSH_TRACE_TS_MSECS + const int TS_LENGTH_MSECS = 10; /* Room for LONG_MAX 2147483648 */ +#endif + if (is_active) { + va_start(args, format); + +#ifdef FRSH_TRACE_TS_MSECS + printf("%*ld: ", TS_LENGTH_MSECS, FRSH_GET_TIMESTAMP_MSECS()); +#endif vprintf(format, args); va_end(args); } } + + + +#endif diff --git a/timespec_operations.h b/timespec_operations.h index 9d6f2fe..e9e13ad 100644 --- a/timespec_operations.h +++ b/timespec_operations.h @@ -185,23 +185,37 @@ static inline void msec2timespec(long msec, struct timespec *timespec) static inline void timespec2msec(const struct timespec *timespec, long *msec) { - *msec = 0; + + *msec = (timespec->tv_sec % 2147482) * 1000 + timespec->tv_nsec/1000000; +} - /* We convert first the seconds checking for a possible overflow */ - if (timespec->tv_sec < 2147482) - { - *msec = timespec->tv_sec*1000; - } - else - { - *msec = -1; - return; - } - /* Now we add the contribution from the msecs with a truncation */ - *msec += (timespec->tv_nsec/1000000); +#define HOURS_IN_MSECS 3600000 +#define MINUTES_IN_MSECS 60000 + +#define HOURS_IN_TS 1000000 +#define MINUTES_IN_TS 100000 + +static inline long timespec2msects(const struct timespec *timespec) +{ + long msec_total = -1; + long minutes = -1; + long hours = -1; + + long remainder_msecs = -1; + long timestamp = -1; + + msec_total = (timespec->tv_sec % 2147482) * 1000 + timespec->tv_nsec/1000000; + + hours = msec_total / HOURS_IN_MSECS; + minutes = (msec_total % HOURS_IN_MSECS) / MINUTES_IN_MSECS; + remainder_msecs = ( (msec_total % HOURS_IN_MSECS) % MINUTES_IN_MSECS); + + timestamp = hours*HOURS_IN_TS + minutes*MINUTES_IN_TS + remainder_msecs; + return timestamp; } + //------------------------// // timespec_lessthan_msec // -- 2.39.2