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
00018 #define STDERR_LEVEL 5
00019 #endif
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
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
00057
00058 #define Debug(x) ;
00059 #define DebugM(x,y) ;
00060
00061 #endif
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
00124