X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2FProfiling.c;h=6d23bc2fe260c84d8e8a367984c7a82e26c8e3e7;hb=d8334d807812e40f67770ffc37608c0ce66f96b2;hp=028dc5a5091bf04fa8cdde31cf382ddf102f5b67;hpb=0065d5ab628975892cea1ec7303f968c3338cbe1;p=ghc-hetmet.git diff --git a/rts/Profiling.c b/rts/Profiling.c index 028dc5a..6d23bc2 100644 --- a/rts/Profiling.c +++ b/rts/Profiling.c @@ -10,19 +10,20 @@ #include "PosixSource.h" #include "Rts.h" + #include "RtsUtils.h" -#include "RtsFlags.h" #include "Profiling.h" -#include "Storage.h" #include "Proftimer.h" -#include "Timer.h" #include "ProfHeap.h" #include "Arena.h" #include "RetainerProfile.h" -#include "LdvProfile.h" #include +#ifdef DEBUG +#include "Trace.h" +#endif + /* * Profiling allocation arena. */ @@ -39,7 +40,7 @@ unsigned int HP_ID; /* figures for the profiling report. */ -static ullong total_alloc; +static StgWord64 total_alloc; static lnat total_prof_ticks; /* Globals for opening the profiling log file(s) @@ -183,6 +184,12 @@ initProfiling1 (void) } void +freeProfiling1 (void) +{ + arenaFree(prof_arena); +} + +void initProfiling2 (void) { CostCentreStack *ccs, *next; @@ -259,41 +266,66 @@ ccsSetSelected( CostCentreStack *ccs ) static void initProfilingLogFile(void) { - /* Initialise the log file name */ - prof_filename = arenaAlloc(prof_arena, strlen(prog_name) + 6); - sprintf(prof_filename, "%s.prof", prog_name); - - /* open the log file */ - if ((prof_file = fopen(prof_filename, "w")) == NULL) { - debugBelch("Can't open profiling report file %s\n", prof_filename); - RtsFlags.CcFlags.doCostCentres = 0; - // The following line was added by Sung; retainer/LDV profiling may need - // two output files, i.e., .prof/hp. - if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_RETAINER) - RtsFlags.ProfFlags.doHeapProfile = 0; - return; + char *prog; + + prog = arenaAlloc(prof_arena, strlen(prog_name) + 1); + strcpy(prog, prog_name); +#ifdef mingw32_HOST_OS + // on Windows, drop the .exe suffix if there is one + { + char *suff; + suff = strrchr(prog,'.'); + if (suff != NULL && !strcmp(suff,".exe")) { + *suff = '\0'; + } } +#endif - if (RtsFlags.CcFlags.doCostCentres == COST_CENTRES_XML) { - /* dump the time, and the profiling interval */ - fprintf(prof_file, "\"%s\"\n", time_str()); - fprintf(prof_file, "\"%d ms\"\n", TICK_MILLISECS); - - /* declare all the cost centres */ - { - CostCentre *cc; - for (cc = CC_LIST; cc != NULL; cc = cc->link) { - fprintf(prof_file, "%d %d \"%s\" \"%s\"\n", - CC_UQ, cc->ccID, cc->label, cc->module); - } - } + if (RtsFlags.CcFlags.doCostCentres == 0 && + RtsFlags.ProfFlags.doHeapProfile != HEAP_BY_RETAINER) + { + /* No need for the .prof file */ + prof_filename = NULL; + prof_file = NULL; + } + else + { + /* Initialise the log file name */ + prof_filename = arenaAlloc(prof_arena, strlen(prog) + 6); + sprintf(prof_filename, "%s.prof", prog); + + /* open the log file */ + if ((prof_file = fopen(prof_filename, "w")) == NULL) { + debugBelch("Can't open profiling report file %s\n", prof_filename); + RtsFlags.CcFlags.doCostCentres = 0; + // The following line was added by Sung; retainer/LDV profiling may need + // two output files, i.e., .prof/hp. + if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_RETAINER) + RtsFlags.ProfFlags.doHeapProfile = 0; + return; + } + + if (RtsFlags.CcFlags.doCostCentres == COST_CENTRES_XML) { + /* dump the time, and the profiling interval */ + fprintf(prof_file, "\"%s\"\n", time_str()); + fprintf(prof_file, "\"%d ms\"\n", RtsFlags.MiscFlags.tickInterval); + + /* declare all the cost centres */ + { + CostCentre *cc; + for (cc = CC_LIST; cc != NULL; cc = cc->link) { + fprintf(prof_file, "%d %ld \"%s\" \"%s\"\n", + CC_UQ, cc->ccID, cc->label, cc->module); + } + } + } } if (RtsFlags.ProfFlags.doHeapProfile) { /* Initialise the log file name */ - hp_filename = arenaAlloc(prof_arena, strlen(prog_name) + 6); - sprintf(hp_filename, "%s.hp", prog_name); - + hp_filename = arenaAlloc(prof_arena, strlen(prog) + 6); + sprintf(hp_filename, "%s.hp", prog); + /* open the log file */ if ((hp_file = fopen(hp_filename, "w")) == NULL) { debugBelch("Can't open profiling report file %s\n", @@ -353,11 +385,12 @@ CostCentreStack * PushCostCentre ( CostCentreStack *ccs, CostCentre *cc ) #define PushCostCentre _PushCostCentre { - IF_DEBUG(prof, - debugBelch("Pushing %s on ", cc->label); - debugCCS(ccs); - debugBelch("\n")); - return PushCostCentre(ccs,cc); + IF_DEBUG(prof, + traceBegin("pushing %s on ", cc->label); + debugCCS(ccs); + traceEnd();); + + return PushCostCentre(ccs,cc); } #endif @@ -533,10 +566,10 @@ DecCCS(CostCentreStack *ccs) { if (prof_file && RtsFlags.CcFlags.doCostCentres == COST_CENTRES_XML) { if (ccs->prevStack == EMPTY_STACK) - fprintf(prof_file, "%d %d 1 %d\n", CCS_UQ, + fprintf(prof_file, "%d %ld 1 %ld\n", CCS_UQ, ccs->ccsID, ccs->cc->ccID); else - fprintf(prof_file, "%d %d 2 %d %d\n", CCS_UQ, + fprintf(prof_file, "%d %ld 2 %ld %ld\n", CCS_UQ, ccs->ccsID, ccs->cc->ccID, ccs->prevStack->ccsID); } } @@ -546,10 +579,10 @@ DecBackEdge( CostCentreStack *ccs, CostCentreStack *oldccs ) { if (prof_file && RtsFlags.CcFlags.doCostCentres == COST_CENTRES_XML) { if (ccs->prevStack == EMPTY_STACK) - fprintf(prof_file, "%d %d 1 %d\n", CCS_UQ, + fprintf(prof_file, "%d %ld 1 %ld\n", CCS_UQ, ccs->ccsID, ccs->cc->ccID); else - fprintf(prof_file, "%d %d 2 %d %d\n", CCS_UQ, + fprintf(prof_file, "%d %ld 2 %ld %ld\n", CCS_UQ, ccs->ccsID, ccs->cc->ccID, oldccs->ccsID); } } @@ -663,7 +696,8 @@ report_per_cc_costs( void ) ); if (RtsFlags.CcFlags.doCostCentres >= COST_CENTRES_VERBOSE) { - fprintf(prof_file, " %5llu %9llu", (StgWord64)(cc->time_ticks), cc->mem_alloc); + fprintf(prof_file, " %5" FMT_Word64 " %9" FMT_Word64, + (StgWord64)(cc->time_ticks), cc->mem_alloc*sizeof(W_)); } fprintf(prof_file, "\n"); } @@ -730,11 +764,13 @@ reportCCSProfiling( void ) fprintf(prof_file, "\n\n"); fprintf(prof_file, "\ttotal time = %11.2f secs (%lu ticks @ %d ms)\n", - total_prof_ticks / (StgFloat) TICK_FREQUENCY, - total_prof_ticks, TICK_MILLISECS); + (double) total_prof_ticks * + (double) RtsFlags.MiscFlags.tickInterval / 1000, + (unsigned long) total_prof_ticks, + (int) RtsFlags.MiscFlags.tickInterval); fprintf(prof_file, "\ttotal alloc = %11s bytes", - ullong_format_string(total_alloc * sizeof(W_), + showStgWord64(total_alloc * sizeof(W_), temp, rtsTrue/*commas*/)); #if defined(PROFILING_DETAIL_COUNTS) @@ -768,7 +804,7 @@ reportCCS(CostCentreStack *ccs, nat indent) fprintf(prof_file, "%-*s%-*s %-50s", indent, "", 24-indent, cc->label, cc->module); - fprintf(prof_file, "%6d %11.0f %5.1f %5.1f %5.1f %5.1f", + fprintf(prof_file, "%6ld %11.0f %5.1f %5.1f %5.1f %5.1f", ccs->ccsID, (double) ccs->scc_count, total_prof_ticks == 0 ? 0.0 : ((double)ccs->time_ticks / (double)total_prof_ticks * 100.0), total_alloc == 0 ? 0.0 : ((double)ccs->mem_alloc / (double)total_alloc * 100.0), @@ -777,7 +813,8 @@ reportCCS(CostCentreStack *ccs, nat indent) ); if (RtsFlags.CcFlags.doCostCentres >= COST_CENTRES_VERBOSE) { - fprintf(prof_file, " %5llu %9llu", (StgWord64)(ccs->time_ticks), ccs->mem_alloc*sizeof(W_)); + fprintf(prof_file, " %5" FMT_Word64 " %9" FMT_Word64, + (StgWord64)(ccs->time_ticks), ccs->mem_alloc*sizeof(W_)); #if defined(PROFILING_DETAIL_COUNTS) fprintf(prof_file, " %8ld %8ld %8ld %8ld %8ld %8ld %8ld", ccs->mem_allocs, ccs->thunk_count, @@ -879,8 +916,6 @@ gen_XML_logfile( void ) reportCCS_XML(pruneCCSTree(CCS_MAIN)); fprintf(prof_file, " 0\n"); - - fclose(prof_file); } static void @@ -893,7 +928,7 @@ reportCCS_XML(CostCentreStack *ccs) cc = ccs->cc; - fprintf(prof_file, " 1 %d %llu %llu %llu", + fprintf(prof_file, " 1 %ld %" FMT_Word64 " %" FMT_Word64 " %" FMT_Word64, ccs->ccsID, ccs->scc_count, (StgWord64)(ccs->time_ticks), ccs->mem_alloc); for (i = ccs->indexTable; i != 0; i = i->next) {