Debug.h

Go to the documentation of this file.
00001 
00007 #ifndef DEBUG_H
00008 #define DEBUG_H
00009 
00010 #ifndef MIN_DEBUG_LEVEL
00011   #define MIN_DEBUG_LEVEL 0
00012 #endif
00013 #ifndef MAX_DEBUG_LEVEL
00014   #define MAX_DEBUG_LEVEL 10
00015 #endif
00016 #ifndef STDERR_LEVEL
00017   /* anything >= this error level goes to stderr */
00018   #define STDERR_LEVEL 5
00019 #endif
00020 
00021 
00022 /*****************************************************************
00023  *  DebugM(): function to display a debug message.
00024  *  Messages have different levels.  The low numbers are low severity
00025  *  while the high numbers are really important.  Very high numbers
00026  *  are sent to stderr rather than stdout.
00027  *  The default severity scale is from 0 to 10.
00028  *     0 = plain message
00029  *     4 = important message
00030  *     5 = warning (stderr)
00031  *     10 = CRASH BANG BOOM error (stderr)
00032  *  The remaining args are like printf: a format string and some args.
00033  *  This function can be turned off by compiling without the DEBUGM flag
00034  *  No parameters to this function should have a side effect!
00035  *  No functions should be passed as parameters!  (including inline)
00036  *****************************************************************/
00037 
00038  #ifdef DEBUGM
00039 
00040 #include "InfoStream.h"
00041 
00042   #define Debug(x) (x)
00043   #define DebugM(level,format) \
00044         { \
00045           if ((level >= MIN_DEBUG_LEVEL) && (level <= MAX_DEBUG_LEVEL)) \
00046           { \
00047             infostream Dout; \
00048             if (level >= STDERR_LEVEL)  Dout << "[ERROR " << level << "] "; \
00049             else if (level > 0) Dout << "[Debug " << level << "] "; \
00050             Dout << iPE << ' ' << iFILE; \
00051             Dout << format << endi; \
00052           } \
00053         }
00054 
00055  #else
00056   /* make a void function. */
00057   /* parameters with side effects will be removed! */
00058   #define Debug(x) ;
00059   #define DebugM(x,y)   ;
00060 
00061  #endif /* DEBUGM */
00062 
00063 #ifdef PROCTRACE_DEBUG
00064 #include "charm++.h"
00065 #include <stdarg.h>
00066 #include "ProcessorPrivate.h"
00067 class DebugFileTrace{
00068 private:
00069     char *fname;
00070     FILE *fp;
00071 public:
00072     inline static DebugFileTrace *Instance(char *fn){
00073         if(CkpvAccess(DebugFileTrace_instance)==0){
00074             CkpvAccess(DebugFileTrace_instance) = new DebugFileTrace(fn);
00075         }
00076         return CkpvAccess(DebugFileTrace_instance);
00077     }
00078     inline static DebugFileTrace *Object(){
00079         return CkpvAccess(DebugFileTrace_instance);
00080     }
00081     DebugFileTrace(char *fn){
00082         if(fn==NULL) {
00083             fname = NULL;
00084             fp = stdout;
00085             return;
00086         }else{
00087             char tmp[128];
00088             memset(tmp, 0, 128*sizeof(char));
00089             sprintf(tmp, "%s.%d", fn, CkMyPe());
00090             fname = new char[strlen(tmp)+1];
00091             memcpy(fname, tmp, strlen(tmp)+1);
00092             fp = fopen(fname, "w");
00093             fclose(fp);
00094         }
00095     }
00096     ~DebugFileTrace(){
00097         delete [] fname;
00098     }
00099     inline void writeTrace(const char *msg, ...){
00100         va_list argList;
00101         va_start(argList, msg);
00102         vfprintf(fp, msg, argList);
00103         va_end(argList);
00104     }   
00105     inline int openTrace(){ 
00106         if(fname==NULL)  return 0;
00107         fp = fopen(fname, "a"); 
00108         if(fp==NULL)
00109             return 1;
00110         else
00111             return 0;
00112     }
00113     inline int closeTrace(){ 
00114         if(fname==NULL)  return 0;
00115         return fclose(fp); 
00116     }
00117     inline int flushTrace(){
00118         return fflush(fp);
00119     }
00120 };
00121 #endif
00122 
00123 #endif /* DEBUG_H */
00124 

Generated on Tue Nov 21 01:17:13 2017 for NAMD by  doxygen 1.4.7