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 _sdagMsg, _sdagChare, _sdagEP;
00030
00031
00032 extern "C" void traceAddThreadListeners(CthThread tid, envelope *e);
00033
00034
00035
00036
00037
00038 CkpvExtern(int, traceOnPe);
00039
00040
00041 CpvExtern(int, curPeEvent);
00042
00043
00044
00045 #if CMK_HAS_COUNTER_PAPI
00046 typedef long_long LONG_LONG_PAPI;
00047 #else
00048 typedef CMK_TYPEDEF_INT8 LONG_LONG_PAPI;
00049 #endif
00050
00051
00052
00053 class Trace {
00054
00055 protected:
00056 bool _traceOn;
00057
00058 public:
00059 Trace(): _traceOn(false) {}
00060 virtual void setTraceOnPE(int flag) { _traceOn = (flag!=0); }
00061 virtual inline int traceOnPE() { return (int)_traceOn; }
00062
00063
00064
00065 virtual void traceBegin() {}
00066 virtual void traceEnd() {}
00067
00068
00069 virtual void traceBeginComm() {}
00070 virtual void traceEndComm() {}
00071 virtual void traceBeginOnCommThread() {}
00072 virtual void traceEndOnCommThread() {}
00073 virtual void traceCommSetMsgID(char *) {}
00074 virtual void traceGetMsgID(char *msg, int *pe, int *event) {
00075 (void)msg; (void)pe; (void)event;
00076 }
00077 virtual void traceSetMsgID(char *msg, int pe, int event) {
00078 (void)msg; (void)pe; (void)event;
00079 }
00080
00081
00082 virtual int traceRegisterUserEvent(const char* eventName, int e) {
00083 (void)eventName; (void)e;
00084 return 0;
00085 }
00086
00087 virtual void userEvent(int eventID) { (void)eventID; }
00088
00089 virtual void userBracketEvent(int eventID, double bt, double et, int nestedID=0) {
00090 (void)eventID; (void)bt; (void)et; (void) nestedID;
00091 }
00092
00093 virtual void beginUserBracketEvent(int eventID, int nestedID=0) {
00094 (void)eventID; (void) nestedID;
00095 }
00096 virtual void endUserBracketEvent(int eventID, int nestedID=0) {
00097 (void)eventID; (void) nestedID;
00098 }
00099
00100
00101 virtual int traceRegisterUserStat(const char* evt, int e) {
00102 return 0;
00103 }
00104
00105
00106 virtual void updateStatPair(int e, double stat,double time) {}
00107 virtual void updateStat(int e, double stat) {}
00108
00109
00110 virtual void beginAppWork() {}
00111 virtual void endAppWork() {}
00112 virtual void countNewChare() {}
00113 virtual void beginTuneOverhead() {}
00114 virtual void endTuneOverhead() {}
00115
00116
00117 virtual void userSuppliedData(int e) { (void)e; }
00118
00119
00120 virtual void userSuppliedNote(const char *note) { (void)note; }
00121
00122 virtual void userSuppliedBracketedNote(const char *note, int eventID, double bt, double et) {
00123 (void)note; (void)eventID; (void)bt; (void)et;
00124 }
00125
00126
00127 virtual void memoryUsage(double currentMemUsage) { (void)currentMemUsage; }
00128
00129
00130 virtual void creation(envelope *, int epIdx, int num=1) {
00131 (void)epIdx; (void)num;
00132 }
00133
00134 virtual void creation(char *) {}
00135 virtual void creationMulticast(envelope *, int epIdx, int num=1,
00136 const int *pelist=NULL) {
00137 (void)epIdx; (void)num; (void)pelist;
00138 }
00139 virtual void creationDone(int num=1) { (void)num; }
00140
00141 virtual void messageRecv(void *env, int size) { (void)env; (void)size; }
00142 virtual void messageSend(void *env, int pe, int size) { (void)env; (void)pe; (void)size; }
00143 virtual void beginSDAGBlock(
00144 int event,
00145 int msgType,
00146 int ep,
00147 int srcPe,
00148 int ml,
00149 CmiObjId* idx)
00150 {
00151 (void)event; (void)msgType; (void)ep; (void)srcPe; (void)ml; (void)idx;
00152 }
00153 virtual void endSDAGBlock(void) {}
00154
00155
00156
00157
00158 virtual void beginExecute(envelope *, void *) {}
00159 virtual void beginExecute(char *) {}
00160 virtual void beginExecute(CmiObjId *tid) { (void)tid; }
00161 virtual void beginExecute(
00162 int event,
00163 int msgType,
00164 int ep,
00165 int srcPe,
00166 int ml,
00167 CmiObjId* idx,
00168 void* obj)
00169 {
00170 (void)event; (void)msgType; (void)ep; (void)srcPe;
00171 (void)ml; (void)idx; (void)obj;
00172 }
00173 virtual void changeLastEntryTimestamp(double ts) { (void)ts; }
00174 virtual void endExecute(void) {}
00175 virtual void endExecute(char *) {}
00176
00177 virtual void beginIdle(double curWallTime) { (void)curWallTime; }
00178 virtual void endIdle(double curWallTime) { (void)curWallTime; }
00179
00180 virtual void beginPack(void) {}
00181 virtual void endPack(void) {}
00182
00183
00184 virtual void beginUnpack(void) {}
00185 virtual void endUnpack(void) {}
00186
00187 virtual void enqueue(envelope *) {}
00188 virtual void dequeue(envelope *) {}
00189
00190 virtual void beginComputation(void) {}
00191 virtual void endComputation(void) {}
00192
00193 virtual void endPhase() {}
00194
00195 virtual void traceClearEps() {}
00196
00197 virtual void traceEnableCCS() {}
00198
00199 virtual void traceWriteSts() {}
00200
00201 virtual void traceClose() {}
00202
00203 virtual void traceFlushLog() {}
00204
00205
00206 virtual void malloc(void *where, int size, void **stack, int stackSize) {
00207 (void)where; (void)size; (void)stack; (void)stackSize;
00208 }
00209 virtual void free(void *where, int size) {
00210 (void)where; (void)size;
00211 }
00212
00213
00214 virtual void traceAddThreadListeners(CthThread tid, envelope *e) {
00215 (void)tid; (void)e;
00216 }
00217
00218 virtual ~Trace() {}
00219 };
00220
00221 #define ALLDO(x) for (int i=0; i<length(); i++) if (traces[i] && traces[i]->traceOnPE()) traces[i]->x
00222 #define ALLREVERSEDO(x) for (int i=length()-1; i>=0; i--) if (traces[i]->traceOnPE()) traces[i]->x
00223
00225 class TraceArray {
00226 private:
00227 CkVec<Trace *> traces;
00228 int n;
00229 int cancel_beginIdle, cancel_endIdle;
00230 public:
00231 TraceArray(): n(0) {}
00232 inline void addTrace(Trace *tr) { traces.push_back(tr); n++;}
00233 inline void setTraceOnPE(int flag) { for (int i=0; i<length(); i++) traces[i]->setTraceOnPE(flag); }
00234
00235
00236
00237 inline void removeTrace(Trace *tr) {
00238 int i;
00239 for (i=0; i<n; i++) if (tr == traces[i]) break;
00240 CmiAssert(i<n);
00241 traces[i] = NULL;
00242 }
00243 inline void clearTrace() {
00244 int len = traces.length();
00245 int removed = 0;
00246 for (int i=0; i<len; i++) {
00247 if (traces[i-removed] == NULL) { traces.remove(i-removed); removed++; }
00248 }
00249 n -= removed;
00250 }
00251 inline int length() const { return n; }
00252
00253 inline void userEvent(int e) { ALLDO(userEvent(e));}
00254 inline void userBracketEvent(int e,double bt, double et, int nestedID=0) {ALLDO(userBracketEvent(e,bt,et,nestedID));}
00255 inline void beginUserBracketEvent(int e, int nestedID=0) {ALLDO(beginUserBracketEvent(e, nestedID));}
00256 inline void endUserBracketEvent(int e, int nestedID=0) {ALLDO(endUserBracketEvent(e, nestedID));}
00257
00258 inline void beginAppWork() { ALLDO(beginAppWork());}
00259 inline void endAppWork() { ALLDO(endAppWork());}
00260 inline void countNewChare() { ALLDO(countNewChare());}
00261 inline void beginTuneOverhead() { ALLDO(beginTuneOverhead());}
00262 inline void endTuneOverhead() { ALLDO(endTuneOverhead());}
00263
00264 inline void userSuppliedData(int d) { ALLDO(userSuppliedData(d));}
00265
00266 inline void userSuppliedNote(const char *note) { ALLDO(userSuppliedNote(note));}
00267 inline void userSuppliedBracketedNote(const char *note, int eventID, double bt, double et) {ALLDO(userSuppliedBracketedNote(note, eventID, bt, et));}
00268
00269
00270 inline void memoryUsage(double memUsage) { ALLDO(memoryUsage(memUsage));}
00271
00272
00273
00274 void creation(envelope *env, int ep, int num=1);
00275 inline void creation(char *msg){
00276
00277
00278
00279 ALLDO(creation(msg));
00280 }
00281 void creationMulticast(envelope *env, int ep, int num=1, const int *pelist=NULL);
00282
00283 inline void creationDone(int num=1) { ALLDO(creationDone(num)); }
00284 inline void beginSDAGBlock(int event,int msgType,int ep,int srcPe, int mlen,CmiObjId *idx=NULL) {ALLDO(beginSDAGBlock(event, msgType, ep, srcPe, mlen,idx));}
00285 inline void endSDAGBlock(void) {ALLREVERSEDO(endExecute());}
00286 inline void beginExecute(envelope *env, void *obj) {ALLDO(beginExecute(env, obj));}
00287 inline void beginExecute(char *msg) {ALLDO(beginExecute(msg));}
00288 inline void beginExecute(CmiObjId *tid) {ALLDO(beginExecute(tid));}
00289 inline void beginExecute(int event,int msgType,int ep,int srcPe, int mlen,CmiObjId *idx=NULL, void *obj=NULL) {ALLDO(beginExecute(event, msgType, ep, srcPe, mlen,idx, obj));}
00290 inline void endExecute(void) {ALLREVERSEDO(endExecute());}
00291 inline void endExecute(char *msg) {ALLREVERSEDO(endExecute(msg));}
00292 inline void changeLastEntryTimestamp(double ts) {ALLDO(changeLastEntryTimestamp(ts));}
00293 inline void messageRecv(void *env, int size) {ALLDO(messageRecv(env, size));}
00294 inline void messageSend(void *env, int pe, int size) {ALLDO(messageSend(env, pe, size));}
00295 inline void beginPack(void) {ALLDO(beginPack());}
00296 inline void endPack(void) {ALLDO(endPack());}
00297 inline void beginUnpack(void) {ALLDO(beginUnpack());}
00298 inline void endUnpack(void) {ALLDO(endUnpack());}
00299 inline void enqueue(envelope *e) {ALLDO(enqueue(e));}
00300 inline void dequeue(envelope *e) {ALLDO(dequeue(e));}
00301 inline void beginComputation(void) {ALLDO(beginComputation());}
00302 inline void endComputation(void) {ALLDO(endComputation());}
00303 inline int traceRegisterUserEvent(const char*x, int evt) {
00304 int eno = 0;
00305 for (int i=0; i<length(); i++) {
00306 if (traces[i]->traceOnPE() == 0) {
00307 continue;
00308 }
00309 int e = traces[i]->traceRegisterUserEvent(x, evt);
00310 if (e) eno = e;
00311 }
00312 return eno;
00313 }
00314
00315
00316 inline int traceRegisterUserStat(const char*x, int evt) {
00317 int eno = 0;
00318 for (int i=0; i<length(); i++) {
00319 if (traces[i]->traceOnPE() == 0) {
00320 continue;
00321 }
00322 int e = traces[i]->traceRegisterUserStat(x, evt);
00323 if (e) eno = e;
00324 }
00325 return eno;
00326 }
00327 inline void updateStatPair(int e,double stat,double time) {ALLDO(updateStatPair(e,stat,time));}
00328 inline void updateStat(int e,double stat) {ALLDO(updateStat(e,stat));}
00329
00330 inline void traceClearEps() {ALLDO(traceClearEps());}
00331 inline void traceEnableCCS() {ALLDO(traceEnableCCS());}
00332 inline void traceWriteSts() {ALLDO(traceWriteSts());}
00333 inline void traceClose() {ALLDO(traceClose()); clearTrace();}
00334 inline void traceFlushLog() {ALLDO(traceFlushLog());}
00335
00336
00337 inline void beginIdle(double curWallTime) {ALLDO(beginIdle(curWallTime));}
00338 inline void endIdle(double curWallTime) {ALLDO(endIdle(curWallTime));}
00339 void traceBegin();
00340 void traceEnd();
00341
00342
00343 void traceBeginComm();
00344 void traceEndComm();
00345 void traceBeginOnCommThread();
00346 void traceEndOnCommThread();
00347 void traceCommSetMsgID(char *msg) { ALLDO(traceCommSetMsgID(msg)); }
00348 void traceGetMsgID(char *msg, int *pe, int *event) { ALLDO(traceGetMsgID(msg, pe, event)); }
00349 void traceSetMsgID(char *msg, int pe, int event) { ALLDO(traceSetMsgID(msg, pe, event)); }
00350
00351
00352 inline void endPhase() { ALLDO(endPhase()); }
00353
00354
00355 inline void malloc(void *where, int size, void **stack, int stackSize){ ALLDO(malloc(where,size,stack,stackSize)); }
00356 inline void free(void *where, int size){ ALLDO(free(where, size)); }
00357
00358
00359 inline void traceAddThreadListeners(CthThread tid, envelope *e) {
00360 ALLDO(traceAddThreadListeners(tid, e));
00361 }
00362 };
00363
00364 CkpvExtern(TraceArray*, _traces);
00365
00366 #if CMK_TRACE_ENABLED
00367 #if CMK_BIGSIM_CHARM
00368 extern void resetVTime();
00369 # define _TRACE_ONLY(code) do{ BgGetTime(); if(CpvAccess(traceOn) && CkpvAccess(_traces)->length()>0) { code; } resetVTime(); } while(0)
00370 #else
00371 # define _TRACE_ONLY(code) do{if(CpvAccess(traceOn) && CkpvAccess(_traces)->length()>0) { code; }} while(0)
00372 #endif
00373 # define _TRACE_ALWAYS(code) do{ code; } while(0)
00374 #else
00375 # define _TRACE_ONLY(code)
00376 # define _TRACE_ALWAYS(code)
00377 #endif
00378
00379 extern "C" {
00380 #include "conv-trace.h"
00381 }
00382
00383 #define _TRACE_USER_EVENT(x) _TRACE_ONLY(CkpvAccess(_traces)->userEvent(x))
00384 #define _TRACE_USER_EVENT_BRACKET(x,bt,et) _TRACE_ONLY(CkpvAccess(_traces)->userBracketEvent(x,bt,et))
00385 #define _TRACE_BEGIN_USER_EVENT_BRACKET(x) _TRACE_ONLY(CkpvAccess(_traces)->beginUserBracketEvent(x))
00386 #define _TRACE_END_USER_EVENT_BRACKET(x) _TRACE_ONLY(CkpvAccess(_traces)->endUserBracketEvent(x))
00387 #define _TRACE_BEGIN_APPWORK() _TRACE_ONLY(CkpvAccess(_traces)->beginAppWork())
00388 #define _TRACE_END_APPWORK() _TRACE_ONLY(CkpvAccess(_traces)->endAppWork())
00389 #define _TRACE_NEW_CHARE() _TRACE_ONLY(CkpvAccess(_traces)->countNewChare())
00390 #define _TRACE_BEGIN_TUNEOVERHEAD() _TRACE_ONLY(CkpvAccess(_traces)->beginTuneOverhead())
00391 #define _TRACE_END_TUNEOVERHEAD() _TRACE_ONLY(CkpvAccess(_traces)->endTuneOverhead())
00392 #define _TRACE_CREATION_1(env) _TRACE_ONLY(CkpvAccess(_traces)->creation(env,env->getEpIdx()))
00393 #define _TRACE_CREATION_DETAILED(env,ep) _TRACE_ONLY(CkpvAccess(_traces)->creation(env,ep))
00394 #define _TRACE_CREATION_N(env, num) _TRACE_ONLY(CkpvAccess(_traces)->creation(env, env->getEpIdx(), num))
00395 #define _TRACE_CREATION_MULTICAST(env, num, pelist) _TRACE_ONLY(CkpvAccess(_traces)->creationMulticast(env, env->getEpIdx(), num, pelist))
00396 #define _TRACE_CREATION_DONE(num) _TRACE_ONLY(CkpvAccess(_traces)->creationDone(num))
00397 #define _TRACE_BEGIN_SDAG(env) _TRACE_ONLY(CkpvAccess(_traces)->beginSDAGBlock(env))
00398 #define _TRACE_END_SDAG(env) _TRACE_ONLY(CkpvAccess(_traces)->endSDAGBlock(env))
00399 #define _TRACE_BEGIN_EXECUTE(env, obj) _TRACE_ONLY(CkpvAccess(_traces)->beginExecute(env, obj))
00400 #define _TRACE_BEGIN_EXECUTE_DETAILED(evt,typ,ep,src,mlen,idx, obj) _TRACE_ONLY(CkpvAccess(_traces)->beginExecute(evt,typ,ep,src,mlen,idx, obj))
00401 #define _TRACE_END_EXECUTE() _TRACE_ONLY(CkpvAccess(_traces)->endExecute())
00402 #define _TRACE_MESSAGE_RECV(env, size) _TRACE_ONLY(CkpvAccess(_traces)->messageRecv(env, size))
00403 #define _TRACE_MESSAGE_SEND(env, pe, size) _TRACE_ONLY(CkpvAccess(_traces)->messageSend(env, pe, size))
00404 #define _TRACE_BEGIN_PACK() _TRACE_ONLY(CkpvAccess(_traces)->beginPack())
00405 #define _TRACE_END_PACK() _TRACE_ONLY(CkpvAccess(_traces)->endPack())
00406 #define _TRACE_BEGIN_UNPACK() _TRACE_ONLY(CkpvAccess(_traces)->beginUnpack())
00407 #define _TRACE_END_UNPACK() _TRACE_ONLY(CkpvAccess(_traces)->endUnpack())
00408 #define _TRACE_BEGIN_COMPUTATION() _TRACE_ALWAYS(CkpvAccess(_traces)->beginComputation())
00409 #define _TRACE_END_COMPUTATION() _TRACE_ALWAYS(CkpvAccess(_traces)->endComputation())
00410 #define _TRACE_ENQUEUE(env) _TRACE_ONLY(CkpvAccess(_traces)->enqueue(env))
00411 #define _TRACE_DEQUEUE(env) _TRACE_ONLY(CkpvAccess(_traces)->dequeue(env))
00412
00413 #define _TRACE_END_PHASE() _TRACE_ONLY(CkpvAccess(_traces)->endPhase())
00414
00415
00416 #define _TRACE_MALLOC(where, size, stack, stackSize) _TRACE_ONLY(CkpvAccess(_traces)->malloc(where,size,stack,stackSize))
00417 #define _TRACE_FREE(where, size) _TRACE_ONLY(CkpvAccess(_traces)->free(where, size))
00418
00419 #include "trace-bluegene.h"
00420
00421 #endif
00422
00423