4 #include "trace-TauBOC.h"
5 #include "trace-common.h"
7 //#include "tau_selective.cpp"
16 #define GETCWD _getcwd
18 #define PATHSEPSTR "\\"
24 #define PATHSEPSTR "/"
27 /*#ifndef PROFILING_ON
28 void TAU_PROFILER_CREATE(void *p, char *n, char *s, taugroup_t t) {
30 create profiler: %s \n", s); }
32 void TAU_PROFILER_STOP(void *p) { dprintf("---> tau
35 void TAU_PROFILER_START(void *p) { dprintf("---> tau
38 void TAU_PROFILE_SET_NODE(int i) { dprintf("---> tau
44 #define dprintf printf
46 #define dprintf if (0) printf
49 extern bool processFileForInstrumentation(const string& file_name);
50 extern void printExcludeList();
51 extern bool instrumentEntity(const string& function_name);
52 extern int processInstrumentationRequests(char *fname);
54 // Charm++ "processor"(user thread)-private global variable
55 CkpvStaticDeclare(TraceTau*, _trace);
57 // This global variable is required for any post-execution
58 // parallel analysis or activities the trace module might wish to perform.
59 CkGroupID traceTauGID;
62 For each TraceFoo module, _createTraceFoo() must be defined.
63 This function is called in _createTraces() generated in moduleInit.C
67 //char *name = "default";
68 bool profile = true, snapshotProfiling = false;
70 //map<const int, void*> events;
72 stack<void*> eventStack;
74 void *EXCLUDED = &EX_VALUE;
75 void startEntryEvent(int id)
77 dprintf("---------> starting Entry Event with id: %d\n", id);
79 if ((id == -1) || (events[id] == NULL))
81 dprintf("-------> create event with id: %d\n", id);
82 //sprintf(name, "Event %d", id);
85 char *name = "dummy_thread_ep";
86 dprintf(" ------> creating event: %s\n", name);
87 TAU_PROFILER_CREATE(events[id], name, "", TAU_DEFAULT);
88 dprintf("timer created.\n");
89 eventStack.push(events[id]);
90 dprintf(" ------> starting event: %s\n", (char*) name);
91 TAU_PROFILER_START(eventStack.top());*/
93 dprintf("------> excluding dummy function");
94 eventStack.push(EXCLUDED);
98 //string check("doFFT(RSFFTMsg* impl_msg)");
99 //string name_s(_entryTable[id]->name);
100 //printf("checking name4: %s", _entryTable[id]->name);
101 //if (check.compare(name_s) != 0)
104 sprintf(name, "%s::%s::%d", _chareTable[_entryTable[id]->chareIdx]->name,
105 _entryTable[id]->name, id);
106 //should this fuction be excluded from instrumentation?
107 if (!instrumentEntity(name))
110 dprintf("------> excluding function %s\n", name);
111 events[id] = EXCLUDED;
112 eventStack.push(events[id]);
116 dprintf(" ------> creating event: %s\n", name);
117 TAU_PROFILER_CREATE(events[id], name, "", TAU_DEFAULT);
118 dprintf("timer created.\n");
119 eventStack.push(events[id]);
120 dprintf("starting event\n");
121 dprintf(" ------> starting event: %s\n", (char*) name);
122 TAU_PROFILER_START(eventStack.top());
129 eventStack.push(events[id]);
130 if (events[id] != EXCLUDED)
132 TAU_PROFILER_START(eventStack.top());
137 void stopEntryEvent()
139 dprintf("stop timer...\n");
140 if (eventStack.top() != EXCLUDED)
142 TAU_PROFILER_STOP(eventStack.top());
148 void _createTraceTau(char **argv)
151 memset(events, 0, sizeof(void *)*5000);
152 //CkPrintf("NEWEST VERSION");
153 dprintf("arguments:\n");
154 dprintf("[0] = %s, ", argv[0]);
155 dprintf("[1] = %s, ", argv[1]);
156 dprintf("[2] = %s, ", argv[2]);
158 string disable = "disable-profiling";
159 if (argv[1] == NULL) { profile = true; }
160 else if (argv[1] == disable) { profile = false; }
161 if (not CkpvAccess(traceOn)) {
162 dprintf("traceoff selected using snapshot profiling.\n");
163 snapshotProfiling = true;
166 CkpvInitialize(TraceTau*, _trace);
167 CkpvAccess(_trace) = new TraceTau(argv);
168 CkpvAccess(_traces)->addTrace(CkpvAccess(_trace));
171 TraceTau::TraceTau(char **argv)
173 if (CkpvAccess(traceOnPe) == 0) return;
175 // Process runtime arguments intended for the module
176 CmiGetArgIntDesc(argv,"+TauPar0", &par0, "Fake integer parameter 0");
177 CmiGetArgDoubleDesc(argv,"+TauPar1", &par1, "Fake double parameter 1");
178 //TAU_REGISTER_THREAD();
181 if (strcmp(CkpvAccess(selective), ""))
183 //printf("select file: %s\n", CkpvAccess(selective));
184 //processFileForInstrumentation(CkpvAccess(selective));
185 processInstrumentationRequests(CkpvAccess(selective));
187 if (!instrumentEntity("Main::done(void)::99"))
189 dprintf("selective file working...\n");
192 dprintf("selective flile not working...\n");
195 TAU_PROFILER_CREATE(idle, "Idle", "", TAU_DEFAULT);
196 //TAU_PROFILER_CREATE(entry,name,"", TAU_DEFAULT);
197 dprintf("before %p\n", comp);
198 TAU_PROFILER_CREATE(comp, "Main", "", TAU_DEFAULT);
199 dprintf("after %p\n", comp);
201 //Need to add an entry timer to the top of the stack because
202 //traceTauExitFunction calls CkExit() which calls endExecute
203 eventStack.push(EXCLUDED);
207 dprintf("--> [TAU] creating timers...\n");
211 void TraceTau::userEvent(int eventID)
213 dprintf("[%d] User Point Event id %d encountered\n", CkMyPe(), eventID);
216 void TraceTau::userBracketEvent(int eventID, double bt, double et) {
217 dprintf("[%d] User Bracket Event id %d encountered\n", CkMyPe(), eventID);
220 void TraceTau::creation(envelope *, int epIdx, int num) {
221 dprintf("[%d] Point-to-Point Message for Entry Method id %d sent\n",
225 void TraceTau::creationMulticast(envelope *, int epIdx, int num,
227 dprintf("[%d] Multicast Message for Entry Method id %d sent to %d pes\n",
228 CkMyPe(), epIdx, num);
231 void TraceTau::creationDone(int num) {
232 dprintf("[%d] Last initiated send completes\n", CkMyPe());
235 void TraceTau::messageRecv(char *env, int pe) {
236 dprintf("[%d] Message from pe %d received by scheduler\n",
240 void TraceTau::beginExecute(CmiObjId *tid)
242 // CmiObjId is a 4-integer tuple uniquely identifying a migratable
243 // Charm++ object. Note that there are other non-migratable Charm++
244 // objects that CmiObjId will not identify.
245 dprintf("[%d] Entry Method invoked using object id\n", CkMyPe());
251 dprintf("--> [TAU] starting entry timer...\n");
255 void TraceTau::beginExecute(envelope *e)
257 // no message means thread execution
259 dprintf("[%d] Entry Method invoked via thread id %d\n", CkMyPe(),
266 dprintf("--> [TAU] starting entry timer...\n");
268 // Below is what is found in trace-summary.
269 // beginExecute(-1,-1,_threadEP,-1);
271 dprintf("[%d] Entry Method %d invoked via message envelope\n",
272 CkMyPe(), e->getEpIdx());
274 startEntryEvent(e->getEpIdx());
278 dprintf("--> [TAU] starting entry timer...\n");
280 // Below is what is found in trace-summary.
281 // beginExecute(-1,-1,e->getEpIdx(),-1);
285 void TraceTau::beginExecute(int event,int msgType,int ep,int srcPe,
286 int mlen, CmiObjId *idx)
288 dprintf("[%d] Entry Method %d invoked by parameters\n", CkMyPe(),
295 dprintf("--> [TAU] starting entry timer...\n");
299 void TraceTau::endExecute(void)
306 dprintf("--> [TAU] stoping entry timer...\n");
308 dprintf("[%d] Previously executing Entry Method completes\n", CkMyPe());
311 void TraceTau::beginIdle(double curWallTime) {
312 dprintf("[%d] Scheduler has no useful user-work\n", CkMyPe());
314 TAU_PROFILER_START(idle);
318 dprintf("--> [TAU] starting idle timer...\n");
322 void TraceTau::endIdle(double curWallTime) {
324 TAU_PROFILER_STOP(idle);
328 dprintf("--> [TAU] stopping idle timer...\n");
330 dprintf("[%d] Scheduler now has useful user-work\n", CkMyPe());
333 void TraceTau::beginComputation(void)
335 dprintf("[%d] Computation Begins\n", CkMyPe());
336 //TAU_DISABLE_ALL_GROUPS();
337 // Code Below shows what trace-summary would do.
338 // initialze arrays because now the number of entries is known.
339 // _logPool->initMem();
342 void TraceTau::endComputation(void)
344 dprintf("[%d] Computation Ends\n", CkMyPe());
347 void TraceTau::traceBegin(void)
349 dprintf("[%d] >>>>>> Tracing Begins\n", CkMyPe());
351 dprintf("ptr: %p\n", comp);
353 TAU_ENABLE_ALL_GROUPS();
354 TAU_PROFILER_START(comp);
358 dprintf("--> [TAU] starting computation timer...\n");
362 void TraceTau::traceEnd(void)
364 dprintf("[%d] >>>>>> Tracing Ends\n", CkMyPe());
366 dprintf("ptr: %p\n", comp);
367 //TAU_PROFILER_STOP(comp);
368 TAU_PROFILE_EXIT("tracing complete.");
369 TAU_DISABLE_ALL_GROUPS();
373 dprintf("--> [TAU] stopping computation timer and writing profiles\n");
375 dprintf("[%d] Computation Ends\n", CkMyPe());
378 void TraceTau::malloc(void *where, int size, void **stack, int stackSize)
380 dprintf("[%d] Memory allocation of size %d occurred\n", CkMyPe(), size);
383 void TraceTau::free(void *where, int size) {
384 dprintf("[%d] %d-byte Memory block freed\n", CkMyPe(), size);
387 void TraceTau::traceClose(void)
389 dprintf("traceClose called.\n");
390 CkpvAccess(_trace)->endComputation();
391 CkpvAccess(_trace)->traceEnd();
392 //TAU_PROFILE_EXIT("closing trace...");
393 //dprintf(" [%d] Exit called \n", CkMyPe());
394 //TAU_PROFILE_EXIT("exiting...");
395 // remove myself from traceArray so that no tracing will be called.
396 CkpvAccess(_traces)->removeTrace(this);
399 extern "C" void traceTauExitFunction() {
400 dprintf("traceTauExitFunction called.\n");
401 //TAU_PROFILE_EXIT("exiting...");
402 //TAU_PROFILE_EXIT("done");
403 //eventStack.push(NULL);
407 // Initialization of the parallel trace module.
408 void initTraceTauBOC() {
410 dprintf("tracetauboc setting node %d\n", CmiMyPe());
412 TAU_PROFILE_SET_NODE(CmiMyPe());
416 dprintf("---> [TAU] settting node.\n");
418 //TAU_PROFILER_CREATE(main, "main", "", TAU_DEFAULT);
419 //TAU_PROFILER_START(main);
421 if (BgNodeRank()==0) {
423 if (CkMyRank() == 0) {
425 registerExitFn(traceTauExitFunction);
429 #include "TraceTau.def.h"