]> rtime.felk.cvut.cz Git - frescor/frsh-include.git/blob - frsh_debug.h
Correcting function comments and synchronising .h with .c files
[frescor/frsh-include.git] / frsh_debug.h
1 // -----------------------------------------------------------------------
2 //  Copyright (C) 2006 - 2007 FRESCOR consortium partners:
3 //
4 //    Universidad de Cantabria,              SPAIN
5 //    University of York,                    UK
6 //    Scuola Superiore Sant'Anna,            ITALY
7 //    Kaiserslautern University,             GERMANY
8 //    Univ. Politécnica  Valencia,           SPAIN
9 //    Czech Technical University in Prague,  CZECH REPUBLIC
10 //    ENEA                                   SWEDEN
11 //    Thales Communication S.A.              FRANCE
12 //    Visual Tools S.A.                      SPAIN
13 //    Rapita Systems Ltd                     UK
14 //    Evidence                               ITALY
15 //
16 //    See http://www.frescor.org for a link to partners' websites
17 //
18 //           FRESCOR project (FP6/2005/IST/5-034026) is funded
19 //        in part by the European Union Sixth Framework Programme
20 //        The European Union is not liable of any use that may be
21 //        made of this code.
22 //
23 //
24 //  based on previous work (FSF) done in the FIRST project
25 //
26 //   Copyright (C) 2005  Mälardalen University, SWEDEN
27 //                       Scuola Superiore S.Anna, ITALY
28 //                       Universidad de Cantabria, SPAIN
29 //                       University of York, UK
30 //
31 //   FSF API web pages: http://marte.unican.es/fsf/docs
32 //                      http://shark.sssup.it/contrib/first/docs/
33 //
34 //  This file is part of FRSH Implementation
35 //
36 //  FRSH API is free software; you can  redistribute it and/or  modify
37 //  it under the terms of  the GNU General Public License as published by
38 //  the Free Software Foundation;  either  version 2, or (at  your option)
39 //  any later version.
40 //
41 //  FRSH API  is distributed  in  the hope  that  it  will  be useful,  but
42 //  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
43 //  MERCHANTABILITY  or  FITNESS FOR  A  PARTICULAR PURPOSE. See  the  GNU
44 //  General Public License for more details.
45 //
46 //  You should have  received a  copy of  the  GNU  General Public License
47 //  distributed  with  FRSH API;  see file COPYING.   If not,  write to the
48 //  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
49 //  02111-1307, USA.
50 //
51 //  As a special exception, if you include this header file into source
52 //  files to be compiled, this header file does not by itself cause
53 //  the resulting executable to be covered by the GNU General Public
54 //  License.  This exception does not however invalidate any other
55 //  reasons why the executable file might be covered by the GNU General
56 //  Public License.
57 // -----------------------------------------------------------------------
58 //==============================================
59 //  ******** *******    ********  **      **
60 //  **///// /**////**  **//////  /**     /**
61 //  **      /**   /** /**        /**     /**
62 //  ******* /*******  /********* /**********
63 //  **////  /**///**  ////////** /**//////**
64 //  **      /**  //**        /** /**     /**
65 //  **      /**   //** ********  /**     /**
66 //  //       //     // ////////   //      //
67 //
68 // FRSH(FRescor ScHeduler), pronounced "fresh"
69 //==============================================
70 //
71 // 23-Jul-2007 SANGORRIN: create this file for debugging functions
72 // 31-Jul-2007 TELLERIA:  Change "debug" for "trace"
73 // -----------------------------------------------------------------------
74 #ifndef FRSH_DEBUG_H
75 #define FRSH_DEBUG_H
76
77 #include <stdio.h> // for vprintf
78 #include <stdbool.h> // for bool
79 #include <stdarg.h> // for va_list, va_start and va_end
80 #include "timespec_operations.h"
81 #include "fosa_configuration_parameters.h" /* FOSA_CLOCK_REALTIME */
82 #include "fosa_clocks_and_timers.h"
83
84 // Tune the following FLAGS to select the debugging messages to be generated
85 #define FRSH_TRACE_CALLBACKS false
86 #define FRSH_TRACE_SERVICE_TH false
87 #define FRSH_TRACE_WATCHDOG false
88 #define FRSH_TRACE_SPORADIC_SERVER false
89 #define FRSH_TRACE_ROUND_ROBIN false
90 #define FRSH_TRACE_BOUNDED_JOB false
91
92 #define FRSH_TRACE_ADMISSION_TEST false
93 #define FRSH_TRACE_ADMISSION_RESULT false
94
95 #define FRSH_TRACE_THREAD_INDEX false
96 #define FRSH_TRACE_VRES_INDEX false
97
98 #define FRSH_TRACE_DISTRIBUTED false
99
100 #define FRSH_TRACE_TS_MSECS
101
102 /* These variables live defined in frsh_error.c */
103 /************************************************/
104 extern struct timespec frsh_trace_init_timespec;
105 extern long frsh_trace_init_timemsec;
106
107 extern int global_error_condition;  /* Used to propagate error
108                                      * conditions in debugging */
109
110 static inline long int FRSH_GET_TIMESTAMP_MSECS()
111 {
112     int terror = -1;
113     struct timespec current_time = {-1, -1};
114     long int current_time_msec = -1;
115     long int result = -1;
116
117     PRW(  fosa_clock_get_time(FOSA_CLOCK_REALTIME, &current_time)  );
118     current_time_msec = timespec2msec(&current_time);
119
120     result = current_time_msec - frsh_trace_init_timemsec;
121
122     return result;
123 }
124
125 static inline long int FRSH_TIMESPEC_TO_RELATIVE_MSECS(const struct timespec *tspec)
126 {
127     long int time_msecs = -1;
128
129     time_msecs = timespec2msec(tspec);
130
131     return time_msecs - frsh_trace_init_timemsec;
132 }
133
134 static void inline FRSH_TRACE(bool is_active, const char *format, ...)
135 {
136     va_list args;
137
138 #ifdef FRSH_TRACE_TS_MSECS
139     const int TS_LENGTH_MSECS = 10; /* Room for LONG_MAX 2147483648 */
140 #endif
141
142     if (is_active) {
143
144         va_start(args, format);
145
146 #ifdef FRSH_TRACE_TS_MSECS
147         printf("%*ld: ", TS_LENGTH_MSECS, FRSH_GET_TIMESTAMP_MSECS());
148 #endif
149         vprintf(format, args);
150         va_end(args);
151     }
152 }
153
154 #endif