10 #include "trace-common.h"
11 #include "trace-bluegene.h"
13 #include "blue_impl.h"
14 #include "memory-isomalloc.h"
17 #define DEBUGF(x) // CmiPrintf x
19 void _createTracebluegene(char** argv)
21 DEBUGF(("%d createTraceBluegene\n", CkMyPe()));
22 CkpvInitialize(TraceBluegene*, _tracebg);
23 CkpvAccess(_tracebg) = new TraceBluegene(argv);
24 CkpvAccess(_traces)->addTrace(CkpvAccess(_tracebg));
25 traceBluegeneLinked = 1;
29 // this PE must be trace-enabled(in trace-common.C) to be able to do bgPrint()
30 static void writeData(void *data, double t, double recvT, void *ptr)
32 TraceBluegene *traceBluegene = (TraceBluegene *)ptr;
33 CmiAssert(traceBluegene);
34 traceBluegene->writePrint((char*)data, t);
37 void TraceBluegene::writePrint(char* str, double t){
40 fprintf(pfp,"[%d] ", CkMyPe());
44 TraceBluegene::TraceBluegene(char** argv): pfp(NULL)
48 void TraceBluegene::traceClose() {
49 DEBUGF(("%d TraceBluegene::traceClose\n", CkMyPe()));
51 if(pfp != 0) fclose(pfp);
53 CkpvAccess(_traces)->removeTrace(this);
56 TraceBluegene::~TraceBluegene(){
59 CpvExtern(BGMach, bgMach);
60 void TraceBluegene::creatFiles()
62 char* fname = new char[1024];
63 sprintf(fname, "%sbgPrintFile.%d", cva(bgMach).traceroot?cva(bgMach).traceroot:"", CkMyPe());
64 pfp = fopen(fname,"w");
66 CmiAbort("Cannot open Bluegene print file for writing.\n");
70 void TraceBluegene::tlineEnd(void** parentLogPtr){
72 *parentLogPtr = (void*)BgLastLog(tTIMELINEREC);
77 void TraceBluegene::bgAddTag(const char* str){
78 if (!genTimeLog) return;
79 BgTimeLog * log = BgLastLog(tTIMELINEREC);
80 CmiAssert(log != NULL);
84 void TraceBluegene::bgDummyBeginExec(const char* name,void** parentLogPtr, int split)
87 CmiAssert(parentLogPtr!=NULL);
88 double startTime = BgGetCurTime();
89 BgTimeLog* newLog = BgStartLogByName(tTIMELINEREC, _threadEP, name, startTime, *(BgTimeLog**)parentLogPtr);
90 // if event's mesgID is (-1:-1) and there is no backward dependence
91 // to avoid timestamp correction, set a fake recv time so that it stays here
92 if (*parentLogPtr == NULL)
93 newLog->recvTime = startTime;
96 newLog->objId = (*(BgTimeLog**)parentLogPtr)->objId;
97 newLog->charm_ep = (*(BgTimeLog**)parentLogPtr)->charm_ep;
100 *parentLogPtr = newLog;
105 void TraceBluegene::bgBeginExec(char* msg, char *name)
108 if (!genTimeLog) return;
109 BgTimeLog* newLog = new BgTimeLog(msg, name);
110 tTIMELINEREC.logEntryStart(newLog);
113 // mark a new log, which depends on log
114 void TraceBluegene::bgSetInfo(char *msg, const char *name, void **logs, int count)
116 if (!genTimeLog) return;
117 BgTimeLog * curlog = BgLastLog(tTIMELINEREC);
118 if (name != NULL) curlog->setName(name);
119 for (int i=0; i<count; i++)
120 curlog->addBackwardDep((BgTimeLog*)logs[i]);
121 if (msg) curlog->addMsgBackwardDep(tTIMELINEREC, msg);
124 // mark a new log, which depends on log
125 void TraceBluegene::bgAmpiBeginExec(char *msg, char *name, void **logs, int count)
128 if (!genTimeLog) return;
129 BgTimeLog * curlog = BgLastLog(tTIMELINEREC);
130 curlog->setName(name);
131 for (int i=0; i<count; i++)
132 curlog->addBackwardDep((BgTimeLog*)logs[i]);
133 if (msg) curlog->addMsgBackwardDep(tTIMELINEREC, msg);
136 void TraceBluegene::bgAmpiLog(unsigned short op, unsigned int dataSize)
138 if (!genTimeLog) return;
139 BgTimeLog *curlog = BgLastLog(tTIMELINEREC);
141 curlog->mpiSize = dataSize;
144 void TraceBluegene::bgEndExec(int commit)
147 if (!genTimeLog) return;
149 BgLogEntryCommit(tTIMELINEREC);
151 BgEndLastLog(tTIMELINEREC);
154 void TraceBluegene::beginExecute(envelope *e, void *obj)
156 if (e==NULL || !genTimeLog) return;
157 BgTimeLog* log = tTIMELINE[tTIMELINE.length()-1];
158 CmiAssert(log!=NULL);
159 log->setCharmEP(e->getEpIdx());
162 void TraceBluegene::beginExecute(int event,int msgType,int ep,int srcPe, int mlen,CmiObjId *idx, void *obj)
164 //printf("SET OBJ ID\n");
167 log = tTIMELINE[tTIMELINE.length()-1];
170 if (idx!=NULL) log->setObjId(idx);
174 void TraceBluegene::getForwardDep(void* log, void** fDepPtr){
176 BgTimeLog* cLog = (BgTimeLog*) log;
178 if(cLog->forwardDeps.length() !=1) {
180 CkAbort("Quitting\n");
182 *fDepPtr = (void*)(cLog->forwardDeps[0]);
185 void TraceBluegene::getForwardDepForAll(void** logs1, void** logs2, int logsize,void* fDepPtr){
186 if(!genTimeLog) return;
188 CmiAssert(logsize>0);
189 BgTimeLog* cLog = (BgTimeLog*)fDepPtr;
193 // find the valid sdag overlap pointer
194 for(i=0;i< logsize+1;i++)
199 cLog->addBackwardDep((BgTimeLog*)logs2[i]);
201 // CmiAssert(i<logsize+1);
203 cLog->objId = ((BgTimeLog*)logs1[0])->objId; // sdag objID
204 for(int j=0;j<logsize;j++) {
205 cLog->addBackwardDep((BgTimeLog*)(logs1[j]));
206 CmiAssert(cLog->objId == ((BgTimeLog*)logs1[j])->objId);
210 void TraceBluegene::addBackwardDep(void *log)
212 if(!genTimeLog || log==NULL) return;
213 BgTimeLog *parentLogPtr = BgLastLog(tTIMELINEREC);
214 CmiAssert(parentLogPtr);
215 BgAddBackwardDep(parentLogPtr, (BgTimeLog*)log);
218 void TraceBluegene::userBracketEvent(const char* name, double bt, double et, void** parentLogPtr){
220 if (!genTimeLog) return;
222 BgTimeLog* newLog = new BgTimeLog(_threadEP,name,bt,et);
224 newLog->addBackwardDep(*(BgTimeLog**)parentLogPtr);
225 newLog->objId = (*(BgTimeLog**)parentLogPtr)->objId; // sdag objID
227 *parentLogPtr = newLog;
228 CmiAssert(*parentLogPtr != NULL);
229 tTIMELINEREC.logEntryInsert(newLog);
232 void TraceBluegene::userBracketEvent(const char* name, double bt, double et, void** parentLogPtr, CkVec<void*> bgLogList){
234 if (!genTimeLog) return;
236 BgTimeLog* newLog = new BgTimeLog(_threadEP,name,bt,et);
237 newLog->addBackwardDeps(bgLogList);
238 CmiAssert(bgLogList.size()>0);
239 newLog->objId = ((BgTimeLog*)bgLogList[0])->objId; // for sdag
240 *parentLogPtr = newLog;
241 tTIMELINEREC.logEntryInsert(newLog);
244 void TraceBluegene::bgPrint(const char* str){
245 if (CmiMemoryIs(CMI_MEMORY_IS_ISOMALLOC)) CmiDisableIsomalloc();
246 double curT = BgGetTime();
248 bgAddProjEvent(strdup(str), -1, curT, writeData, this, BG_EVENT_PRINT);
249 CmiPrintf(str, curT);
250 if (CmiMemoryIs(CMI_MEMORY_IS_ISOMALLOC)) CmiEnableIsomalloc();
253 extern "C" void BgPrintf(const char *str)
258 void TraceBluegene::bgMark(const char* str){
259 double curT = BgGetTime();
261 bgAddProjEvent(strdup(str), -1, curT, writeData, this, BG_EVENT_MARK);
264 extern "C" void BgMark(const char *str)
269 extern "C" void BgSetStartEvent()
273 log = tTIMELINE[tTIMELINE.length()-1];
276 log->setStartEvent();