Fix breakages caused by commit 48ed568c6
[charm.git] / src / ck-perf / trace-projector.C
blobf28ed63d80a2a7d520f46786d78b442d5931c685
1 /***********Projector tracing file added by Sayantan ****************/
3 #include "charm++.h"
4 #include "trace-projector.h"
5 #include "trace-projections.h"
7 #define DEBUGF(x)           // CmiPrintf x
9 CkpvStaticDeclare(Trace*, _traceproj);
10 class UsrEvent {
11 public:
12   int e;
13   char *str;
14   UsrEvent(int _e, char* _s): e(_e),str(_s) {}
17 CkpvStaticDeclare(CkVec<UsrEvent *>, usrEventsProjector);
18 #if ! CMK_TRACE_ENABLED
19 static int warned=0;
20 #define OPTIMIZED_VERSION       \
21         if (!warned) { warned=1;        \
22         CmiPrintf("\n\n!!!! Warning: traceUserEvent not available in optimized version!!!!\n\n\n"); }
23 #else
24 #define OPTIMIZED_VERSION /*empty*/
25 #endif
27 /**
28   For each TraceFoo module, _createTraceFoo() must be defined.
29   This function is called in _createTraces() generated in moduleInit.C
31 void _createTraceprojector(char **argv)
33   DEBUGF(("%d createTraceProjector\n", CkMyPe()));
34   CkpvInitialize(Trace*, _traceproj);
35   CkpvInitialize(CkVec<UsrEvent *>, usrEventsProjector);
36   CkpvAccess(_traceproj) = new  TraceProjector(argv);
37   CkpvAccess(_traces)->addTrace(CkpvAccess(_traceproj));
40 TraceProjector::TraceProjector(char **argv)
42         
43                 CpvInitialize(int, _traceCoreOn);
44                 CpvAccess(_traceCoreOn)=1;
45                 traceCoreOn = 1;
49 int TraceProjector::traceRegisterUserEvent(const char* evt, int e)
51 CkAssert(e==-1 || e>=0);
52   CkAssert(evt != NULL);
53   int event;
54   int biggest = -1;
55   for (int i=0; i<CkpvAccess(usrEventsProjector).length(); i++) {
56     int cur = CkpvAccess(usrEventsProjector)[i]->e;
57     if (cur == e) 
58       CmiAbort("UserEvent double registered!");
59     if (cur > biggest) biggest = cur;
60   }
61   // if biggest is -1, it means no user events were previously registered
62   // hence automatically assigned events will start from id of 0.
63   if (e==-1) event = biggest+1; // automatically assign new event id
64   else event = e;
65   CkpvAccess(usrEventsProjector).push_back(new UsrEvent(event,(char *)evt));
66   return event;
69 void TraceProjector::traceClearEps(void)
71   // In trace-summary, this zeros out the EP bins, to eliminate noise
72   // from startup.  Here, this isn't useful, since we can do that in
73   // post-processing
77 extern "C" void writeSts(){
78         FILE *stsfp;
79         char *fname = new char[strlen(CkpvAccess(traceRoot))+strlen(".sts")+1];
80         sprintf(fname, "%s.sts", CkpvAccess(traceRoot));
81         do{
82                 stsfp = fopen(fname, "w");
83         } while (!stsfp && (errno == EINTR || errno == EMFILE));
84         if(stsfp==0)
85                 CmiAbort("Cannot open projections sts file for writing.\n");
86         delete[] fname;
87                     
88          fprintf(stsfp, "VERSION %s\n", PROJECTION_VERSION);
89          traceWriteSTS(stsfp,CkpvAccess(usrEventsProjector).length());
90          int i;
91          for(i=0;i<CkpvAccess(usrEventsProjector).length();i++)
92               fprintf(stsfp, "EVENT %d %s\n", CkpvAccess(usrEventsProjector)[i]->e, CkpvAccess(usrEventsProjector)[i]->str);
93          fprintf(stsfp, "END\n");
94         fclose(stsfp);
95                              
99 void TraceProjector::traceWriteSts(void)
101         if(CkMyPe()==0)
102                 writeSts();
105 void TraceProjector::traceClose(void)
107     if(CkMyPe()==0){
108             writeSts();
109     }
110     CkpvAccess(_traceproj)->endComputation();   
111     closeTraceCore(); 
114 void TraceProjector::traceBegin(void)
118 void TraceProjector::traceEnd(void) 
122 void TraceProjector::userEvent(int e)
124         _LOG_E_USER_EVENT_CHARM(e);
127 void TraceProjector::userBracketEvent(int e, double bt, double et)
129         _LOG_E_USER_EVENT_PAIR_CHARM(e,bt,et);
132 void TraceProjector::creation(envelope *e, int ep,int num)
134         _LOG_E_CREATION_N(e, ep, num);
137 void TraceProjector::beginExecute(envelope *e)
139         //_LOG_E_BEGIN_EXECUTE(e);
140         
141         charm_beginExecute(e);
144 void TraceProjector::beginExecute(CmiObjId  *tid)
146         // FIXME-- log this
147         
148         _LOG_E_BEGIN_EXECUTE(0);
152 void TraceProjector::beginExecute(int event,int msgType,int ep,int srcPe,int mlen,CmiObjId *idx)
154         //CmiPrintf("TraceProjector:iData in beginExecuteDetailed %d %d \n",event,srcPe);
155         _LOG_E_BEGIN_EXECUTE_DETAILED(event, msgType, ep, srcPe, mlen);
158 void TraceProjector::endExecute(void)
160         _LOG_E_END_EXECUTE();
163 void TraceProjector::messageRecv(char *env, int pe)
165         _LOG_E_MSG_RECV_CHARM(env, pe);
168 void TraceProjector::beginIdle(double curWallTime)
170         _LOG_E_PROC_IDLE();
173 void TraceProjector::endIdle(double curWallTime)
175         _LOG_E_PROC_BUSY();
178 void TraceProjector::beginPack(void)
180         _LOG_E_BEGIN_PACK();
183 void TraceProjector::endPack(void)
185         _LOG_E_END_PACK();
188 void TraceProjector::beginUnpack(void)
190         _LOG_E_BEGIN_UNPACK();
193 void TraceProjector::endUnpack(void)
195         _LOG_E_END_UNPACK();
198 void TraceProjector::enqueue(envelope *env) 
200         _LOG_E_ENQUEUE(env);
203 void TraceProjector::dequeue(envelope *env) 
205         _LOG_E_DEQUEUE(env);
208 void TraceProjector::beginComputation(void)
210         _LOG_E_BEGIN_COMPUTATION();
213 void TraceProjector::endComputation(void)
215         _LOG_E_END_COMPUTATION();