PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
papi_debug.h
Go to the documentation of this file.
1 /****************************/
2 /* THIS IS OPEN SOURCE CODE */
3 /****************************/
16 #ifndef _PAPI_DEBUG_H
17 #define _PAPI_DEBUG_H
18 
19 #ifdef NO_VARARG_MACRO
20 #include <stdarg.h>
21 #endif
22 
23 #include <stdio.h>
24 
25 /* Debug Levels */
26 
27 #define DEBUG_SUBSTRATE 0x002
28 #define DEBUG_API 0x004
29 #define DEBUG_INTERNAL 0x008
30 #define DEBUG_THREADS 0x010
31 #define DEBUG_MULTIPLEX 0x020
32 #define DEBUG_OVERFLOW 0x040
33 #define DEBUG_PROFILE 0x080
34 #define DEBUG_MEMORY 0x100
35 #define DEBUG_LEAK 0x200
36 #define DEBUG_ALL (DEBUG_SUBSTRATE|DEBUG_API|DEBUG_INTERNAL|DEBUG_THREADS|DEBUG_MULTIPLEX|DEBUG_OVERFLOW|DEBUG_PROFILE|DEBUG_MEMORY|DEBUG_LEAK)
37 
38 /* Please get rid of the DBG macro from your code */
39 
40 extern int _papi_hwi_debug;
41 extern unsigned long int ( *_papi_hwi_thread_id_fn ) ( void );
42 
43 #ifdef DEBUG
44 
45 #ifdef __GNUC__
46 #define FUNC __FUNCTION__
47 #elif defined(__func__)
48 #define FUNC __func__
49 #else
50 #define FUNC "?"
51 #endif
52 
53 #define DEBUGLABEL(a) if (_papi_hwi_thread_id_fn) fprintf(stderr, "%s:%s:%s:%d:%d:%#lx ",a,__FILE__, FUNC, __LINE__,(int)getpid(),_papi_hwi_thread_id_fn()); else fprintf(stderr, "%s:%s:%s:%d:%d ",a,__FILE__, FUNC, __LINE__, (int)getpid())
54 #define ISLEVEL(a) (_papi_hwi_debug&a)
55 
56 #define DEBUGLEVEL(a) ((a&DEBUG_SUBSTRATE)?"SUBSTRATE":(a&DEBUG_API)?"API":(a&DEBUG_INTERNAL)?"INTERNAL":(a&DEBUG_THREADS)?"THREADS":(a&DEBUG_MULTIPLEX)?"MULTIPLEX":(a&DEBUG_OVERFLOW)?"OVERFLOW":(a&DEBUG_PROFILE)?"PROFILE":(a&DEBUG_MEMORY)?"MEMORY":(a&DEBUG_LEAK)?"LEAK":"UNKNOWN")
57 
58 #ifndef NO_VARARG_MACRO /* Has variable arg macro support */
59 #define PAPIDEBUG(level,format, args...) { if(_papi_hwi_debug&level){DEBUGLABEL(DEBUGLEVEL(level));fprintf(stderr,format, ## args);}}
60 
61  /* Macros */
62 
63 #define SUBDBG(format, args...) (PAPIDEBUG(DEBUG_SUBSTRATE,format, ## args))
64 #define APIDBG(format, args...) (PAPIDEBUG(DEBUG_API,format, ## args))
65 #define INTDBG(format, args...) (PAPIDEBUG(DEBUG_INTERNAL,format, ## args))
66 #define THRDBG(format, args...) (PAPIDEBUG(DEBUG_THREADS,format, ## args))
67 #define MPXDBG(format, args...) (PAPIDEBUG(DEBUG_MULTIPLEX,format, ## args))
68 #define OVFDBG(format, args...) (PAPIDEBUG(DEBUG_OVERFLOW,format, ## args))
69 #define PRFDBG(format, args...) (PAPIDEBUG(DEBUG_PROFILE,format, ## args))
70 #define MEMDBG(format, args...) (PAPIDEBUG(DEBUG_MEMORY,format, ## args))
71 #define LEAKDBG(format, args...) (PAPIDEBUG(DEBUG_LEAK,format, ## args))
72 #endif
73 
74 #else
75 #ifndef NO_VARARG_MACRO /* Has variable arg macro support */
76 #define SUBDBG(format, args...) { ; }
77 #define APIDBG(format, args...) { ; }
78 #define INTDBG(format, args...) { ; }
79 #define THRDBG(format, args...) { ; }
80 #define MPXDBG(format, args...) { ; }
81 #define OVFDBG(format, args...) { ; }
82 #define PRFDBG(format, args...) { ; }
83 #define MEMDBG(format, args...) { ; }
84 #define LEAKDBG(format, args...) { ; }
85 #define PAPIDEBUG(level, format, args...) { ; }
86 #endif
87 #endif
88 
89 /*
90  * Debug functions for platforms without vararg macro support
91  */
92 
93 #ifdef NO_VARARG_MACRO
94 
95 static void PAPIDEBUG( int level, char *format, va_list args )
96 {
97 #ifdef DEBUG
98 
99  if ( ISLEVEL( level ) ) {
100  vfprintf( stderr, format, args );
101  } else
102 #endif
103  return;
104 }
105 
106 static void
107 _SUBDBG( char *format, ... )
108 {
109 #ifdef DEBUG
110  va_list args;
111  va_start(args, format);
112  PAPIDEBUG( DEBUG_SUBSTRATE, format, args );
113  va_end(args);
114 #endif
115 }
116 #ifdef DEBUG
117 #define SUBDBG do { \
118  if (DEBUG_SUBSTRATE & _papi_hwi_debug) {\
119  DEBUGLABEL( DEBUGLEVEL ( DEBUG_SUBSTRATE ) ); \
120  } \
121 } while(0); _SUBDBG
122 #else
123 #define SUBDBG _SUBDBG
124 #endif
125 
126 static void
127 _APIDBG( char *format, ... )
128 {
129 #ifdef DEBUG
130  va_list args;
131  va_start(args, format);
132  PAPIDEBUG( DEBUG_API, format, args );
133  va_end(args);
134 #endif
135 }
136 #ifdef DEBUG
137 #define APIDBG do { \
138  if (DEBUG_API&_papi_hwi_debug) {\
139  DEBUGLABEL( DEBUGLEVEL ( DEBUG_API ) ); \
140  } \
141 } while(0); _APIDBG
142 #else
143 #define APIDBG _APIDBG
144 #endif
145 
146 static void
147 _INTDBG( char *format, ... )
148 {
149 #ifdef DEBUG
150  va_list args;
151  va_start(args, format);
152  PAPIDEBUG( DEBUG_INTERNAL, format, args );
153  va_end(args);
154 #endif
155 }
156 #ifdef DEBUG
157 #define INTDBG do { \
158  if (DEBUG_INTERNAL&_papi_hwi_debug) {\
159  DEBUGLABEL( DEBUGLEVEL ( DEBUG_INTERNAL ) ); \
160  } \
161 } while(0); _INTDBG
162 #else
163 #define INTDBG _INTDBG
164 #endif
165 
166 static void
167 _THRDBG( char *format, ... )
168 {
169 #ifdef DEBUG
170  va_list args;
171  va_start(args, format);
172  PAPIDEBUG( DEBUG_THREADS, format, args );
173  va_end(args);
174 #endif
175 }
176 #ifdef DEBUG
177 #define THRDBG do { \
178  if (DEBUG_THREADS&_papi_hwi_debug) {\
179  DEBUGLABEL( DEBUGLEVEL ( DEBUG_THREADS ) ); \
180  } \
181 } while(0); _THRDBG
182 #else
183 #define THRDBG _THRDBG
184 #endif
185 
186 static void
187 _MPXDBG( char *format, ... )
188 {
189 #ifdef DEBUG
190  va_list args;
191  va_start(args, format);
192  PAPIDEBUG( DEBUG_MULTIPLEX, format, args );
193  va_end(args);
194 #endif
195 }
196 #ifdef DEBUG
197 #define MPXDBG do { \
198  if (DEBUG_MULTIPLEX&_papi_hwi_debug) {\
199  DEBUGLABEL( DEBUGLEVEL ( DEBUG_MULTIPLEX ) ); \
200  } \
201 } while(0); _MPXDBG
202 #else
203 #define MPXDBG _MPXDBG
204 #endif
205 
206 static void
207 _OVFDBG( char *format, ... )
208 {
209 #ifdef DEBUG
210  va_list args;
211  va_start(args, format);
212  PAPIDEBUG( DEBUG_OVERFLOW, format, args );
213  va_end(args);
214 #endif
215 }
216 #ifdef DEBUG
217 #define OVFDBG do { \
218  if (DEBUG_OVERFLOW&_papi_hwi_debug) {\
219  DEBUGLABEL( DEBUGLEVEL ( DEBUG_OVERFLOW ) ); \
220  } \
221 } while(0); _OVFDBG
222 #else
223 #define OVFDBG _OVFDBG
224 #endif
225 
226 static void
227 _PRFDBG( char *format, ... )
228 {
229 #ifdef DEBUG
230  va_list args;
231  va_start(args, format);
232  PAPIDEBUG( DEBUG_PROFILE, format, args );
233  va_end(args);
234 #endif
235 }
236 #ifdef DEBUG
237 #define PRFDBG do { \
238  if (DEBUG_PROFILE&_papi_hwi_debug) {\
239  DEBUGLABEL( DEBUGLEVEL ( DEBUG_PROFILE ) ); \
240  } \
241 } while(0); _PRFDBG
242 #else
243 #define PRFDBG _PRFDBG
244 #endif
245 
246 static void
247 _MEMDBG( char *format, ... )
248 {
249 #ifdef DEBUG
250  va_list args;
251  va_start(args, format);
252  PAPIDEBUG( DEBUG_MEMORY, format , args);
253  va_end(args);
254 #endif
255 }
256 #ifdef DEBUG
257 #define MEMDBG do { \
258  if (DEBUG_MEMORY&_papi_hwi_debug) {\
259  DEBUGLABEL( DEBUGLEVEL ( DEBUG_MEMORY ) ); \
260  } \
261 } while(0); _MEMDBG
262 #else
263 #define MEMDBG _MEMDBG
264 #endif
265 
266 static void
267 _LEAKDBG( char *format, ... )
268 {
269 #ifdef DEBUG
270  va_list args;
271  va_start(args, format);
272  PAPIDEBUG( DEBUG_LEAK, format , args);
273  va_end(args);
274 #endif
275 }
276 #ifdef DEBUG
277 #define LEAKDBG do { \
278  if (DEBUG_LEAK&_papi_hwi_debug) {\
279  DEBUGLABEL( DEBUGLEVEL ( DEBUG_LEAK ) ); \
280  } \
281 } while(0); _LEAKDBG
282 #else
283 #define LEAKDBG _LEAKDBG
284 #endif
285 
286 /* ifdef NO_VARARG_MACRO */
287 #endif
288 
289 #endif /* PAPI_DEBUG_H */
#define DEBUG_MULTIPLEX
Definition: papi_debug.h:31
#define DEBUG_PROFILE
Definition: papi_debug.h:33
int _papi_hwi_debug
Definition: papi.c:74
void
Definition: iozone.c:18627
#define DEBUG_MEMORY
Definition: papi_debug.h:34
#define DEBUG_API
Definition: papi_debug.h:28
#define PAPIDEBUG(level, format, args...)
Definition: papi_debug.h:59
#define DEBUG_LEAK
Definition: papi_debug.h:35
#define DEBUG_INTERNAL
Definition: papi_debug.h:29
unsigned long int(* _papi_hwi_thread_id_fn)(void)
Definition: threads.c:42
#define DEBUG_OVERFLOW
Definition: papi_debug.h:32
int
Definition: iozone.c:18528
#define ISLEVEL(a)
Definition: papi_debug.h:54
#define DEBUG_THREADS
Definition: papi_debug.h:30
#define DEBUG_SUBSTRATE
Definition: papi_debug.h:27