00001
00002
00003 #include "charm++.h"
00004 #include "trace-projector.h"
00005 #include "trace-projections.h"
00006
00007 #define DEBUGF(x) // CmiPrintf x
00008
00009 CkpvStaticDeclare(Trace*, _traceproj);
00010 class UsrEvent {
00011 public:
00012 int e;
00013 char *str;
00014 UsrEvent(int _e, char* _s): e(_e),str(_s) {}
00015 };
00016
00017 CkpvStaticDeclare(CkVec<UsrEvent *>, usrEventsProjector);
00018 #if ! CMK_TRACE_ENABLED
00019 static int warned=0;
00020 #define OPTIMIZED_VERSION \
00021 if (!warned) { warned=1; \
00022 CmiPrintf("\n\n!!!! Warning: traceUserEvent not available in optimized version!!!!\n\n\n"); }
00023 #else
00024 #define OPTIMIZED_VERSION
00025 #endif
00026
00031 void _createTraceprojector(char **argv)
00032 {
00033 DEBUGF(("%d createTraceProjector\n", CkMyPe()));
00034 CkpvInitialize(Trace*, _traceproj);
00035 CkpvInitialize(CkVec<UsrEvent *>, usrEventsProjector);
00036 CkpvAccess(_traceproj) = new TraceProjector(argv);
00037 CkpvAccess(_traces)->addTrace(CkpvAccess(_traceproj));
00038 }
00039
00040 TraceProjector::TraceProjector(char **argv)
00041 {
00042
00043 CpvInitialize(int, _traceCoreOn);
00044 CpvAccess(_traceCoreOn)=1;
00045 traceCoreOn = 1;
00046
00047 }
00048
00049 int TraceProjector::traceRegisterUserEvent(const char* evt, int e)
00050 {
00051 CkAssert(e==-1 || e>=0);
00052 CkAssert(evt != NULL);
00053 int event;
00054 int biggest = -1;
00055 for (int i=0; i<CkpvAccess(usrEventsProjector).length(); i++) {
00056 int cur = CkpvAccess(usrEventsProjector)[i]->e;
00057 if (cur == e)
00058 CmiAbort("UserEvent double registered!");
00059 if (cur > biggest) biggest = cur;
00060 }
00061
00062
00063 if (e==-1) event = biggest+1;
00064 else event = e;
00065 CkpvAccess(usrEventsProjector).push_back(new UsrEvent(event,(char *)evt));
00066 return event;
00067 }
00068
00069 void TraceProjector::traceClearEps(void)
00070 {
00071
00072
00073
00074 }
00075
00076
00077 extern "C" void writeSts(){
00078 FILE *stsfp;
00079 char *fname = new char[strlen(CkpvAccess(traceRoot))+strlen(".sts")+1];
00080 sprintf(fname, "%s.sts", CkpvAccess(traceRoot));
00081 do{
00082 stsfp = fopen(fname, "w");
00083 } while (!stsfp && (errno == EINTR || errno == EMFILE));
00084 if(stsfp==0)
00085 CmiAbort("Cannot open projections sts file for writing.\n");
00086 delete[] fname;
00087
00088 fprintf(stsfp, "VERSION %s\n", PROJECTION_VERSION);
00089 traceWriteSTS(stsfp,CkpvAccess(usrEventsProjector).length());
00090 int i;
00091 for(i=0;i<CkpvAccess(usrEventsProjector).length();i++)
00092 fprintf(stsfp, "EVENT %d %s\n", CkpvAccess(usrEventsProjector)[i]->e, CkpvAccess(usrEventsProjector)[i]->str);
00093 fprintf(stsfp, "END\n");
00094 fclose(stsfp);
00095
00096 }
00097
00098
00099 void TraceProjector::traceWriteSts(void)
00100 {
00101 if(CkMyPe()==0)
00102 writeSts();
00103 }
00104
00105 void TraceProjector::traceClose(void)
00106 {
00107 if(CkMyPe()==0){
00108 writeSts();
00109 }
00110 CkpvAccess(_traceproj)->endComputation();
00111 closeTraceCore();
00112 }
00113
00114 void TraceProjector::traceBegin(void)
00115 {
00116 }
00117
00118 void TraceProjector::traceEnd(void)
00119 {
00120 }
00121
00122 void TraceProjector::userEvent(int e)
00123 {
00124 _LOG_E_USER_EVENT_CHARM(e);
00125 }
00126
00127 void TraceProjector::userBracketEvent(int e, double bt, double et)
00128 {
00129 _LOG_E_USER_EVENT_PAIR_CHARM(e,bt,et);
00130 }
00131
00132 void TraceProjector::creation(envelope *e, int ep,int num)
00133 {
00134 _LOG_E_CREATION_N(e, ep, num);
00135 }
00136
00137 void TraceProjector::beginExecute(envelope *e)
00138 {
00139
00140
00141 charm_beginExecute(e);
00142 }
00143
00144 void TraceProjector::beginExecute(CmiObjId *tid)
00145 {
00146
00147
00148 _LOG_E_BEGIN_EXECUTE(0);
00149 }
00150
00151
00152 void TraceProjector::beginExecute(int event,int msgType,int ep,int srcPe,int mlen,CmiObjId *idx)
00153 {
00154
00155 _LOG_E_BEGIN_EXECUTE_DETAILED(event, msgType, ep, srcPe, mlen);
00156 }
00157
00158 void TraceProjector::endExecute(void)
00159 {
00160 _LOG_E_END_EXECUTE();
00161 }
00162
00163 void TraceProjector::messageRecv(char *env, int pe)
00164 {
00165 _LOG_E_MSG_RECV_CHARM(env, pe);
00166 }
00167
00168 void TraceProjector::beginIdle(double curWallTime)
00169 {
00170 _LOG_E_PROC_IDLE();
00171 }
00172
00173 void TraceProjector::endIdle(double curWallTime)
00174 {
00175 _LOG_E_PROC_BUSY();
00176 }
00177
00178 void TraceProjector::beginPack(void)
00179 {
00180 _LOG_E_BEGIN_PACK();
00181 }
00182
00183 void TraceProjector::endPack(void)
00184 {
00185 _LOG_E_END_PACK();
00186 }
00187
00188 void TraceProjector::beginUnpack(void)
00189 {
00190 _LOG_E_BEGIN_UNPACK();
00191 }
00192
00193 void TraceProjector::endUnpack(void)
00194 {
00195 _LOG_E_END_UNPACK();
00196 }
00197
00198 void TraceProjector::enqueue(envelope *env)
00199 {
00200 _LOG_E_ENQUEUE(env);
00201 }
00202
00203 void TraceProjector::dequeue(envelope *env)
00204 {
00205 _LOG_E_DEQUEUE(env);
00206 }
00207
00208 void TraceProjector::beginComputation(void)
00209 {
00210 _LOG_E_BEGIN_COMPUTATION();
00211 }
00212
00213 void TraceProjector::endComputation(void)
00214 {
00215 _LOG_E_END_COMPUTATION();
00216 }
00217