10 #include "trace-common.h"
11 #include "trace-bluegene.h"
13 #include "blue_impl.h"
16 #define DEBUGF(x) // CmiPrintf x
18 void _createTracebluegene(char** argv)
20 DEBUGF(("%d createTraceBluegene\n", CkMyPe()));
21 CkpvInitialize(TraceBluegene*, _tracebg);
22 CkpvAccess(_tracebg) = new TraceBluegene(argv);
23 CkpvAccess(_traces)->addTrace(CkpvAccess(_tracebg));
24 traceBluegeneLinked = 1;
28 // this PE must be trace-enabled(in trace-common.C) to be able to do bgPrint()
29 static void writeData(void *data, double t, double recvT, void *ptr)
31 TraceBluegene *traceBluegene = (TraceBluegene *)ptr;
32 CmiAssert(traceBluegene);
33 traceBluegene->writePrint((char*)data, t);
36 void TraceBluegene::writePrint(char* str, double t){
39 fprintf(pfp,"[%d] ", CkMyPe());
43 TraceBluegene::TraceBluegene(char** argv): pfp(NULL)
47 void TraceBluegene::traceClose() {
48 DEBUGF(("%d TraceBluegene::traceClose\n", CkMyPe()));
50 if(pfp != 0) fclose(pfp);
52 CkpvAccess(_traces)->removeTrace(this);
55 TraceBluegene::~TraceBluegene(){
58 CpvExtern(BGMach, bgMach);
59 void TraceBluegene::creatFiles()
61 char* fname = new char[1024];
62 sprintf(fname, "%sbgPrintFile.%d", cva(bgMach).traceroot?cva(bgMach).traceroot:"", CkMyPe());
63 pfp = fopen(fname,"w");
65 CmiAbort("Cannot open Bluegene print file for writing.\n");
69 void TraceBluegene::tlineEnd(void** parentLogPtr){
71 *parentLogPtr = (void*)BgLastLog(tTIMELINEREC);
76 void TraceBluegene::bgAddTag(const char* str){
77 if (!genTimeLog) return;
78 BgTimeLog * log = BgLastLog(tTIMELINEREC);
79 CmiAssert(log != NULL);
83 void TraceBluegene::bgDummyBeginExec(const char* name,void** parentLogPtr, int split)
86 CmiAssert(parentLogPtr!=NULL);
87 double startTime = BgGetCurTime();
88 BgTimeLog* newLog = BgStartLogByName(tTIMELINEREC, _threadEP, name, startTime, *(BgTimeLog**)parentLogPtr);
89 // if event's mesgID is (-1:-1) and there is no backward dependence
90 // to avoid timestamp correction, set a fake recv time so that it stays here
91 if (*parentLogPtr == NULL)
92 newLog->recvTime = startTime;
95 newLog->objId = (*(BgTimeLog**)parentLogPtr)->objId;
96 newLog->charm_ep = (*(BgTimeLog**)parentLogPtr)->charm_ep;
99 *parentLogPtr = newLog;
104 void TraceBluegene::bgBeginExec(char* msg, char *name)
107 if (!genTimeLog) return;
108 BgTimeLog* newLog = new BgTimeLog(msg, name);
109 tTIMELINEREC.logEntryStart(newLog);
112 // mark a new log, which depends on log
113 void TraceBluegene::bgSetInfo(char *msg, const char *name, void **logs, int count)
115 if (!genTimeLog) return;
116 BgTimeLog * curlog = BgLastLog(tTIMELINEREC);
117 if (name != NULL) curlog->setName(name);
118 for (int i=0; i<count; i++)
119 curlog->addBackwardDep((BgTimeLog*)logs[i]);
120 if (msg) curlog->addMsgBackwardDep(tTIMELINEREC, msg);
123 // mark a new log, which depends on log
124 void TraceBluegene::bgAmpiBeginExec(char *msg, char *name, void **logs, int count)
127 if (!genTimeLog) return;
128 BgTimeLog * curlog = BgLastLog(tTIMELINEREC);
129 curlog->setName(name);
130 for (int i=0; i<count; i++)
131 curlog->addBackwardDep((BgTimeLog*)logs[i]);
132 if (msg) curlog->addMsgBackwardDep(tTIMELINEREC, msg);
135 void TraceBluegene::bgAmpiLog(unsigned short op, unsigned int dataSize)
137 if (!genTimeLog) return;
138 BgTimeLog *curlog = BgLastLog(tTIMELINEREC);
140 curlog->mpiSize = dataSize;
143 void TraceBluegene::bgEndExec(int commit)
146 if (!genTimeLog) return;
148 BgLogEntryCommit(tTIMELINEREC);
150 BgEndLastLog(tTIMELINEREC);
153 void TraceBluegene::beginExecute(envelope *e, void *obj)
155 if (e==NULL || !genTimeLog) return;
156 BgTimeLog* log = tTIMELINE[tTIMELINE.length()-1];
157 CmiAssert(log!=NULL);
158 log->setCharmEP(e->getEpIdx());
161 void TraceBluegene::beginExecute(int event,int msgType,int ep,int srcPe, int mlen,CmiObjId *idx, void *obj)
163 //printf("SET OBJ ID\n");
166 log = tTIMELINE[tTIMELINE.length()-1];
169 if (idx!=NULL) log->setObjId(idx);
173 void TraceBluegene::getForwardDep(void* log, void** fDepPtr){
175 BgTimeLog* cLog = (BgTimeLog*) log;
177 if(cLog->forwardDeps.length() !=1) {
179 CkAbort("Quitting\n");
181 *fDepPtr = (void*)(cLog->forwardDeps[0]);
184 void TraceBluegene::getForwardDepForAll(void** logs1, void** logs2, int logsize,void* fDepPtr){
185 if(!genTimeLog) return;
187 CmiAssert(logsize>0);
188 BgTimeLog* cLog = (BgTimeLog*)fDepPtr;
192 // find the valid sdag overlap pointer
193 for(i=0;i< logsize+1;i++)
198 cLog->addBackwardDep((BgTimeLog*)logs2[i]);
200 // CmiAssert(i<logsize+1);
202 cLog->objId = ((BgTimeLog*)logs1[0])->objId; // sdag objID
203 for(int j=0;j<logsize;j++) {
204 cLog->addBackwardDep((BgTimeLog*)(logs1[j]));
205 CmiAssert(cLog->objId == ((BgTimeLog*)logs1[j])->objId);
209 void TraceBluegene::addBackwardDep(void *log)
211 if(!genTimeLog || log==NULL) return;
212 BgTimeLog *parentLogPtr = BgLastLog(tTIMELINEREC);
213 CmiAssert(parentLogPtr);
214 BgAddBackwardDep(parentLogPtr, (BgTimeLog*)log);
217 void TraceBluegene::userBracketEvent(const char* name, double bt, double et, void** parentLogPtr){
219 if (!genTimeLog) return;
221 BgTimeLog* newLog = new BgTimeLog(_threadEP,name,bt,et);
223 newLog->addBackwardDep(*(BgTimeLog**)parentLogPtr);
224 newLog->objId = (*(BgTimeLog**)parentLogPtr)->objId; // sdag objID
226 *parentLogPtr = newLog;
227 CmiAssert(*parentLogPtr != NULL);
228 tTIMELINEREC.logEntryInsert(newLog);
231 void TraceBluegene::userBracketEvent(const char* name, double bt, double et, void** parentLogPtr, CkVec<void*> bgLogList){
233 if (!genTimeLog) return;
235 BgTimeLog* newLog = new BgTimeLog(_threadEP,name,bt,et);
236 newLog->addBackwardDeps(bgLogList);
237 CmiAssert(bgLogList.size()>0);
238 newLog->objId = ((BgTimeLog*)bgLogList[0])->objId; // for sdag
239 *parentLogPtr = newLog;
240 tTIMELINEREC.logEntryInsert(newLog);
243 void TraceBluegene::bgPrint(const char* str){
244 if (CmiMemoryIs(CMI_MEMORY_IS_ISOMALLOC)) CmiDisableIsomalloc();
245 double curT = BgGetTime();
247 bgAddProjEvent(strdup(str), -1, curT, writeData, this, BG_EVENT_PRINT);
248 CmiPrintf(str, curT);
249 if (CmiMemoryIs(CMI_MEMORY_IS_ISOMALLOC)) CmiEnableIsomalloc();
252 extern "C" void BgPrintf(const char *str)
257 void TraceBluegene::bgMark(const char* str){
258 double curT = BgGetTime();
260 bgAddProjEvent(strdup(str), -1, curT, writeData, this, BG_EVENT_MARK);
263 extern "C" void BgMark(const char *str)
268 extern "C" void BgSetStartEvent()
272 log = tTIMELINE[tTIMELINE.length()-1];
275 log->setStartEvent();