00001
00002 #ifndef _TRACE_H
00003 #define _TRACE_H
00004
00005
00006
00007
00008
00009
00010 #if CMK_HAS_COUNTER_PAPI
00011 #include <papi.h>
00012 #endif
00013
00014 class envelope;
00015
00020
00021
00022 extern "C" void traceClearEps();
00023
00024
00025 extern "C" void traceEnableCCS();
00026
00027 extern double CmiTraceTimer();
00028
00029 extern int _dummyMsg, _dummyChare, _dummyEP;
00030
00031
00032 extern "C" void traceAddThreadListeners(CthThread tid, envelope *e);
00033
00034
00035
00036
00037
00038 CkpvExtern(int, traceOnPe);
00039
00040
00041
00042 #if CMK_HAS_COUNTER_PAPI
00043 typedef long_long LONG_LONG_PAPI;
00044 #else
00045 typedef CMK_TYPEDEF_INT8 LONG_LONG_PAPI;
00046 #endif
00047
00048
00049
00050 class Trace {
00051 protected:
00052 int _traceOn;
00053
00054 public:
00055 Trace(): _traceOn(0) {}
00056 virtual void setTraceOnPE(int flag) { _traceOn = flag; }
00057 virtual inline int traceOnPE() { return _traceOn; }
00058
00059
00060
00061 virtual void traceBegin() {}
00062 virtual void traceEnd() {}
00063
00064
00065 virtual void traceBeginOnCommThread() {}
00066 virtual void traceEndOnCommThread() {}
00067 virtual void traceCommSetMsgID(char *) {}
00068 virtual void traceGetMsgID(char *msg, int *pe, int *event) {}
00069 virtual void traceSetMsgID(char *msg, int pe, int event) {}
00070
00071
00072 virtual int traceRegisterUserEvent(const char* eventName, int e) {
00073 return 0;
00074 }
00075
00076 virtual void userEvent(int eventID) {}
00077
00078 virtual void userBracketEvent(int eventID, double bt, double et) {}
00079
00080
00081 virtual void userSuppliedData(int e) {}
00082
00083
00084 virtual void userSuppliedNote(char *note) {}
00085
00086 virtual void userSuppliedBracketedNote(char *note, int eventID, double bt, double et) {}
00087
00088
00089 virtual void memoryUsage(double currentMemUsage) {}
00090
00091
00092 virtual void creation(envelope *, int epIdx, int num=1) {}
00093
00094 virtual void creation(char *) {}
00095 virtual void creationMulticast(envelope *, int epIdx, int num=1,
00096 int *pelist=NULL) {}
00097 virtual void creationDone(int num=1) {}
00098
00099 virtual void messageRecv(char *env, int pe) {}
00100 virtual void beginSDAGBlock(
00101 int event,
00102 int msgType,
00103 int ep,
00104 int srcPe,
00105 int ml,
00106 CmiObjId* idx)
00107 { }
00108 virtual void endSDAGBlock(void) {}
00109
00110
00111
00112
00113 virtual void beginExecute(envelope *) {}
00114 virtual void beginExecute(char *) {}
00115 virtual void beginExecute(CmiObjId *tid) {}
00116 virtual void beginExecute(
00117 int event,
00118 int msgType,
00119 int ep,
00120 int srcPe,
00121 int ml,
00122 CmiObjId* idx)
00123 { }
00124 virtual void changeLastEntryTimestamp(double ts) {}
00125 virtual void endExecute(void) {}
00126 virtual void endExecute(char *) {}
00127
00128 virtual void beginIdle(double curWallTime) {}
00129 virtual void endIdle(double curWallTime) {}
00130
00131 virtual void beginPack(void) {}
00132 virtual void endPack(void) {}
00133
00134
00135 virtual void beginUnpack(void) {}
00136 virtual void endUnpack(void) {}
00137
00138 virtual void enqueue(envelope *) {}
00139 virtual void dequeue(envelope *) {}
00140
00141 virtual void beginComputation(void) {}
00142 virtual void endComputation(void) {}
00143
00144 virtual void endPhase() {}
00145
00146 virtual void traceClearEps() {}
00147
00148 virtual void traceEnableCCS() {}
00149
00150 virtual void traceWriteSts() {}
00151
00152 virtual void traceClose() {}
00153
00154 virtual void traceFlushLog() {}
00155
00156
00157 virtual void regFunc(const char *name, int &idx, int idxSpecifiedByUser=0){}
00158 virtual void beginFunc(char *name,char *file,int line){}
00159 virtual void beginFunc(int idx,char *file,int line){}
00160 virtual void endFunc(char *name){}
00161 virtual void endFunc(int idx){}
00162
00163
00164 virtual void malloc(void *where, int size, void **stack, int stackSize){}
00165 virtual void free(void *where, int size){}
00166
00167
00168 virtual void traceAddThreadListeners(CthThread tid, envelope *e) {}
00169
00170 virtual ~Trace() {}
00171 };
00172
00173 #define ALLDO(x) for (int i=0; i<length(); i++) if (traces[i]->traceOnPE()) traces[i]->x
00174 #define ALLREVERSEDO(x) for (int i=length()-1; i>=0; i--) if (traces[i]->traceOnPE()) traces[i]->x
00175
00177 class TraceArray {
00178 private:
00179 CkVec<Trace *> traces;
00180 int n;
00181 int cancel_beginIdle, cancel_endIdle;
00182 public:
00183 TraceArray(): n(0) {}
00184 inline void addTrace(Trace *tr) { traces.push_back(tr); n++;}
00185 inline void setTraceOnPE(int flag) { for (int i=0; i<length(); i++) traces[i]->setTraceOnPE(flag); }
00186
00187
00188
00189 inline void removeTrace(Trace *tr) {
00190 int i;
00191 for (i=0; i<n; i++) if (tr == traces[i]) break;
00192 CmiAssert(i<n);
00193 traces[i] = NULL;
00194 }
00195 inline void clearTrace() {
00196 int len = traces.length();
00197 int removed = 0;
00198 for (int i=0; i<len; i++) {
00199 if (traces[i-removed] == NULL) { traces.remove(i-removed); removed++; }
00200 }
00201 n -= removed;
00202 }
00203 inline int length() const { return n; }
00204
00205 inline void userEvent(int e) { ALLDO(userEvent(e));}
00206 inline void userBracketEvent(int e,double bt, double et) {ALLDO(userBracketEvent(e,bt,et));}
00207
00208 inline void userSuppliedData(int d) { ALLDO(userSuppliedData(d));}
00209
00210 inline void userSuppliedNote(char *note) { ALLDO(userSuppliedNote(note));}
00211 inline void userSuppliedBracketedNote(char *note, int eventID, double bt, double et) {ALLDO(userSuppliedBracketedNote(note, eventID, bt, et));}
00212
00213
00214 inline void memoryUsage(double memUsage) { ALLDO(memoryUsage(memUsage));}
00215
00216
00217
00218 void creation(envelope *env, int ep, int num=1);
00219 inline void creation(char *msg){
00220
00221
00222
00223 ALLDO(creation(msg));
00224 }
00225 void creationMulticast(envelope *env, int ep, int num=1, int *pelist=NULL);
00226
00227 inline void creationDone(int num=1) { ALLDO(creationDone(num)); }
00228 inline void beginSDAGBlock(int event,int msgType,int ep,int srcPe, int mlen,CmiObjId *idx=NULL) {ALLDO(beginSDAGBlock(event, msgType, ep, srcPe, mlen,idx));}
00229 inline void endSDAGBlock(void) {ALLREVERSEDO(endExecute());}
00230 inline void beginExecute(envelope *env) {ALLDO(beginExecute(env));}
00231 inline void beginExecute(char *msg) {ALLDO(beginExecute(msg));}
00232 inline void beginExecute(CmiObjId *tid) {ALLDO(beginExecute(tid));}
00233 inline void beginExecute(int event,int msgType,int ep,int srcPe, int mlen,CmiObjId *idx=NULL) {ALLDO(beginExecute(event, msgType, ep, srcPe, mlen,idx));}
00234 inline void endExecute(void) {ALLREVERSEDO(endExecute());}
00235 inline void endExecute(char *msg) {ALLREVERSEDO(endExecute(msg));}
00236 inline void changeLastEntryTimestamp(double ts) {ALLDO(changeLastEntryTimestamp(ts));}
00237 inline void messageRecv(char *env, int pe) {ALLDO(messageRecv(env, pe));}
00238 inline void beginPack(void) {ALLDO(beginPack());}
00239 inline void endPack(void) {ALLDO(endPack());}
00240 inline void beginUnpack(void) {ALLDO(beginUnpack());}
00241 inline void endUnpack(void) {ALLDO(endUnpack());}
00242 inline void enqueue(envelope *e) {ALLDO(enqueue(e));}
00243 inline void dequeue(envelope *e) {ALLDO(dequeue(e));}
00244 inline void beginComputation(void) {ALLDO(beginComputation());}
00245 inline void endComputation(void) {ALLDO(endComputation());}
00246 inline int traceRegisterUserEvent(const char*x, int evt) {
00247 int eno = 0;
00248 for (int i=0; i<length(); i++) {
00249 if (traces[i]->traceOnPE() == 0) {
00250 continue;
00251 }
00252 int e = traces[i]->traceRegisterUserEvent(x, evt);
00253 if (e) eno = e;
00254 }
00255 return eno;
00256 }
00257 inline void traceClearEps() {ALLDO(traceClearEps());}
00258 inline void traceEnableCCS() {ALLDO(traceEnableCCS());}
00259 inline void traceWriteSts() {ALLDO(traceWriteSts());}
00260 inline void traceClose() {ALLDO(traceClose()); clearTrace();}
00261 inline void traceFlushLog() {ALLDO(traceFlushLog());}
00262
00263
00264 inline void beginIdle(double curWallTime) {ALLDO(beginIdle(curWallTime));}
00265 inline void endIdle(double curWallTime) {ALLDO(endIdle(curWallTime));}
00266 void traceBegin();
00267 void traceEnd();
00268
00269
00270 void traceBeginOnCommThread();
00271 void traceEndOnCommThread();
00272 void traceCommSetMsgID(char *msg) { ALLDO(traceCommSetMsgID(msg)); }
00273 void traceGetMsgID(char *msg, int *pe, int *event) { ALLDO(traceGetMsgID(msg, pe, event)); }
00274 void traceSetMsgID(char *msg, int pe, int event) { ALLDO(traceSetMsgID(msg, pe, event)); }
00275
00276 inline void regFunc(const char *name, int &idx, int idxSpecifiedByUser=0){ ALLDO(regFunc(name, idx, idxSpecifiedByUser)); }
00277 inline void beginFunc(char *name,char *file,int line){ ALLDO(beginFunc(name,file,line)); };
00278 inline void beginFunc(int idx,char *file,int line){ ALLDO(beginFunc(idx,file,line)); };
00279 inline void endFunc(char *name){ ALLDO(endFunc(name)); }
00280 inline void endFunc(int idx){ ALLDO(endFunc(idx)); }
00281
00282
00283 inline void endPhase() { ALLDO(endPhase()); }
00284
00285
00286 inline void malloc(void *where, int size, void **stack, int stackSize){ ALLDO(malloc(where,size,stack,stackSize)); }
00287 inline void free(void *where, int size){ ALLDO(free(where, size)); }
00288
00289
00290 inline void traceAddThreadListeners(CthThread tid, envelope *e) {
00291 ALLDO(traceAddThreadListeners(tid, e));
00292 }
00293 };
00294
00295 CkpvExtern(TraceArray*, _traces);
00296
00297 #if CMK_TRACE_ENABLED
00298 #if CMK_BIGSIM_CHARM
00299 extern void resetVTime();
00300 # define _TRACE_ONLY(code) do{ BgGetTime(); if(CpvAccess(traceOn) && CkpvAccess(_traces)->length()>0) { code; } resetVTime(); } while(0)
00301 #else
00302 # define _TRACE_ONLY(code) do{if(CpvAccess(traceOn) && CkpvAccess(_traces)->length()>0) { code; }} while(0)
00303 #endif
00304 # define _TRACE_ALWAYS(code) do{ code; } while(0)
00305 #else
00306 # define _TRACE_ONLY(code)
00307 # define _TRACE_ALWAYS(code)
00308 #endif
00309
00310 extern "C" {
00311 #include "conv-trace.h"
00312 }
00313
00314 #define _TRACE_USER_EVENT(x) _TRACE_ONLY(CkpvAccess(_traces)->userEvent(x))
00315 #define _TRACE_USER_EVENT_BRACKET(x,bt,et) _TRACE_ONLY(CkpvAccess(_traces)->userBracketEvent(x,bt,et))
00316 #define _TRACE_CREATION_1(env) _TRACE_ONLY(CkpvAccess(_traces)->creation(env,env->getEpIdx()))
00317 #define _TRACE_CREATION_DETAILED(env,ep) _TRACE_ONLY(CkpvAccess(_traces)->creation(env,ep))
00318 #define _TRACE_CREATION_N(env, num) _TRACE_ONLY(CkpvAccess(_traces)->creation(env, env->getEpIdx(), num))
00319 #define _TRACE_CREATION_MULTICAST(env, num, pelist) _TRACE_ONLY(CkpvAccess(_traces)->creationMulticast(env, env->getEpIdx(), num, pelist))
00320 #define _TRACE_CREATION_DONE(num) _TRACE_ONLY(CkpvAccess(_traces)->creationDone(num))
00321 #define _TRACE_BEGIN_SDAG(env) _TRACE_ONLY(CkpvAccess(_traces)->beginSDAGBlock(env))
00322 #define _TRACE_END_SDAG(env) _TRACE_ONLY(CkpvAccess(_traces)->endSDAGBlock(env))
00323 #define _TRACE_BEGIN_EXECUTE(env) _TRACE_ONLY(CkpvAccess(_traces)->beginExecute(env))
00324 #define _TRACE_BEGIN_EXECUTE_DETAILED(evt,typ,ep,src,mlen,idx) _TRACE_ONLY(CkpvAccess(_traces)->beginExecute(evt,typ,ep,src,mlen,idx))
00325 #define _TRACE_END_EXECUTE() _TRACE_ONLY(CkpvAccess(_traces)->endExecute())
00326 #define _TRACE_MESSAGE_RECV(env, pe) _TRACE_ONLY(CkpvAccess(_traces)->messageRecv(env, pe))
00327 #define _TRACE_BEGIN_PACK() _TRACE_ONLY(CkpvAccess(_traces)->beginPack())
00328 #define _TRACE_END_PACK() _TRACE_ONLY(CkpvAccess(_traces)->endPack())
00329 #define _TRACE_BEGIN_UNPACK() _TRACE_ONLY(CkpvAccess(_traces)->beginUnpack())
00330 #define _TRACE_END_UNPACK() _TRACE_ONLY(CkpvAccess(_traces)->endUnpack())
00331 #define _TRACE_BEGIN_COMPUTATION() _TRACE_ALWAYS(CkpvAccess(_traces)->beginComputation())
00332 #define _TRACE_END_COMPUTATION() _TRACE_ALWAYS(CkpvAccess(_traces)->endComputation())
00333 #define _TRACE_ENQUEUE(env) _TRACE_ONLY(CkpvAccess(_traces)->enqueue(env))
00334 #define _TRACE_DEQUEUE(env) _TRACE_ONLY(CkpvAccess(_traces)->dequeue(env))
00335
00336 #define _TRACE_END_PHASE() _TRACE_ONLY(CkpvAccess(_traces)->endPhase())
00337
00338
00339 #define _TRACE_MALLOC(where, size, stack, stackSize) _TRACE_ONLY(CkpvAccess(_traces)->malloc(where,size,stack,stackSize))
00340 #define _TRACE_FREE(where, size) _TRACE_ONLY(CkpvAccess(_traces)->free(where, size))
00341
00342 #include "trace-bluegene.h"
00343
00344 #endif
00345
00346