]> rtime.felk.cvut.cz Git - frescor/frsh-include.git/commitdiff
Adding the possibility to place a timestamp in msecs before any FRSH_TRACE
authortelleriam <telleriam@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Tue, 7 Aug 2007 10:35:19 +0000 (10:35 +0000)
committertelleriam <telleriam@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Tue, 7 Aug 2007 10:35:19 +0000 (10:35 +0000)
output.

git-svn-id: http://www.frescor.org/private/svn/frescor/frsh/trunk/include@639 35b4ef3e-fd22-0410-ab77-dab3279adceb

frsh_debug.h
timespec_operations.h

index 0b909a3b43ec488d2daea36f2035c036d1c2b112..03cdb573647f0856b009989c3e7129f036ef6da1 100644 (file)
@@ -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
 // 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 <stdio.h> // for vprintf
 #include <stdbool.h> // for bool
 #include <stdarg.h> // 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, &current_time)  );
+    timespec2msec(&current_time, &current_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
index 9d6f2fe76ec64d3499af75402a8ecdfbe9898bd7..e9e13add680b142be1e6fdc4447b521ce6a5ba5d 100644 (file)
@@ -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 //