1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2003
5 * Support for heap profiling
7 * ---------------------------------------------------------------------------*/
9 #if defined(DEBUG) && !defined(PROFILING)
10 #define DEBUG_HEAP_PROF
12 #undef DEBUG_HEAP_PROF
15 #if defined(PROFILING) || defined(DEBUG_HEAP_PROF)
17 #include "PosixSource.h"
21 #include "Profiling.h"
26 #include "RetainerProfile.h"
27 #include "LdvProfile.h"
35 /* -----------------------------------------------------------------------------
36 * era stores the current time period. It is the same as the
37 * number of censuses that have been performed.
40 * era must be no longer than LDV_SHIFT (15 or 30) bits.
42 * era is initialized to 1 in initHeapProfiling().
44 * max_era is initialized to 2^LDV_SHIFT in initHeapProfiling().
45 * When era reaches max_era, the profiling stops because a closure can
46 * store only up to (max_era - 1) as its creation or last use time.
47 * -------------------------------------------------------------------------- */
51 /* -----------------------------------------------------------------------------
54 * For most heap profiles each closure identity gets a simple count
55 * of live words in the heap at each census. However, if we're
56 * selecting by biography, then we have to keep the various
57 * lag/drag/void counters for each identity.
58 * -------------------------------------------------------------------------- */
59 typedef struct _counter {
64 int prim; // total size of 'inherently used' closures
65 int not_used; // total size of 'never used' closures
66 int used; // total size of 'used at least once' closures
67 int void_total; // current total size of 'destroyed without being used' closures
68 int drag_total; // current total size of 'used at least once and waiting to die'
71 struct _counter *next;
75 initLDVCtr( counter *ctr )
78 ctr->c.ldv.not_used = 0;
80 ctr->c.ldv.void_total = 0;
81 ctr->c.ldv.drag_total = 0;
85 double time; // the time in MUT time when the census is made
90 // for LDV profiling, when just displaying by LDV
98 static Census *censuses = NULL;
99 static nat n_censuses = 0;
102 static void aggregateCensusInfo( void );
105 static void dumpCensus( Census *census );
107 /* -----------------------------------------------------------------------------
108 Closure Type Profiling;
110 PROBABLY TOTALLY OUT OF DATE -- ToDo (SDM)
111 -------------------------------------------------------------------------- */
113 #ifdef DEBUG_HEAP_PROF
114 static char *type_names[] = {
120 , "CONSTR_NOCAF_STATIC"
156 , "MUT_ARR_PTRS_CLEAN"
157 , "MUT_ARR_PTRS_DIRTY"
158 , "MUT_ARR_PTRS_FROZEN"
172 #endif /* DEBUG_HEAP_PROF */
174 /* -----------------------------------------------------------------------------
175 * Find the "closure identity", which is a unique pointer reresenting
176 * the band to which this closure's heap space is attributed in the
178 * ------------------------------------------------------------------------- */
180 closureIdentity( StgClosure *p )
182 switch (RtsFlags.ProfFlags.doHeapProfile) {
186 return p->header.prof.ccs;
188 return p->header.prof.ccs->cc->module;
190 return get_itbl(p)->prof.closure_desc;
192 return get_itbl(p)->prof.closure_type;
193 case HEAP_BY_RETAINER:
194 // AFAIK, the only closures in the heap which might not have a
195 // valid retainer set are DEAD_WEAK closures.
196 if (isRetainerSetFieldValid(p))
197 return retainerSetOf(p);
202 case HEAP_BY_INFOPTR:
203 return (void *)((StgClosure *)p)->header.info;
204 case HEAP_BY_CLOSURE_TYPE:
205 return type_names[get_itbl(p)->type];
209 barf("closureIdentity");
213 /* --------------------------------------------------------------------------
214 * Profiling type predicates
215 * ----------------------------------------------------------------------- */
217 STATIC_INLINE rtsBool
218 doingLDVProfiling( void )
220 return (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV
221 || RtsFlags.ProfFlags.bioSelector != NULL);
224 STATIC_INLINE rtsBool
225 doingRetainerProfiling( void )
227 return (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_RETAINER
228 || RtsFlags.ProfFlags.retainerSelector != NULL);
230 #endif /* PROFILING */
232 // Precesses a closure 'c' being destroyed whose size is 'size'.
233 // Make sure that LDV_recordDead() is not invoked on 'inherently used' closures
234 // such as TSO; they should not be involved in computing dragNew or voidNew.
236 // Even though era is checked in both LdvCensusForDead() and
237 // LdvCensusKillAll(), we still need to make sure that era is > 0 because
238 // LDV_recordDead() may be called from elsewhere in the runtime system. E.g.,
239 // when a thunk is replaced by an indirection object.
243 LDV_recordDead( StgClosure *c, nat size )
249 if (era > 0 && closureSatisfiesConstraints(c)) {
250 size -= sizeofW(StgProfHeader);
251 ASSERT(LDVW(c) != 0);
252 if ((LDVW((c)) & LDV_STATE_MASK) == LDV_STATE_CREATE) {
253 t = (LDVW((c)) & LDV_CREATE_MASK) >> LDV_SHIFT;
255 if (RtsFlags.ProfFlags.bioSelector == NULL) {
256 censuses[t].void_total += (int)size;
257 censuses[era].void_total -= (int)size;
258 ASSERT(censuses[t].void_total < censuses[t].not_used);
260 id = closureIdentity(c);
261 ctr = lookupHashTable(censuses[t].hash, (StgWord)id);
262 ASSERT( ctr != NULL );
263 ctr->c.ldv.void_total += (int)size;
264 ctr = lookupHashTable(censuses[era].hash, (StgWord)id);
266 ctr = arenaAlloc(censuses[era].arena, sizeof(counter));
268 insertHashTable(censuses[era].hash, (StgWord)id, ctr);
270 ctr->next = censuses[era].ctrs;
271 censuses[era].ctrs = ctr;
273 ctr->c.ldv.void_total -= (int)size;
277 t = LDVW((c)) & LDV_LAST_MASK;
279 if (RtsFlags.ProfFlags.bioSelector == NULL) {
280 censuses[t+1].drag_total += size;
281 censuses[era].drag_total -= size;
284 id = closureIdentity(c);
285 ctr = lookupHashTable(censuses[t+1].hash, (StgWord)id);
286 ASSERT( ctr != NULL );
287 ctr->c.ldv.drag_total += (int)size;
288 ctr = lookupHashTable(censuses[era].hash, (StgWord)id);
290 ctr = arenaAlloc(censuses[era].arena, sizeof(counter));
292 insertHashTable(censuses[era].hash, (StgWord)id, ctr);
294 ctr->next = censuses[era].ctrs;
295 censuses[era].ctrs = ctr;
297 ctr->c.ldv.drag_total -= (int)size;
305 /* --------------------------------------------------------------------------
306 * Initialize censuses[era];
307 * ----------------------------------------------------------------------- */
309 initEra(Census *census)
311 census->hash = allocHashTable();
313 census->arena = newArena();
315 census->not_used = 0;
318 census->void_total = 0;
319 census->drag_total = 0;
322 /* --------------------------------------------------------------------------
323 * Increases era by 1 and initialize census[era].
324 * Reallocates gi[] and increases its size if needed.
325 * ----------------------------------------------------------------------- */
330 if (doingLDVProfiling()) {
333 if (era == max_era) {
334 errorBelch("maximum number of censuses reached; use +RTS -i to reduce");
335 stg_exit(EXIT_FAILURE);
338 if (era == n_censuses) {
340 censuses = stgReallocBytes(censuses, sizeof(Census) * n_censuses,
344 #endif /* PROFILING */
346 initEra( &censuses[era] );
349 /* -----------------------------------------------------------------------------
350 * DEBUG heap profiling, by info table
351 * -------------------------------------------------------------------------- */
353 #ifdef DEBUG_HEAP_PROF
355 static char *hp_filename;
357 void initProfiling1( void )
361 void initProfiling2( void )
363 if (RtsFlags.ProfFlags.doHeapProfile) {
364 /* Initialise the log file name */
365 hp_filename = stgMallocBytes(strlen(prog_name) + 6, "hpFileName");
366 sprintf(hp_filename, "%s.hp", prog_name);
368 /* open the log file */
369 if ((hp_file = fopen(hp_filename, "w")) == NULL) {
370 debugBelch("Can't open profiling report file %s\n",
372 RtsFlags.ProfFlags.doHeapProfile = 0;
380 void endProfiling( void )
384 #endif /* DEBUG_HEAP_PROF */
387 printSample(rtsBool beginSample, StgDouble sampleValue)
389 StgDouble fractionalPart, integralPart;
390 fractionalPart = modf(sampleValue, &integralPart);
391 fprintf(hp_file, "%s %d.%02d\n",
392 (beginSample ? "BEGIN_SAMPLE" : "END_SAMPLE"),
393 (int)integralPart, (int)(fractionalPart * 100));
396 /* --------------------------------------------------------------------------
397 * Initialize the heap profilier
398 * ----------------------------------------------------------------------- */
400 initHeapProfiling(void)
402 if (! RtsFlags.ProfFlags.doHeapProfile) {
407 if (doingLDVProfiling() && doingRetainerProfiling()) {
408 errorBelch("cannot mix -hb and -hr");
409 stg_exit(EXIT_FAILURE);
413 // we only count eras if we're doing LDV profiling. Otherwise era
416 if (doingLDVProfiling()) {
424 { // max_era = 2^LDV_SHIFT
427 for (p = 0; p < LDV_SHIFT; p++)
432 censuses = stgMallocBytes(sizeof(Census) * n_censuses, "initHeapProfiling");
434 initEra( &censuses[era] );
436 /* initProfilingLogFile(); */
437 fprintf(hp_file, "JOB \"%s", prog_name);
442 for(count = 1; count < prog_argc; count++)
443 fprintf(hp_file, " %s", prog_argv[count]);
444 fprintf(hp_file, " +RTS");
445 for(count = 0; count < rts_argc; count++)
446 fprintf(hp_file, " %s", rts_argv[count]);
448 #endif /* PROFILING */
450 fprintf(hp_file, "\"\n" );
452 fprintf(hp_file, "DATE \"%s\"\n", time_str());
454 fprintf(hp_file, "SAMPLE_UNIT \"seconds\"\n");
455 fprintf(hp_file, "VALUE_UNIT \"bytes\"\n");
457 printSample(rtsTrue, 0);
458 printSample(rtsFalse, 0);
460 #ifdef DEBUG_HEAP_PROF
461 DEBUG_LoadSymbols(prog_name);
465 if (doingRetainerProfiling()) {
466 initRetainerProfiling();
474 endHeapProfiling(void)
478 if (! RtsFlags.ProfFlags.doHeapProfile) {
483 if (doingRetainerProfiling()) {
484 endRetainerProfiling();
489 if (doingLDVProfiling()) {
492 aggregateCensusInfo();
493 for (t = 1; t < era; t++) {
494 dumpCensus( &censuses[t] );
499 seconds = mut_user_time();
500 printSample(rtsTrue, seconds);
501 printSample(rtsFalse, seconds);
509 buf_append(char *p, const char *q, char *end)
513 for (m = 0; p < end; p++, q++, m++) {
515 if (*q == '\0') { break; }
521 fprint_ccs(FILE *fp, CostCentreStack *ccs, nat max_length)
523 char buf[max_length+1], *p, *buf_end;
525 // MAIN on its own gets printed as "MAIN", otherwise we ignore MAIN.
526 if (ccs == CCS_MAIN) {
531 fprintf(fp, "(%ld)", ccs->ccsID);
534 buf_end = buf + max_length + 1;
536 // keep printing components of the stack until we run out of space
537 // in the buffer. If we run out of space, end with "...".
538 for (; ccs != NULL && ccs != CCS_MAIN; ccs = ccs->prevStack) {
540 // CAF cost centres print as M.CAF, but we leave the module
541 // name out of all the others to save space.
542 if (!strcmp(ccs->cc->label,"CAF")) {
543 p += buf_append(p, ccs->cc->module, buf_end);
544 p += buf_append(p, ".CAF", buf_end);
546 if (ccs->prevStack != NULL && ccs->prevStack != CCS_MAIN) {
547 p += buf_append(p, "/", buf_end);
549 p += buf_append(p, ccs->cc->label, buf_end);
553 sprintf(buf+max_length-4, "...");
557 fprintf(fp, "%s", buf);
559 #endif /* PROFILING */
562 strMatchesSelector( char* str, char* sel )
565 // debugBelch("str_matches_selector %s %s\n", str, sel);
567 // Compare str against wherever we've got to in sel.
569 while (*p != '\0' && *sel != ',' && *sel != '\0' && *p == *sel) {
572 // Match if all of str used and have reached the end of a sel fragment.
573 if (*p == '\0' && (*sel == ',' || *sel == '\0'))
576 // No match. Advance sel to the start of the next elem.
577 while (*sel != ',' && *sel != '\0') sel++;
578 if (*sel == ',') sel++;
580 /* Run out of sel ?? */
581 if (*sel == '\0') return rtsFalse;
585 /* -----------------------------------------------------------------------------
586 * Figure out whether a closure should be counted in this census, by
587 * testing against all the specified constraints.
588 * -------------------------------------------------------------------------- */
590 closureSatisfiesConstraints( StgClosure* p )
592 #ifdef DEBUG_HEAP_PROF
593 (void)p; /* keep gcc -Wall happy */
598 // The CCS has a selected field to indicate whether this closure is
599 // deselected by not being mentioned in the module, CC, or CCS
601 if (!p->header.prof.ccs->selected) {
605 if (RtsFlags.ProfFlags.descrSelector) {
606 b = strMatchesSelector( (get_itbl((StgClosure *)p))->prof.closure_desc,
607 RtsFlags.ProfFlags.descrSelector );
608 if (!b) return rtsFalse;
610 if (RtsFlags.ProfFlags.typeSelector) {
611 b = strMatchesSelector( (get_itbl((StgClosure *)p))->prof.closure_type,
612 RtsFlags.ProfFlags.typeSelector );
613 if (!b) return rtsFalse;
615 if (RtsFlags.ProfFlags.retainerSelector) {
618 // We must check that the retainer set is valid here. One
619 // reason it might not be valid is if this closure is a
620 // a newly deceased weak pointer (i.e. a DEAD_WEAK), since
621 // these aren't reached by the retainer profiler's traversal.
622 if (isRetainerSetFieldValid((StgClosure *)p)) {
623 rs = retainerSetOf((StgClosure *)p);
625 for (i = 0; i < rs->num; i++) {
626 b = strMatchesSelector( rs->element[i]->cc->label,
627 RtsFlags.ProfFlags.retainerSelector );
628 if (b) return rtsTrue;
635 #endif /* PROFILING */
638 /* -----------------------------------------------------------------------------
639 * Aggregate the heap census info for biographical profiling
640 * -------------------------------------------------------------------------- */
643 aggregateCensusInfo( void )
647 counter *c, *d, *ctrs;
650 if (!doingLDVProfiling()) return;
652 // Aggregate the LDV counters when displaying by biography.
653 if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
654 int void_total, drag_total;
656 // Now we compute void_total and drag_total for each census
657 // After the program has finished, the void_total field of
658 // each census contains the count of words that were *created*
659 // in this era and were eventually void. Conversely, if a
660 // void closure was destroyed in this era, it will be
661 // represented by a negative count of words in void_total.
663 // To get the count of live words that are void at each
664 // census, just propagate the void_total count forwards:
668 for (t = 1; t < era; t++) { // note: start at 1, not 0
669 void_total += censuses[t].void_total;
670 drag_total += censuses[t].drag_total;
671 censuses[t].void_total = void_total;
672 censuses[t].drag_total = drag_total;
674 ASSERT( censuses[t].void_total <= censuses[t].not_used );
675 // should be true because: void_total is the count of
676 // live words that are void at this census, which *must*
677 // be less than the number of live words that have not
680 ASSERT( censuses[t].drag_total <= censuses[t].used );
681 // similar reasoning as above.
687 // otherwise... we're doing a heap profile that is restricted to
688 // some combination of lag, drag, void or use. We've kept all the
689 // census info for all censuses so far, but we still need to
690 // aggregate the counters forwards.
693 acc = allocHashTable();
696 for (t = 1; t < era; t++) {
698 // first look through all the counters we're aggregating
699 for (c = ctrs; c != NULL; c = c->next) {
700 // if one of the totals is non-zero, then this closure
701 // type must be present in the heap at this census time...
702 d = lookupHashTable(censuses[t].hash, (StgWord)c->identity);
705 // if this closure identity isn't present in the
706 // census for this time period, then our running
707 // totals *must* be zero.
708 ASSERT(c->c.ldv.void_total == 0 && c->c.ldv.drag_total == 0);
710 // debugCCS(c->identity);
711 // debugBelch(" census=%d void_total=%d drag_total=%d\n",
712 // t, c->c.ldv.void_total, c->c.ldv.drag_total);
714 d->c.ldv.void_total += c->c.ldv.void_total;
715 d->c.ldv.drag_total += c->c.ldv.drag_total;
716 c->c.ldv.void_total = d->c.ldv.void_total;
717 c->c.ldv.drag_total = d->c.ldv.drag_total;
719 ASSERT( c->c.ldv.void_total >= 0 );
720 ASSERT( c->c.ldv.drag_total >= 0 );
724 // now look through the counters in this census to find new ones
725 for (c = censuses[t].ctrs; c != NULL; c = c->next) {
726 d = lookupHashTable(acc, (StgWord)c->identity);
728 d = arenaAlloc( arena, sizeof(counter) );
730 insertHashTable( acc, (StgWord)c->identity, d );
731 d->identity = c->identity;
734 d->c.ldv.void_total = c->c.ldv.void_total;
735 d->c.ldv.drag_total = c->c.ldv.drag_total;
737 ASSERT( c->c.ldv.void_total >= 0 );
738 ASSERT( c->c.ldv.drag_total >= 0 );
742 freeHashTable(acc, NULL);
747 /* -----------------------------------------------------------------------------
748 * Print out the results of a heap census.
749 * -------------------------------------------------------------------------- */
751 dumpCensus( Census *census )
756 printSample(rtsTrue, census->time);
759 if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
760 fprintf(hp_file, "VOID\t%lu\n", (unsigned long)(census->void_total) * sizeof(W_));
761 fprintf(hp_file, "LAG\t%lu\n",
762 (unsigned long)(census->not_used - census->void_total) * sizeof(W_));
763 fprintf(hp_file, "USE\t%lu\n",
764 (unsigned long)(census->used - census->drag_total) * sizeof(W_));
765 fprintf(hp_file, "INHERENT_USE\t%lu\n",
766 (unsigned long)(census->prim) * sizeof(W_));
767 fprintf(hp_file, "DRAG\t%lu\n",
768 (unsigned long)(census->drag_total) * sizeof(W_));
769 printSample(rtsFalse, census->time);
774 for (ctr = census->ctrs; ctr != NULL; ctr = ctr->next) {
777 if (RtsFlags.ProfFlags.bioSelector != NULL) {
779 if (strMatchesSelector("lag", RtsFlags.ProfFlags.bioSelector))
780 count += ctr->c.ldv.not_used - ctr->c.ldv.void_total;
781 if (strMatchesSelector("drag", RtsFlags.ProfFlags.bioSelector))
782 count += ctr->c.ldv.drag_total;
783 if (strMatchesSelector("void", RtsFlags.ProfFlags.bioSelector))
784 count += ctr->c.ldv.void_total;
785 if (strMatchesSelector("use", RtsFlags.ProfFlags.bioSelector))
786 count += ctr->c.ldv.used - ctr->c.ldv.drag_total;
790 count = ctr->c.resid;
793 ASSERT( count >= 0 );
795 if (count == 0) continue;
797 #ifdef DEBUG_HEAP_PROF
798 switch (RtsFlags.ProfFlags.doHeapProfile) {
799 case HEAP_BY_INFOPTR:
800 fprintf(hp_file, "%s", lookupGHCName(ctr->identity));
802 case HEAP_BY_CLOSURE_TYPE:
803 fprintf(hp_file, "%s", (char *)ctr->identity);
809 switch (RtsFlags.ProfFlags.doHeapProfile) {
811 fprint_ccs(hp_file, (CostCentreStack *)ctr->identity, 25);
816 fprintf(hp_file, "%s", (char *)ctr->identity);
818 case HEAP_BY_RETAINER:
820 RetainerSet *rs = (RetainerSet *)ctr->identity;
822 // it might be the distinguished retainer set rs_MANY:
823 if (rs == &rs_MANY) {
824 fprintf(hp_file, "MANY");
828 // Mark this retainer set by negating its id, because it
829 // has appeared in at least one census. We print the
830 // values of all such retainer sets into the log file at
831 // the end. A retainer set may exist but not feature in
832 // any censuses if it arose as the intermediate retainer
833 // set for some closure during retainer set calculation.
837 // report in the unit of bytes: * sizeof(StgWord)
838 printRetainerSetShort(hp_file, rs);
842 barf("dumpCensus; doHeapProfile");
846 fprintf(hp_file, "\t%lu\n", (unsigned long)count * sizeof(W_));
849 printSample(rtsFalse, census->time);
852 /* -----------------------------------------------------------------------------
853 * Code to perform a heap census.
854 * -------------------------------------------------------------------------- */
856 heapCensusChain( Census *census, bdescr *bd )
866 for (; bd != NULL; bd = bd->link) {
868 // HACK: ignore pinned blocks, because they contain gaps.
869 // It's not clear exactly what we'd like to do here, since we
870 // can't tell which objects in the block are actually alive.
871 // Perhaps the whole block should be counted as SYSTEM memory.
872 if (bd->flags & BF_PINNED) {
877 while (p < bd->free) {
878 info = get_itbl((StgClosure *)p);
881 switch (info->type) {
884 size = thunk_sizeW_fromITBL(info);
890 size = sizeofW(StgThunkHeader) + 2;
896 size = sizeofW(StgThunkHeader) + 1;
903 case IND_OLDGEN_PERM:
905 case SE_CAF_BLACKHOLE:
909 case CONSTR_CHARLIKE:
920 size = sizeW_fromITBL(info);
924 // Special case/Delicate Hack: INDs don't normally
925 // appear, since we're doing this heap census right
926 // after GC. However, GarbageCollect() also does
927 // resurrectThreads(), which can update some
928 // blackholes when it calls raiseAsync() on the
929 // resurrected threads. So we know that any IND will
930 // be the size of a BLACKHOLE.
931 size = BLACKHOLE_sizeW();
936 size = bco_sizeW((StgBCO *)p);
945 size = sizeW_fromITBL(info);
949 size = ap_sizeW((StgAP *)p);
953 size = pap_sizeW((StgPAP *)p);
957 size = ap_stack_sizeW((StgAP_STACK *)p);
962 size = arr_words_sizeW(stgCast(StgArrWords*,p));
965 case MUT_ARR_PTRS_CLEAN:
966 case MUT_ARR_PTRS_DIRTY:
967 case MUT_ARR_PTRS_FROZEN:
968 case MUT_ARR_PTRS_FROZEN0:
970 size = mut_arr_ptrs_sizeW((StgMutArrPtrs *)p);
975 #ifdef DEBUG_HEAP_PROF
976 size = tso_sizeW((StgTSO *)p);
979 if (RtsFlags.ProfFlags.includeTSOs) {
980 size = tso_sizeW((StgTSO *)p);
983 // Skip this TSO and move on to the next object
984 p += tso_sizeW((StgTSO *)p);
991 size = sizeofW(StgTRecHeader);
994 case TVAR_WAIT_QUEUE:
996 size = sizeofW(StgTVarWaitQueue);
1001 size = sizeofW(StgTVar);
1006 size = sizeofW(StgTRecChunk);
1010 barf("heapCensus, unknown object: %d", info->type);
1015 #ifdef DEBUG_HEAP_PROF
1018 // subtract the profiling overhead
1019 real_size = size - sizeofW(StgProfHeader);
1022 if (closureSatisfiesConstraints((StgClosure*)p)) {
1024 if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
1026 census->prim += real_size;
1027 else if ((LDVW(p) & LDV_STATE_MASK) == LDV_STATE_CREATE)
1028 census->not_used += real_size;
1030 census->used += real_size;
1034 identity = closureIdentity((StgClosure *)p);
1036 if (identity != NULL) {
1037 ctr = lookupHashTable( census->hash, (StgWord)identity );
1040 if (RtsFlags.ProfFlags.bioSelector != NULL) {
1042 ctr->c.ldv.prim += real_size;
1043 else if ((LDVW(p) & LDV_STATE_MASK) == LDV_STATE_CREATE)
1044 ctr->c.ldv.not_used += real_size;
1046 ctr->c.ldv.used += real_size;
1050 ctr->c.resid += real_size;
1053 ctr = arenaAlloc( census->arena, sizeof(counter) );
1055 insertHashTable( census->hash, (StgWord)identity, ctr );
1056 ctr->identity = identity;
1057 ctr->next = census->ctrs;
1061 if (RtsFlags.ProfFlags.bioSelector != NULL) {
1063 ctr->c.ldv.prim = real_size;
1064 else if ((LDVW(p) & LDV_STATE_MASK) == LDV_STATE_CREATE)
1065 ctr->c.ldv.not_used = real_size;
1067 ctr->c.ldv.used = real_size;
1071 ctr->c.resid = real_size;
1089 census = &censuses[era];
1090 census->time = mut_user_time();
1092 // calculate retainer sets if necessary
1094 if (doingRetainerProfiling()) {
1100 stat_startHeapCensus();
1103 // Traverse the heap, collecting the census info
1105 // First the small_alloc_list: we have to fix the free pointer at
1106 // the end by calling tidyAllocatedLists() first.
1107 tidyAllocateLists();
1108 heapCensusChain( census, small_alloc_list );
1110 // Now traverse the heap in each generation/step.
1111 if (RtsFlags.GcFlags.generations == 1) {
1112 heapCensusChain( census, g0s0->blocks );
1114 for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
1115 for (s = 0; s < generations[g].n_steps; s++) {
1116 heapCensusChain( census, generations[g].steps[s].blocks );
1117 // Are we interested in large objects? might be
1118 // confusing to include the stack in a heap profile.
1119 heapCensusChain( census, generations[g].steps[s].large_objects );
1124 // dump out the census info
1126 // We can't generate any info for LDV profiling until
1127 // the end of the run...
1128 if (!doingLDVProfiling())
1129 dumpCensus( census );
1131 dumpCensus( census );
1135 // free our storage, unless we're keeping all the census info for
1136 // future restriction by biography.
1138 if (RtsFlags.ProfFlags.bioSelector == NULL)
1141 freeHashTable( census->hash, NULL/* don't free the elements */ );
1142 arenaFree( census->arena );
1143 census->hash = NULL;
1144 census->arena = NULL;
1147 // we're into the next time period now
1151 stat_endHeapCensus();
1155 #endif /* PROFILING || DEBUG_HEAP_PROF */