PAPI  5.0.1.0
papi_debug.h
Go to the documentation of this file.
00001 /****************************/
00002 /* THIS IS OPEN SOURCE CODE */
00003 /****************************/
00016 #ifndef _PAPI_DEBUG_H
00017 #define _PAPI_DEBUG_H
00018 
00019 #ifdef NO_VARARG_MACRO
00020 #include <stdarg.h>
00021 #endif
00022 
00023 #include <stdio.h>
00024 
00025 /* Debug Levels */
00026 
00027 #define DEBUG_SUBSTRATE         0x002
00028 #define DEBUG_API               0x004
00029 #define DEBUG_INTERNAL          0x008
00030 #define DEBUG_THREADS           0x010
00031 #define DEBUG_MULTIPLEX         0x020
00032 #define DEBUG_OVERFLOW          0x040
00033 #define DEBUG_PROFILE           0x080
00034 #define DEBUG_MEMORY            0x100
00035 #define DEBUG_LEAK              0x200
00036 #define DEBUG_ALL               (DEBUG_SUBSTRATE|DEBUG_API|DEBUG_INTERNAL|DEBUG_THREADS|DEBUG_MULTIPLEX|DEBUG_OVERFLOW|DEBUG_PROFILE|DEBUG_MEMORY|DEBUG_LEAK)
00037 
00038 /* Please get rid of the DBG macro from your code */
00039 
00040 extern int _papi_hwi_debug;
00041 extern unsigned long int ( *_papi_hwi_thread_id_fn ) ( void );
00042 
00043 #ifdef DEBUG
00044 
00045 #ifdef __GNUC__
00046 #define FUNC __FUNCTION__
00047 #elif defined(__func__)
00048 #define FUNC __func__
00049 #else
00050 #define FUNC "?"
00051 #endif
00052 
00053 #define DEBUGLABEL(a) if (_papi_hwi_thread_id_fn) fprintf(stderr, "%s:%s:%s:%d:%d:0x%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())
00054 #define ISLEVEL(a) (_papi_hwi_debug&a)
00055 
00056 #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")
00057 
00058 #ifndef NO_VARARG_MACRO      /* Has variable arg macro support */
00059 #define PAPIDEBUG(level,format, args...) { if(_papi_hwi_debug&level){DEBUGLABEL(DEBUGLEVEL(level));fprintf(stderr,format, ## args);}}
00060 
00061  /* Macros */
00062 
00063 #define SUBDBG(format, args...) (PAPIDEBUG(DEBUG_SUBSTRATE,format, ## args))
00064 #define APIDBG(format, args...) (PAPIDEBUG(DEBUG_API,format, ## args))
00065 #define INTDBG(format, args...) (PAPIDEBUG(DEBUG_INTERNAL,format, ## args))
00066 #define THRDBG(format, args...) (PAPIDEBUG(DEBUG_THREADS,format, ## args))
00067 #define MPXDBG(format, args...) (PAPIDEBUG(DEBUG_MULTIPLEX,format, ## args))
00068 #define OVFDBG(format, args...) (PAPIDEBUG(DEBUG_OVERFLOW,format, ## args))
00069 #define PRFDBG(format, args...) (PAPIDEBUG(DEBUG_PROFILE,format, ## args))
00070 #define MEMDBG(format, args...) (PAPIDEBUG(DEBUG_MEMORY,format, ## args))
00071 #define LEAKDBG(format, args...) (PAPIDEBUG(DEBUG_LEAK,format, ## args))
00072 #endif
00073 
00074 #else
00075 #ifndef NO_VARARG_MACRO      /* Has variable arg macro support */
00076 #define SUBDBG(format, args...) { ; }
00077 #define APIDBG(format, args...) { ; }
00078 #define INTDBG(format, args...) { ; }
00079 #define THRDBG(format, args...) { ; }
00080 #define MPXDBG(format, args...) { ; }
00081 #define OVFDBG(format, args...) { ; }
00082 #define PRFDBG(format, args...) { ; }
00083 #define MEMDBG(format, args...) { ; }
00084 #define LEAKDBG(format, args...) { ; }
00085 #define PAPIDEBUG(level, format, args...) { ; }
00086 #endif
00087 #endif
00088 
00089 /*
00090  * Debug functions for platforms without vararg macro support
00091  */
00092 
00093 #ifdef NO_VARARG_MACRO
00094 
00095 static void PAPIDEBUG( int level, char *format, va_list args )
00096 {
00097 #ifdef DEBUG
00098 
00099     if ( ISLEVEL( level ) ) {
00100         vfprintf( stderr, format, args );
00101     } else
00102 #endif
00103         return;
00104 }
00105 
00106 static void
00107 _SUBDBG( char *format, ... )
00108 {
00109 #ifdef DEBUG
00110     va_list args;
00111     va_start(args, format);
00112     PAPIDEBUG( DEBUG_SUBSTRATE, format, args );
00113     va_end(args);
00114 #endif
00115 }
00116 #ifdef DEBUG
00117 #define SUBDBG do { \
00118  if (DEBUG_SUBSTRATE & _papi_hwi_debug) {\
00119    DEBUGLABEL( DEBUGLEVEL ( DEBUG_SUBSTRATE ) ); \
00120  } \
00121 } while(0); _SUBDBG
00122 #else
00123 #define SUBDBG _SUBDBG
00124 #endif
00125 
00126 static void
00127 _APIDBG( char *format, ... )
00128 {
00129 #ifdef DEBUG
00130     va_list args;
00131     va_start(args, format);
00132     PAPIDEBUG( DEBUG_API, format, args );
00133     va_end(args);
00134 #endif
00135 }
00136 #ifdef DEBUG
00137 #define APIDBG do { \
00138   if (DEBUG_API&_papi_hwi_debug) {\
00139     DEBUGLABEL( DEBUGLEVEL ( DEBUG_API ) ); \
00140   } \
00141 } while(0); _APIDBG
00142 #else
00143 #define APIDBG _APIDBG
00144 #endif
00145 
00146 static void
00147 _INTDBG( char *format, ... )
00148 {
00149 #ifdef DEBUG
00150     va_list args;
00151     va_start(args, format);
00152     PAPIDEBUG( DEBUG_INTERNAL, format, args );
00153     va_end(args);
00154 #endif
00155 }
00156 #ifdef DEBUG
00157 #define INTDBG do { \
00158     if (DEBUG_INTERNAL&_papi_hwi_debug) {\
00159       DEBUGLABEL( DEBUGLEVEL ( DEBUG_INTERNAL ) ); \
00160     } \
00161 } while(0); _INTDBG
00162 #else
00163 #define INTDBG _INTDBG
00164 #endif 
00165 
00166 static void
00167 _THRDBG( char *format, ... )
00168 {
00169 #ifdef DEBUG
00170     va_list args;
00171     va_start(args, format);
00172     PAPIDEBUG( DEBUG_THREADS, format, args );
00173     va_end(args);
00174 #endif
00175 }
00176 #ifdef DEBUG
00177 #define THRDBG do { \
00178   if (DEBUG_THREADS&_papi_hwi_debug) {\
00179     DEBUGLABEL( DEBUGLEVEL ( DEBUG_THREADS ) ); \
00180   } \
00181 } while(0); _THRDBG
00182 #else
00183 #define THRDBG _THRDBG
00184 #endif
00185 
00186 static void
00187 _MPXDBG( char *format, ... )
00188 {
00189 #ifdef DEBUG
00190     va_list args;
00191     va_start(args, format);
00192     PAPIDEBUG( DEBUG_MULTIPLEX, format, args );
00193     va_end(args);
00194 #endif
00195 }
00196 #ifdef DEBUG
00197 #define MPXDBG do { \
00198   if (DEBUG_MULTIPLEX&_papi_hwi_debug) {\
00199     DEBUGLABEL( DEBUGLEVEL ( DEBUG_MULTIPLEX ) ); \
00200   } \
00201 } while(0); _MPXDBG
00202 #else
00203 #define MPXDBG _MPXDBG
00204 #endif
00205 
00206 static void
00207 _OVFDBG( char *format, ... )
00208 {
00209 #ifdef DEBUG
00210     va_list args;
00211     va_start(args, format);
00212     PAPIDEBUG( DEBUG_OVERFLOW, format, args );
00213     va_end(args);
00214 #endif
00215 }
00216 #ifdef DEBUG
00217 #define OVFDBG do { \
00218   if (DEBUG_OVERFLOW&_papi_hwi_debug) {\
00219     DEBUGLABEL( DEBUGLEVEL ( DEBUG_OVERFLOW ) ); \
00220   } \
00221 } while(0); _OVFDBG
00222 #else
00223 #define OVFDBG _OVFDBG
00224 #endif
00225 
00226 static void
00227 _PRFDBG( char *format, ... )
00228 {
00229 #ifdef DEBUG
00230     va_list args;
00231     va_start(args, format);
00232     PAPIDEBUG( DEBUG_PROFILE, format, args );
00233     va_end(args);
00234 #endif
00235 }
00236 #ifdef DEBUG
00237 #define PRFDBG do { \
00238   if (DEBUG_PROFILE&_papi_hwi_debug) {\
00239     DEBUGLABEL( DEBUGLEVEL ( DEBUG_PROFILE ) ); \
00240   } \
00241 } while(0); _PRFDBG
00242 #else
00243 #define PRFDBG _PRFDBG
00244 #endif
00245 
00246 static void
00247 _MEMDBG( char *format, ... )
00248 {
00249 #ifdef DEBUG
00250     va_list args;
00251     va_start(args, format);
00252     PAPIDEBUG( DEBUG_MEMORY, format , args);
00253     va_end(args);
00254 #endif
00255 }
00256 #ifdef DEBUG
00257 #define MEMDBG do { \
00258   if (DEBUG_MEMORY&_papi_hwi_debug) {\
00259     DEBUGLABEL( DEBUGLEVEL ( DEBUG_MEMORY ) ); \
00260   } \
00261 } while(0); _MEMDBG
00262 #else
00263 #define MEMDBG _MEMDBG
00264 #endif
00265 
00266 static void
00267 _LEAKDBG( char *format, ... )
00268 {
00269 #ifdef DEBUG
00270     va_list args;
00271     va_start(args, format);
00272     PAPIDEBUG( DEBUG_LEAK, format , args);
00273     va_end(args);
00274 #endif
00275 }
00276 #ifdef DEBUG
00277 #define LEAKDBG do { \
00278   if (DEBUG_LEAK&_papi_hwi_debug) {\
00279     DEBUGLABEL( DEBUGLEVEL ( DEBUG_LEAK ) ); \
00280   } \
00281 } while(0); _LEAKDBG
00282 #else
00283 #define LEAKDBG _LEAKDBG
00284 #endif
00285 
00286 /* ifdef NO_VARARG_MACRO */
00287 #endif
00288 
00289 #endif /* PAPI_DEBUG_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines