add API to pass application annotation time to tracing framework
[charm.git] / src / ck-perf / trace-bluegene.h
1 /**
2  * \addtogroup CkPerf
3 */
4 /*@{*/
5
6 #ifndef _TRACE_BIGSIM_H
7 #define _TRACE_BIGSIM_H
8
9 #include "trace.h"
10
11 // Bigsim emulator specific tracing subroutines.
12 class TraceBluegene : public Trace {
13
14  private:
15     FILE* pfp;
16  public:
17     TraceBluegene(char** argv);
18     ~TraceBluegene();
19     virtual void setTraceOnPE(int flag) { _traceOn = 1; }  // always on
20     int traceOnPE() { return 1; }
21     void getForwardDep(void* log, void** fDepPtr);
22     void getForwardDepForAll(void** logs1, void** logs2, int logsize,void* fDepPtr);
23     void tlineEnd(void** parentLogPtr);
24     void bgAddTag(const char *str);
25     void bgDummyBeginExec(const char* name,void** parentLogPtr, int split);
26     void bgBeginExec(char* msg, char *str);
27     void bgAmpiBeginExec(char *msg, char *str, void **logs, int count);
28     void bgAmpiLog(unsigned short op, unsigned int size);
29     void bgSetInfo(char *msg, const char *str, void **logs, int count);
30     void bgEndExec(int);
31     virtual void beginExecute(envelope *);
32     virtual void beginExecute(char *) {}
33     virtual void beginExecute(CmiObjId *tid) {}
34     virtual void beginExecute(int event,int msgType,int ep,int srcPe, int mlen,CmiObjId *idx);
35     void addBackwardDep(void *log);
36     void userBracketEvent(int eventID, double bt, double et) {} // from trace.h
37     void appWork(int e, double bt, double et){}
38     void userBracketEvent(const char* name, double bt, double et, void** parentLogPtr);
39     void userBracketEvent(const char* name, double bt, double et, void** parentLogPtr, CkVec<void*> bgLogList);
40     void bgPrint(const char* str);
41     void bgMark(const char* str);
42     void creatFiles();
43     void writePrint(char *, double t);
44     void traceClose();
45 };
46
47 CkpvExtern(TraceBluegene*, _tracebg);
48 extern int traceBluegeneLinked;
49
50 #if CMK_TRACE_ENABLED
51 #  define _TRACE_BG_ONLY(code) do{ BgGetTime(); if(traceBluegeneLinked && CpvAccess(traceOn)){ code; } resetVTime(); } while(0)
52 #else
53 #  define _TRACE_BG_ONLY(code) /*empty*/
54 #endif
55
56 /* tracing for Blue Gene - before trace projector era */
57 #if CMK_TRACE_ENABLED && CMK_TRACE_IN_CHARM
58 // for Sdag only
59 // fixme - think of better api for tracing sdag code
60 #define BgPrint(x)  _TRACE_BG_ONLY(CkpvAccess(_tracebg)->bgPrint(x))
61 #define BgMark_(x)  _TRACE_BG_ONLY(CkpvAccess(_tracebg)->bgMark(x))
62 #define _TRACE_BG_BEGIN_EXECUTE_NOMSG(x,pLogPtr,split)  _TRACE_BG_ONLY(CkpvAccess(_tracebg)->bgDummyBeginExec(x,pLogPtr,split))
63 #define _TRACE_BG_BEGIN_EXECUTE(msg, str)  _TRACE_BG_ONLY(CkpvAccess(_tracebg)->bgBeginExec(msg, str))
64 #define _TRACE_BG_SET_INFO(msg, str, logs, count)  _TRACE_BG_ONLY(CkpvAccess(_tracebg)->bgSetInfo(msg, str, logs, count))
65 #define _TRACE_BG_AMPI_BEGIN_EXECUTE(msg, str, logs, count)  _TRACE_BG_ONLY(CkpvAccess(_tracebg)->bgAmpiBeginExec(msg, str, logs, count))
66 #define _TRACE_BG_END_EXECUTE(commit)   _TRACE_BG_ONLY(CkpvAccess(_tracebg)->bgEndExec(commit))
67 #define _TRACE_BG_TLINE_END(pLogPtr) _TRACE_BG_ONLY(CkpvAccess(_tracebg)->tlineEnd(pLogPtr))
68 #define _TRACE_BG_FORWARD_DEPS(logs1,logs2,size,fDep)  _TRACE_BG_ONLY(CkpvAccess(_tracebg)->getForwardDepForAll(logs1,logs2, size,fDep))
69 #define _TRACE_BG_ADD_BACKWARD_DEP(log)  _TRACE_BG_ONLY(CkpvAccess(_tracebg)->addBackwardDep(log))
70 #define _TRACE_BG_USER_EVENT_BRACKET(x,bt,et,pLogPtr) _TRACE_BG_ONLY(CkpvAccess(_tracebg)->userBracketEvent(x,bt,et,pLogPtr))
71 #define _TRACE_BGLIST_USER_EVENT_BRACKET(x,bt,et,pLogPtr,bgLogList) _TRACE_BG_ONLY(CkpvAccess(_tracebg)->userBracketEvent(x,bt,et,pLogPtr,bgLogList))
72 #define TRACE_BG_ADD_TAG(str)   _TRACE_BG_ONLY(CkpvAccess(_tracebg)->bgAddTag(str))
73
74 # define TRACE_BG_AMPI_LOG(op,size)                                     \
75     _TRACE_BG_ONLY(CkpvAccess(_tracebg)->bgAmpiLog(op,size))
76
77 # define TRACE_BG_AMPI_SUSPEND()     \
78         _TRACE_BG_END_EXECUTE(1); \
79         /* if(CpvAccess(traceOn)) traceSuspend(); */
80
81 # define TRACE_BG_AMPI_START(t, str)  { \
82         void* _bgParentLog = NULL;      \
83         /*_TRACE_BG_TLINE_END(&_bgParentLog);*/ \
84         if(CpvAccess(traceOn) && t) CthTraceResume(t);  \
85         _TRACE_BG_BEGIN_EXECUTE_NOMSG(str, &_bgParentLog, 1);      \
86         }
87
88 # define TRACE_BG_AMPI_BREAK(t, str, event, count, connect)     \
89         {       \
90         void *curLog;    /* store current log in timeline */    \
91         _TRACE_BG_TLINE_END(&curLog);   \
92         TRACE_BG_AMPI_SUSPEND();        \
93         /* TRACE_BG_AMPI_START(t, str);  */  \
94         void * _bgParentLog = NULL;      \
95          _TRACE_BG_BEGIN_EXECUTE_NOMSG(str, &_bgParentLog, 1);  \
96         for(int i=0;i<count;i++) {      \
97                 _TRACE_BG_ADD_BACKWARD_DEP(((void**)event)[i]);      \
98         }       \
99         if (connect) _TRACE_BG_ADD_BACKWARD_DEP(curLog);      \
100         }
101         
102
103 #define TRACE_BG_AMPI_WAITALL(reqs)     \
104         {       \
105         /* TRACE_BG_AMPI_SUSPEND(); */  \
106         CthThread th = getAmpiInstance(MPI_COMM_WORLD)->getThread();    \
107         TRACE_BG_AMPI_BREAK(th, "AMPI_WAITALL", NULL, 0, 0);    \
108         _TRACE_BG_ADD_BACKWARD_DEP(curLog);     \
109         for(int i=0;i<count;i++) {      \
110           if (request[i] == MPI_REQUEST_NULL) continue; \
111           void *log = (*reqs)[request[i]]->event;       \
112           _TRACE_BG_ADD_BACKWARD_DEP(log);      \
113         }       \
114         }
115 extern "C" void BgSetStartEvent();
116 #else
117 # define BgPrint(x)  
118 # define BgMark_(x)  
119 #define _TRACE_BG_BEGIN_EXECUTE_NOMSG(x,pLogPtr,split)
120 #define _TRACE_BG_BEGIN_EXECUTE(msg, str)
121 #define _TRACE_BG_SET_INFO(msg, str, logs, count) 
122 #define _TRACE_BG_AMPI_BEGIN_EXECUTE(msg, str, logs, count)
123 #define _TRACE_BG_END_EXECUTE(commit)
124 #define _TRACE_BG_TLINE_END(x)  
125 #define _TRACE_BG_FORWARD_DEP(logs1,logs2,size,fDep)
126 #define _TRACE_BG_BACKWARD_DEP(log)     
127 #define _TRACE_BG_USER_EVENT_BRACKET(x,bt,et,pLogPtr)
128 #define _TRACE_BGLIST_USER_EVENT_BRACKET(x,bt,et,pLogPtr,bgLogList)
129 #define _TRACE_BG_ADD_TAG(str)
130         
131 # define TRACE_BG_AMPI_LOG(op, size)
132 # define TRACE_BG_AMPI_SUSPEND()
133 # define TRACE_BG_AMPI_RESUME(t, msg, str, log)
134 # define TRACE_BG_AMPI_START(t, str)
135 # define TRACE_BG_NEWSTART(t, str, events, count)
136 # define TRACE_BG_AMPI_BREAK(t, str, event, count)
137 # define TRACE_BG_AMPI_WAITALL(reqs)
138 # define TRACE_BG_AMPI_SET_SIZE(size)
139 #endif   /* CMK_TRACE_IN_CHARM */
140
141 extern "C" void BgPrintf(const char *str);
142 extern "C" void BgMark(const char *str);
143
144 #endif
145
146 /*@}*/