00001 #include <stdlib.h>
00002 #include "charm++.h"
00003 #include "trace-Tau.h"
00004 #include "trace-TauBOC.h"
00005 #include "trace-common.h"
00006 #include "TAU.h"
00007
00008 #include "map"
00009 #include "stack"
00010 #include <string>
00011 using namespace std;
00012
00013 #if defined(_WIN32) && !defined(__CYGWIN__)
00014 #include <direct.h>
00015 #define CHDIR _chdir
00016 #define GETCWD _getcwd
00017 #define PATHSEP '\\'
00018 #define PATHSEPSTR "\\"
00019 #else
00020 #include <unistd.h>
00021 #define CHDIR chdir
00022 #define GETCWD getcwd
00023 #define PATHSEP '/'
00024 #define PATHSEPSTR "/"
00025 #endif
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifdef DEBUG_PROF
00044 #define dprintf printf
00045 #else // DEBUG_PROF
00046 #define dprintf if (0) printf
00047 #endif
00048
00049 extern bool processFileForInstrumentation(const string& file_name);
00050 extern void printExcludeList();
00051 extern bool instrumentEntity(const string& function_name);
00052 extern int processInstrumentationRequests(char *fname);
00053
00054
00055 CkpvStaticDeclare(TraceTau*, _trace);
00056
00057
00058
00059 CkGroupID traceTauGID;
00060
00066 void *idle, *comp;
00067
00068 bool profile = true, snapshotProfiling = false;
00069
00070
00071 void* events[5000];
00072 stack<void*> eventStack;
00073 int EX_VALUE = 0;
00074 void *EXCLUDED = &EX_VALUE;
00075 void startEntryEvent(int id)
00076 {
00077 dprintf("---------> starting Entry Event with id: %d\n", id);
00078
00079 if ((id == -1) || (events[id] == NULL))
00080 {
00081 dprintf("-------> create event with id: %d\n", id);
00082
00083 if (id == -1)
00084 {
00085
00086
00087
00088
00089
00090
00091
00092
00093 dprintf("------> excluding dummy function");
00094 events[id] = EXCLUDED;
00095 eventStack.push(events[id]);
00096 }
00097 else
00098 {
00099
00100
00101
00102
00103
00104 char name [500];
00105 sprintf(name, "%s::%s::%d", _chareTable[_entryTable[id]->chareIdx]->name,
00106 _entryTable[id]->name, id);
00107
00108 if (!instrumentEntity(name))
00109 {
00110
00111 dprintf("------> excluding function %s\n", name);
00112 events[id] = EXCLUDED;
00113 eventStack.push(events[id]);
00114 }
00115 else
00116 {
00117 dprintf(" ------> creating event: %s\n", name);
00118 TAU_PROFILER_CREATE(events[id], name, "", TAU_DEFAULT);
00119 dprintf("timer created.\n");
00120 eventStack.push(events[id]);
00121 dprintf("starting event\n");
00122 dprintf(" ------> starting event: %s\n", (char*) name);
00123 TAU_PROFILER_START(eventStack.top());
00124 }
00125 dprintf("done.\n");
00126 }
00127 }
00128 else
00129 {
00130 eventStack.push(events[id]);
00131 if (events[id] != EXCLUDED)
00132 {
00133 TAU_PROFILER_START(eventStack.top());
00134 }
00135 }
00136 }
00137
00138 void stopEntryEvent()
00139 {
00140 dprintf("stop timer...\n");
00141 if (eventStack.top() != EXCLUDED)
00142 {
00143 TAU_PROFILER_STOP(eventStack.top());
00144 }
00145 eventStack.pop();
00146 }
00147
00148
00149 void _createTraceTau(char **argv)
00150 {
00151
00152 bzero(events, sizeof(void *)*5000);
00153
00154 dprintf("arguments:\n");
00155 dprintf("[0] = %s, ", argv[0]);
00156 dprintf("[1] = %s, ", argv[1]);
00157 dprintf("[2] = %s, ", argv[2]);
00158 dprintf("\n");
00159 string disable = "disable-profiling";
00160 if (argv[1] == NULL) { profile = true; }
00161 else if (argv[1] == disable) { profile = false; }
00162 if (not CkpvAccess(traceOn)) {
00163 dprintf("traceoff selected using snapshot profiling.\n");
00164 snapshotProfiling = true;
00165 }
00166
00167 CkpvInitialize(TraceTau*, _trace);
00168 CkpvAccess(_trace) = new TraceTau(argv);
00169 CkpvAccess(_traces)->addTrace(CkpvAccess(_trace));
00170 }
00171
00172 TraceTau::TraceTau(char **argv)
00173 {
00174 if (CkpvAccess(traceOnPe) == 0) return;
00175
00176
00177 CmiGetArgIntDesc(argv,"+TauPar0", &par0, "Fake integer parameter 0");
00178 CmiGetArgDoubleDesc(argv,"+TauPar1", &par1, "Fake double parameter 1");
00179
00180 if (profile)
00181 {
00182 if (strcmp(CkpvAccess(selective), ""))
00183 {
00184
00185
00186 processInstrumentationRequests(CkpvAccess(selective));
00187 printExcludeList();
00188 if (!instrumentEntity("Main::done(void)::99"))
00189 {
00190 dprintf("selective file working...\n");
00191 }
00192 else
00193 dprintf("selective flile not working...\n");
00194 }
00195
00196 TAU_PROFILER_CREATE(idle, "Idle", "", TAU_DEFAULT);
00197
00198 dprintf("before %p\n", comp);
00199 TAU_PROFILER_CREATE(comp, "Main", "", TAU_DEFAULT);
00200 dprintf("after %p\n", comp);
00201
00202
00203
00204 eventStack.push(EXCLUDED);
00205 }
00206 else
00207 {
00208 dprintf("--> [TAU] creating timers...\n");
00209 }
00210 }
00211
00212 void TraceTau::userEvent(int eventID)
00213 {
00214 dprintf("[%d] User Point Event id %d encountered\n", CkMyPe(), eventID);
00215 }
00216
00217 void TraceTau::userBracketEvent(int eventID, double bt, double et) {
00218 dprintf("[%d] User Bracket Event id %d encountered\n", CkMyPe(), eventID);
00219 }
00220
00221 void TraceTau::creation(envelope *, int epIdx, int num) {
00222 dprintf("[%d] Point-to-Point Message for Entry Method id %d sent\n",
00223 CkMyPe(), epIdx);
00224 }
00225
00226 void TraceTau::creationMulticast(envelope *, int epIdx, int num,
00227 int *pelist) {
00228 dprintf("[%d] Multicast Message for Entry Method id %d sent to %d pes\n",
00229 CkMyPe(), epIdx, num);
00230 }
00231
00232 void TraceTau::creationDone(int num) {
00233 dprintf("[%d] Last initiated send completes\n", CkMyPe());
00234 }
00235
00236 void TraceTau::messageRecv(char *env, int pe) {
00237 dprintf("[%d] Message from pe %d received by scheduler\n",
00238 CkMyPe(), pe);
00239 }
00240
00241 void TraceTau::beginExecute(CmiObjId *tid)
00242 {
00243
00244
00245
00246 dprintf("[%d] Entry Method invoked using object id\n", CkMyPe());
00247 if (profile) {
00248 startEntryEvent(-1);
00249 }
00250 else
00251 {
00252 dprintf("--> [TAU] starting entry timer...\n");
00253 }
00254 }
00255
00256 void TraceTau::beginExecute(envelope *e)
00257 {
00258
00259 if (e == NULL) {
00260 dprintf("[%d] Entry Method invoked via thread id %d\n", CkMyPe(),
00261 _threadEP);
00262 if (profile) {
00263 startEntryEvent(-1);
00264 }
00265 else
00266 {
00267 dprintf("--> [TAU] starting entry timer...\n");
00268 }
00269
00270
00271 } else {
00272 dprintf("[%d] Entry Method %d invoked via message envelope\n",
00273 CkMyPe(), e->getEpIdx());
00274 if (profile) {
00275 startEntryEvent(e->getEpIdx());
00276 }
00277 else
00278 {
00279 dprintf("--> [TAU] starting entry timer...\n");
00280 }
00281
00282
00283 }
00284 }
00285
00286 void TraceTau::beginExecute(int event,int msgType,int ep,int srcPe,
00287 int mlen, CmiObjId *idx)
00288 {
00289 dprintf("[%d] Entry Method %d invoked by parameters\n", CkMyPe(),
00290 ep);
00291 if (profile) {
00292 startEntryEvent(ep);
00293 }
00294 else
00295 {
00296 dprintf("--> [TAU] starting entry timer...\n");
00297 }
00298 }
00299
00300 void TraceTau::endExecute(void)
00301 {
00302 if (profile) {
00303 stopEntryEvent();
00304 }
00305 else
00306 {
00307 dprintf("--> [TAU] stoping entry timer...\n");
00308 }
00309 dprintf("[%d] Previously executing Entry Method completes\n", CkMyPe());
00310 }
00311
00312 void TraceTau::beginIdle(double curWallTime) {
00313 dprintf("[%d] Scheduler has no useful user-work\n", CkMyPe());
00314 if (profile) {
00315 TAU_PROFILER_START(idle);
00316 }
00317 else
00318 {
00319 dprintf("--> [TAU] starting idle timer...\n");
00320 }
00321 }
00322
00323 void TraceTau::endIdle(double curWallTime) {
00324 if (profile) {
00325 TAU_PROFILER_STOP(idle);
00326 }
00327 else
00328 {
00329 dprintf("--> [TAU] stopping idle timer...\n");
00330 }
00331 dprintf("[%d] Scheduler now has useful user-work\n", CkMyPe());
00332 }
00333
00334 void TraceTau::beginComputation(void)
00335 {
00336 dprintf("[%d] Computation Begins\n", CkMyPe());
00337
00338
00339
00340
00341 }
00342
00343 void TraceTau::endComputation(void)
00344 {
00345 dprintf("[%d] Computation Ends\n", CkMyPe());
00346 }
00347
00348 void TraceTau::traceBegin(void)
00349 {
00350 dprintf("[%d] >>>>>> Tracing Begins\n", CkMyPe());
00351 if (profile) {
00352 dprintf("ptr: %p\n", comp);
00353 TAU_DB_PURGE();
00354 TAU_ENABLE_ALL_GROUPS();
00355 TAU_PROFILER_START(comp);
00356 }
00357 else
00358 {
00359 dprintf("--> [TAU] starting computation timer...\n");
00360 }
00361 }
00362
00363 void TraceTau::traceEnd(void)
00364 {
00365 dprintf("[%d] >>>>>> Tracing Ends\n", CkMyPe());
00366 if (profile){
00367 dprintf("ptr: %p\n", comp);
00368
00369 TAU_PROFILE_EXIT("tracing complete.");
00370 TAU_DISABLE_ALL_GROUPS();
00371 }
00372 else
00373 {
00374 dprintf("--> [TAU] stopping computation timer and writing profiles\n");
00375 }
00376 dprintf("[%d] Computation Ends\n", CkMyPe());
00377 }
00378
00379 void TraceTau::malloc(void *where, int size, void **stack, int stackSize)
00380 {
00381 dprintf("[%d] Memory allocation of size %d occurred\n", CkMyPe(), size);
00382 }
00383
00384 void TraceTau::free(void *where, int size) {
00385 dprintf("[%d] %d-byte Memory block freed\n", CkMyPe(), size);
00386 }
00387
00388 void TraceTau::traceClose(void)
00389 {
00390 dprintf("traceClose called.\n");
00391 CkpvAccess(_trace)->endComputation();
00392 CkpvAccess(_trace)->traceEnd();
00393
00394
00395
00396
00397 CkpvAccess(_traces)->removeTrace(this);
00398 }
00399
00400 extern "C" void traceTauExitFunction() {
00401 dprintf("traceTauExitFunction called.\n");
00402
00403
00404
00405
00406
00407
00408 CkExit();
00409 }
00410
00411
00412 void initTraceTauBOC() {
00413
00414 dprintf("tracetauboc setting node %d\n", CmiMyPe());
00415 if (profile) {
00416 TAU_PROFILE_SET_NODE(CmiMyPe());
00417 }
00418 else
00419 {
00420 dprintf("---> [TAU] settting node.\n");
00421 }
00422
00423
00424 #ifdef __BIGSIM__
00425 if (BgNodeRank()==0) {
00426 #else
00427 if (CkMyRank() == 0) {
00428 #endif
00429 registerExitFn(traceTauExitFunction);
00430 }
00431 }
00432
00433 #include "TraceTau.def.h"