diff options
author | Ömer Sinan Ağacan <omeragacan@gmail.com> | 2019-01-02 13:13:59 +0300 |
---|---|---|
committer | Ömer Sinan Ağacan <omeragacan@gmail.com> | 2019-01-03 00:36:07 -0500 |
commit | 6e4e63764aaf558cf177c2a9c2da345b2a360ea6 (patch) | |
tree | e58576be66b4bc1cbf8a6d4c25a4a9ba4858f3d4 | |
parent | 05cd2319152183b3f44bca3561374217d6af5546 (diff) | |
download | haskell-6e4e63764aaf558cf177c2a9c2da345b2a360ea6.tar.gz |
Minor refactoring and documentation in profiling RTS code
-rw-r--r-- | includes/rts/prof/CCS.h | 14 | ||||
-rw-r--r-- | rts/Profiling.c | 61 |
2 files changed, 29 insertions, 46 deletions
diff --git a/includes/rts/prof/CCS.h b/includes/rts/prof/CCS.h index 4805063a0f..89c9fd2b13 100644 --- a/includes/rts/prof/CCS.h +++ b/includes/rts/prof/CCS.h @@ -36,7 +36,7 @@ typedef struct CostCentre_ { StgWord64 mem_alloc; // align 8 (Note [struct alignment]) StgWord time_ticks; - StgInt is_caf; // non-zero for a CAF cost centre + StgBool is_caf; // true <=> CAF cost centre struct CostCentre_ *link; } CostCentre; @@ -96,9 +96,8 @@ void startProfTimer ( void ); #define EMPTY_TABLE NULL /* Constants used to set is_caf flag on CostCentres */ -#define CC_IS_CAF 'c' /* 'c' => *is* a CAF cc */ -#define CC_NOT_CAF 0 - +#define CC_IS_CAF true +#define CC_NOT_CAF false /* ----------------------------------------------------------------------------- * Data Structures * ---------------------------------------------------------------------------*/ @@ -109,10 +108,15 @@ void startProfTimer ( void ); // result). typedef struct IndexTable_ { + // Just a linked list of (cc, ccs) pairs, where the `ccs` is the result of + // pushing `cc` to the owner of the index table (another CostCentreStack). CostCentre *cc; CostCentreStack *ccs; struct IndexTable_ *next; - uint32_t back_edge; + // back_edge is true when `cc` is already in the stack, so pushing it + // truncates or drops (see RECURSION_DROPS and RECURSION_TRUNCATES in + // Profiling.c). + bool back_edge; } IndexTable; diff --git a/rts/Profiling.c b/rts/Profiling.c index 9f1a442951..7abad59b1f 100644 --- a/rts/Profiling.c +++ b/rts/Profiling.c @@ -118,7 +118,7 @@ static CostCentreStack * pruneCCSTree ( CostCentreStack *ccs ); static CostCentreStack * actualPush ( CostCentreStack *, CostCentre * ); static CostCentreStack * isInIndexTable ( IndexTable *, CostCentre * ); static IndexTable * addToIndexTable ( IndexTable *, CostCentreStack *, - CostCentre *, unsigned int ); + CostCentre *, bool ); static void ccsSetSelected ( CostCentreStack *ccs ); static void aggregateCCCosts( CostCentreStack *ccs ); @@ -476,48 +476,23 @@ ccsSetSelected (CostCentreStack *ccs) Cost-centre stack manipulation -------------------------------------------------------------------------- */ -#if defined(DEBUG) -CostCentreStack * _pushCostCentre ( CostCentreStack *ccs, CostCentre *cc ); -CostCentreStack * -pushCostCentre ( CostCentreStack *ccs, CostCentre *cc ) -#define pushCostCentre _pushCostCentre -{ - IF_DEBUG(prof, - traceBegin("pushing %s on ", cc->label); - debugCCS(ccs); - traceEnd();); - - return pushCostCentre(ccs,cc); -} -#endif - /* Append ccs1 to ccs2 (ignoring any CAF cost centre at the root of ccs1 */ - -#if defined(DEBUG) -CostCentreStack *_appendCCS ( CostCentreStack *ccs1, CostCentreStack *ccs2 ); CostCentreStack * appendCCS ( CostCentreStack *ccs1, CostCentreStack *ccs2 ) -#define appendCCS _appendCCS { - IF_DEBUG(prof, - if (ccs1 != ccs2) { - debugBelch("Appending "); - debugCCS(ccs1); - debugBelch(" to "); - debugCCS(ccs2); - debugBelch("\n");}); - return appendCCS(ccs1,ccs2); -} -#endif + IF_DEBUG(prof, + if (ccs1 != ccs2) { + debugBelch("Appending "); + debugCCS(ccs1); + debugBelch(" to "); + debugCCS(ccs2); + debugBelch("\n");}); -CostCentreStack * -appendCCS ( CostCentreStack *ccs1, CostCentreStack *ccs2 ) -{ if (ccs1 == ccs2) { return ccs1; } - if (ccs2 == CCS_MAIN || ccs2->cc->is_caf == CC_IS_CAF) { + if (ccs2 == CCS_MAIN || ccs2->cc->is_caf) { // stop at a CAF element return ccs1; } @@ -532,8 +507,12 @@ appendCCS ( CostCentreStack *ccs1, CostCentreStack *ccs2 ) CostCentreStack * pushCostCentre (CostCentreStack *ccs, CostCentre *cc) { - CostCentreStack *temp_ccs, *ret; - IndexTable *ixtable; + IF_DEBUG(prof, + traceBegin("pushing %s on ", cc->label); + debugCCS(ccs); + traceEnd();); + + CostCentreStack *ret; if (ccs == EMPTY_STACK) { ACQUIRE_LOCK(&ccs_mutex); @@ -545,8 +524,8 @@ pushCostCentre (CostCentreStack *ccs, CostCentre *cc) return ccs; } else { // check if we've already memoized this stack - ixtable = ccs->indexTable; - temp_ccs = isInIndexTable(ixtable,cc); + IndexTable *ixtable = ccs->indexTable; + CostCentreStack *temp_ccs = isInIndexTable(ixtable,cc); if (temp_ccs != EMPTY_STACK) { return temp_ccs; @@ -585,7 +564,7 @@ pushCostCentre (CostCentreStack *ccs, CostCentre *cc) new_ccs = ccs; #endif ccs->indexTable = addToIndexTable (ccs->indexTable, - new_ccs, cc, 1); + new_ccs, cc, true); ret = new_ccs; } else { ret = actualPush (ccs,cc); @@ -649,7 +628,7 @@ actualPush_ (CostCentreStack *ccs, CostCentre *cc, CostCentreStack *new_ccs) /* update the memoization table for the parent stack */ ccs->indexTable = addToIndexTable(ccs->indexTable, new_ccs, cc, - 0/*not a back edge*/); + false/*not a back edge*/); /* return a pointer to the new stack */ return new_ccs; @@ -674,7 +653,7 @@ isInIndexTable(IndexTable *it, CostCentre *cc) static IndexTable * addToIndexTable (IndexTable *it, CostCentreStack *new_ccs, - CostCentre *cc, unsigned int back_edge) + CostCentre *cc, bool back_edge) { IndexTable *new_it; |