📄 mal_profiler.c
字号:
eventstream = 0; mal_unset_lock(profileLock, "profileLock");}#line 1009 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_profiler.mx"intinstrFilter(InstrPtr pci, str mod, str fcn){#ifdef MALprofiler if (getFunctionId(pci) && (*fcn == '*' || strcmp(fcn, getFunctionId(pci)) == 0)) { if (getModuleId(pci) && (*mod == '*' || strcmp(mod, getModuleId(pci)) == 0)) return 1; } if (getModuleId(pci) && *fcn == '*' && (*mod == '*' || strcmp(mod, getModuleId(pci)) == 0)) return 1;#else stream_printf(GDKout, "# Monet not compiled for profiling\n");#endif return 0;}voidsetFilter(Module cntxt, str mod, str fcn){#ifdef MALprofiler int j, k, moduleOnly = 0; Module s = cntxt; MalBlkPtr mb; Symbol t; InstrPtr p; profileAll = strcmp(mod, "*") == 0 && strcmp(fcn, "*") == 0; if (profileAll) { int i; for (i = 0; profileCounter[i].name; i++) profileCounter[i].status = 1; return; } if( ! profileLockInitialized) { MT_lock_init(&profileLock); profileLockInitialized= 1; } mal_set_lock(profileLock, "profileLock"); while (s != NULL) { if (s->subscope) for (j = 0; j < MAXSCOPE; j++) if (s->subscope[j]) { for (t = s->subscope[j]; t != NULL; t = t->peer) { p = getInstrPtr(mb=t->def, 0); moduleOnly = getModuleId(p) && strcmp(getModuleId(p), mod) == 0; initProfiler(mb); for (k = 0; k < t->def->stop; k++) { p = getInstrPtr(t->def, k); mb->profiler[k].trace = mb->profiler[k].trace || moduleOnly || instrFilter(p, mod, fcn); } } } s = s->outer; } mal_unset_lock(profileLock, "profileLock");#else stream_printf(GDKout, "# Monet not compiled for profiling\n");#endif}#line 1078 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_profiler.mx"voidresetFilter(Module cntxt, str mod, str fcn){#ifdef MALprofiler int j, k; Module s = cntxt; Symbol t; MalBlkPtr mb; (void) mod; (void) fcn; /* still unused */ if( ! profileLockInitialized) { MT_lock_init(&profileLock); profileLockInitialized= 1; } mal_set_lock(profileLock, "profileLock"); if (profileAll) { profileAll = FALSE; return; } while (s != NULL) { if (s->subscope) for (j = 0; j < MAXSCOPE; j++) if (s->subscope[j]) { for (t = s->subscope[j]; t != NULL; t = t->peer) { if( (mb=t->def)->profiler) for (k = 0; k < t->def->stop; k++) { mb->profiler[k].trace = FALSE; } } } s = s->outer; } mal_unset_lock(profileLock, "profileLock");#else stream_printf(GDKout, "# Monet not compiled for profiling\n");#endif}#line 1124 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_profiler.mx"static int TRACE_init=0;static BAT *TRACE_id_time=0;static BAT *TRACE_id_ticks=0;static BAT *TRACE_id_pc=0;static BAT *TRACE_id_modfcn=0;static BAT *TRACE_id_stmt=0;static BAT *TRACEcreate(str hnme, str tnme, int ht, int tt){ BAT *b; char buf[128]; snprintf(buf, 128, "trace_%s_%s", hnme, tnme); b = BATdescriptor(BBPindex(buf)); if (b) return b; b = BATnew(ht, tt, 256); if (b == NULL) GDKfatal("STAT_create: could not allocate."); BATkey(b, TRUE); BBPrename(b->batCacheid, buf); BATmode(b, PERSISTENT); BATcommit(b); return b;}voidinitTrace(void){ if (TRACE_init) return; /* already initialized */ mal_set_lock(mal_contextLock, "trace"); TRACE_id_time = TRACEcreate("id", "time", TYPE_int, TYPE_str); TRACE_id_ticks = TRACEcreate("id", "ticks", TYPE_int, TYPE_int); TRACE_id_pc = TRACEcreate("id", "pc", TYPE_int, TYPE_str); TRACE_id_modfcn = TRACEcreate("id", "modfcn", TYPE_int, TYPE_str); TRACE_id_stmt = TRACEcreate("id", "statement", TYPE_int, TYPE_str); TRACE_init = 1; mal_unset_lock(mal_contextLock, "trace");}#define CLEANUP(X) if(X) { BBPdecref((X)->batCacheid, TRUE); (X)->batPersistence= TRANSIENT; } (X)= NULL;strcleanupProfiler(){ mal_set_lock(mal_contextLock, "cleanup"); CLEANUP( TRACE_id_time ); CLEANUP( TRACE_id_pc ); CLEANUP( TRACE_id_modfcn ); CLEANUP( TRACE_id_stmt ); TRACE_init = 0; mal_unset_lock(mal_contextLock, "cleanup"); return MAL_SUCCEED;}voidstartTrace(void){ initTrace(); malProfileMode = TRUE; cachedProfiling = TRUE;}voidstopTrace(void){ initTrace(); malProfileMode = FALSE; cachedProfiling = FALSE;}voidsetCachedProfiling(void){ onlineProfiling = FALSE; offlineProfiling = FALSE; cachedProfiling = TRUE;}voidsetOnlineProfiling(void){ onlineProfiling = TRUE; offlineProfiling = FALSE; cachedProfiling = FALSE;}voidsetOfflineProfiling(void){ onlineProfiling = FALSE; offlineProfiling = TRUE; cachedProfiling = FALSE;}voidclearTrace(void){ initTrace(); /* drop all trace tables */ BATclear(TRACE_id_time); BATclear(TRACE_id_ticks); BATclear(TRACE_id_pc); BATclear(TRACE_id_modfcn); BATclear(TRACE_id_stmt);}BAT *getTrace(str nme){ if (strcmp(nme, "time") == 0) return TRACE_id_time; if (strcmp(nme, "ticks") == 0) return TRACE_id_ticks; if (strcmp(nme, "pc") == 0) return TRACE_id_pc; if (strcmp(nme, "modfcn") == 0) return TRACE_id_modfcn; if (strcmp(nme, "statement") == 0) return TRACE_id_stmt; return NULL;}voidcachedProfilerEvent(Module cntxt, MalBlkPtr mb, MalStkPtr stk, int pc){ /* static struct mallinfo prevMalloc; */ /* static struct rusage prevUsage; */ static int eventcounter;#ifdef HAVE_TIMES struct tms newTms;#endif /* struct mallinfo infoMalloc; */#ifdef HAVE_SYS_RESOURCE_H struct rusage infoUsage;#endif str stmt, c; int evnt; InstrPtr pci= getInstrPtr(mb,pc); (void) cntxt; if (TRACE_init == 0) return; if (delayswitch > 0) { /* first call to profiled */ delayswitch--; return; } if (delayswitch == 0) { delayswitch = -1; } if (!profileAll && mb->profiler[pc].trace == FALSE) return;#ifdef HAVE_TIMES times(&newTms);#endif /* infoMalloc = MT_mallinfo(); */#ifdef HAVE_SYS_RESOURCE_H getrusage(RUSAGE_SELF, &infoUsage);#endif mal_set_lock(profileLock, "profileLock"); evnt = TRACE_init++; /* update the Trace tables */ if (profileCounter[PROFpc].status) { char buf[1024]; snprintf(buf, 1024, "%s.%s[%d]", getModuleId(getInstrPtr(mb, 0)), getFunctionId(getInstrPtr(mb, 0)), getPC(mb, pci)); BUNins(TRACE_id_pc, &evnt, buf, FALSE); if (getModuleId(pci) && getFunctionId(pci)) { snprintf(buf, 1024, "%s.%s", getModuleId(pci), getFunctionId(pci)); } else { snprintf(buf, 1024, "%s", operatorName(pci->token)); } BUNins(TRACE_id_modfcn, &evnt, buf, FALSE); } if (profileCounter[PROFtime].status) { char *tbuf, *c; tbuf= ctime(&mb->profiler[pc].clock); c = strchr(tbuf, '\n'); if (c) { c[-5] = '"'; c[-4] = 0; } tbuf[10] = '"'; BUNins(TRACE_id_time, &evnt, tbuf + 10, FALSE); } if (profileCounter[PROFlabel].status) { int ticks = (int) (GDKusec() - mb->profiler[pc].clk); BUNins(TRACE_id_ticks, &evnt, &ticks, FALSE); } if (profileCounter[PROFstmt].status) { /* generate actual call statement */ stmt = call2str(MCgetClient(),mb, stk, getPC(mb, pci)); c = stmt; while (c && *c && (isspace((int) *c) || *c == '!')) c++; BUNins(TRACE_id_stmt, &evnt, c, FALSE); GDKfree(stmt); }/* The remainder requires their own BATs#ifdef HAVE_TIMES if( profileCounter[PROFcpu].status ){ log("%d,\t", newTms.tms_utime - mb->profiler[pc].timer.tms_utime); log("%d,\t", newTms.tms_cutime - mb->profiler[pc].timer.tms_cutime); log("%d,\t", newTms.tms_stime - mb->profiler[pc].timer.tms_stime); log("%d,\t", newTms.tms_cstime - mb->profiler[pc].timer.tms_cstime); }#endif if( profileCounter[PROFmemory].status ){#ifdef HAVE_SYS_RESOURCE_H log("%d,\t",infoUsage.ru_maxrss);#endif log("%d,\t", infoMalloc.arena-prevMalloc.arena); log("%d,\t", infoMalloc.ordblks-prevMalloc.ordblks); log("%d,\t", infoMalloc.smblks-prevMalloc.smblks); log("%d,\t", infoMalloc.hblkhd-prevMalloc.hblkhd); log("%d,\t", infoMalloc.hblks-prevMalloc.hblks); log("%d,\t", infoMalloc.fsmblks-prevMalloc.fsmblks); log("%d,\t", infoMalloc.uordblks-prevMalloc.uordblks); prevMalloc = infoMalloc; } if( profileCounter[PROFio].status ){#ifdef HAVE_SYS_RESOURCE_H log("%d,\t", infoUsage.ru_minflt- prevUsage.ru_minflt); log("%d,\t", infoUsage.ru_majflt- prevUsage.ru_majflt); log("%d,\t", infoUsage.ru_nswap- prevUsage.ru_nswap); log("%d,\t", infoUsage.ru_inblock- prevUsage.ru_inblock); log("%d,\t", infoUsage.ru_oublock- prevUsage.ru_oublock); log("%d,\t", infoUsage.ru_nvcsw- prevUsage.ru_nvcsw); log("%d,\t", infoUsage.ru_nivcsw- prevUsage.ru_nivcsw); prevUsage = infoUsage;#endif }*/ eventcounter++; mal_unset_lock(profileLock, "profileLock");}#line 1387 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_profiler.mx"voidprofileReport(Module cntxt, int outer, stream *out){#ifdef MALprofiler int j, k; Module s = cntxt; Symbol t; InstrPtr p; if (malProfileMode == 0) return; while (out && s != NULL) { if (s->subscope) for (j = 0; j < MAXSCOPE; j++) if (s->subscope[j]) for (t = s->subscope[j]; t != NULL; t = t->peer) { for (k = 0; k < t->def->stop; k++) { p = getInstrPtr(t->def, k); if( t->def->profiler && t->def->profiler[k].counter) printInstruction(out, t->def, p, LIST_MAL_INSTR); } } s = s->outer; } if (outer && cntxt->outer) profileReport(cntxt->outer, outer, out);#endif}#line 1421 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_profiler.mx"void initProfiler(MalBlkPtr mb){ if( mb->profiler) return; mb->profiler = (ProfPtr) GDKzalloc(mb->ssize*sizeof(ProfRecord));}#line 1426 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_profiler.mx"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -