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;
259 id = closureIdentity(c);
260 ctr = lookupHashTable(censuses[t].hash, (StgWord)id);
261 ASSERT( ctr != NULL );
262 ctr->c.ldv.void_total += (int)size;
263 ctr = lookupHashTable(censuses[era].hash, (StgWord)id);
265 ctr = arenaAlloc(censuses[era].arena, sizeof(counter));
267 insertHashTable(censuses[era].hash, (StgWord)id, ctr);
269 ctr->next = censuses[era].ctrs;
270 censuses[era].ctrs = ctr;
272 ctr->c.ldv.void_total -= (int)size;
276 t = LDVW((c)) & LDV_LAST_MASK;
278 if (RtsFlags.ProfFlags.bioSelector == NULL) {
279 censuses[t+1].drag_total += size;
280 censuses[era].drag_total -= size;
283 id = closureIdentity(c);
284 ctr = lookupHashTable(censuses[t+1].hash, (StgWord)id);
285 ASSERT( ctr != NULL );
286 ctr->c.ldv.drag_total += (int)size;
287 ctr = lookupHashTable(censuses[era].hash, (StgWord)id);
289 ctr = arenaAlloc(censuses[era].arena, sizeof(counter));
291 insertHashTable(censuses[era].hash, (StgWord)id, ctr);
293 ctr->next = censuses[era].ctrs;
294 censuses[era].ctrs = ctr;
296 ctr->c.ldv.drag_total -= (int)size;
304 /* --------------------------------------------------------------------------
305 * Initialize censuses[era];
306 * ----------------------------------------------------------------------- */
308 initEra(Census *census)
310 census->hash = allocHashTable();
312 census->arena = newArena();
314 census->not_used = 0;
317 census->void_total = 0;
318 census->drag_total = 0;
321 /* --------------------------------------------------------------------------
322 * Increases era by 1 and initialize census[era].
323 * Reallocates gi[] and increases its size if needed.
324 * ----------------------------------------------------------------------- */
329 if (doingLDVProfiling()) {
332 if (era == max_era) {
333 errorBelch("maximum number of censuses reached; use +RTS -i to reduce");
334 stg_exit(EXIT_FAILURE);
337 if (era == n_censuses) {
339 censuses = stgReallocBytes(censuses, sizeof(Census) * n_censuses,
343 #endif /* PROFILING */
345 initEra( &censuses[era] );
348 /* -----------------------------------------------------------------------------
349 * DEBUG heap profiling, by info table
350 * -------------------------------------------------------------------------- */
352 #ifdef DEBUG_HEAP_PROF
354 static char *hp_filename;
356 void initProfiling1( void )
360 void initProfiling2( void )
362 if (RtsFlags.ProfFlags.doHeapProfile) {
363 /* Initialise the log file name */
364 hp_filename = stgMallocBytes(strlen(prog_name) + 6, "hpFileName");
365 sprintf(hp_filename, "%s.hp", prog_name);
367 /* open the log file */
368 if ((hp_file = fopen(hp_filename, "w")) == NULL) {
369 debugBelch("Can't open profiling report file %s\n",
371 RtsFlags.ProfFlags.doHeapProfile = 0;
379 void endProfiling( void )
383 #endif /* DEBUG_HEAP_PROF */
386 printSample(rtsBool beginSample, StgDouble sampleValue)
388 StgDouble fractionalPart, integralPart;
389 fractionalPart = modf(sampleValue, &integralPart);
390 fprintf(hp_file, "%s %d.%02d\n",
391 (beginSample ? "BEGIN_SAMPLE" : "END_SAMPLE"),
392 (int)integralPart, (int)(fractionalPart * 100));
395 /* --------------------------------------------------------------------------
396 * Initialize the heap profilier
397 * ----------------------------------------------------------------------- */
399 initHeapProfiling(void)
401 if (! RtsFlags.ProfFlags.doHeapProfile) {
406 if (doingLDVProfiling() && doingRetainerProfiling()) {
407 errorBelch("cannot mix -hb and -hr");
408 stg_exit(EXIT_FAILURE);
412 // we only count eras if we're doing LDV profiling. Otherwise era
415 if (doingLDVProfiling()) {
423 { // max_era = 2^LDV_SHIFT
426 for (p = 0; p < LDV_SHIFT; p++)
431 censuses = stgMallocBytes(sizeof(Census) * n_censuses, "initHeapProfiling");
433 initEra( &censuses[era] );
435 /* initProfilingLogFile(); */
436 fprintf(hp_file, "JOB \"%s", prog_name);
441 for(count = 1; count < prog_argc; count++)
442 fprintf(hp_file, " %s", prog_argv[count]);
443 fprintf(hp_file, " +RTS");
444 for(count = 0; count < rts_argc; count++)
445 fprintf(hp_file, " %s", rts_argv[count]);
447 #endif /* PROFILING */
449 fprintf(hp_file, "\"\n" );
451 fprintf(hp_file, "DATE \"%s\"\n", time_str());
453 fprintf(hp_file, "SAMPLE_UNIT \"seconds\"\n");
454 fprintf(hp_file, "VALUE_UNIT \"bytes\"\n");
456 printSample(rtsTrue, 0);
457 printSample(rtsFalse, 0);
459 #ifdef DEBUG_HEAP_PROF
460 DEBUG_LoadSymbols(prog_name);
464 if (doingRetainerProfiling()) {
465 initRetainerProfiling();
473 endHeapProfiling(void)
477 if (! RtsFlags.ProfFlags.doHeapProfile) {
482 if (doingRetainerProfiling()) {
483 endRetainerProfiling();
488 if (doingLDVProfiling()) {
491 aggregateCensusInfo();
492 for (t = 1; t < era; t++) {
493 dumpCensus( &censuses[t] );
498 seconds = mut_user_time();
499 printSample(rtsTrue, seconds);
500 printSample(rtsFalse, seconds);
508 buf_append(char *p, const char *q, char *end)
512 for (m = 0; p < end; p++, q++, m++) {
514 if (*q == '\0') { break; }
520 fprint_ccs(FILE *fp, CostCentreStack *ccs, nat max_length)
522 char buf[max_length+1], *p, *buf_end;
524 // MAIN on its own gets printed as "MAIN", otherwise we ignore MAIN.
525 if (ccs == CCS_MAIN) {
530 fprintf(fp, "(%ld)", ccs->ccsID);
533 buf_end = buf + max_length + 1;
535 // keep printing components of the stack until we run out of space
536 // in the buffer. If we run out of space, end with "...".
537 for (; ccs != NULL && ccs != CCS_MAIN; ccs = ccs->prevStack) {
539 // CAF cost centres print as M.CAF, but we leave the module
540 // name out of all the others to save space.
541 if (!strcmp(ccs->cc->label,"CAF")) {
542 p += buf_append(p, ccs->cc->module, buf_end);
543 p += buf_append(p, ".CAF", buf_end);
545 if (ccs->prevStack != NULL && ccs->prevStack != CCS_MAIN) {
546 p += buf_append(p, "/", buf_end);
548 p += buf_append(p, ccs->cc->label, buf_end);
552 sprintf(buf+max_length-4, "...");
556 fprintf(fp, "%s", buf);
558 #endif /* PROFILING */
561 strMatchesSelector( char* str, char* sel )
564 // debugBelch("str_matches_selector %s %s\n", str, sel);
566 // Compare str against wherever we've got to in sel.
568 while (*p != '\0' && *sel != ',' && *sel != '\0' && *p == *sel) {
571 // Match if all of str used and have reached the end of a sel fragment.
572 if (*p == '\0' && (*sel == ',' || *sel == '\0'))
575 // No match. Advance sel to the start of the next elem.
576 while (*sel != ',' && *sel != '\0') sel++;
577 if (*sel == ',') sel++;
579 /* Run out of sel ?? */
580 if (*sel == '\0') return rtsFalse;
584 /* -----------------------------------------------------------------------------
585 * Figure out whether a closure should be counted in this census, by
586 * testing against all the specified constraints.
587 * -------------------------------------------------------------------------- */
589 closureSatisfiesConstraints( StgClosure* p )
591 #ifdef DEBUG_HEAP_PROF
592 (void)p; /* keep gcc -Wall happy */
597 // The CCS has a selected field to indicate whether this closure is
598 // deselected by not being mentioned in the module, CC, or CCS
600 if (!p->header.prof.ccs->selected) {
604 if (RtsFlags.ProfFlags.descrSelector) {
605 b = strMatchesSelector( (get_itbl((StgClosure *)p))->prof.closure_desc,
606 RtsFlags.ProfFlags.descrSelector );
607 if (!b) return rtsFalse;
609 if (RtsFlags.ProfFlags.typeSelector) {
610 b = strMatchesSelector( (get_itbl((StgClosure *)p))->prof.closure_type,
611 RtsFlags.ProfFlags.typeSelector );
612 if (!b) return rtsFalse;
614 if (RtsFlags.ProfFlags.retainerSelector) {
617 // We must check that the retainer set is valid here. One
618 // reason it might not be valid is if this closure is a
619 // a newly deceased weak pointer (i.e. a DEAD_WEAK), since
620 // these aren't reached by the retainer profiler's traversal.
621 if (isRetainerSetFieldValid((StgClosure *)p)) {
622 rs = retainerSetOf((StgClosure *)p);
624 for (i = 0; i < rs->num; i++) {
625 b = strMatchesSelector( rs->element[i]->cc->label,
626 RtsFlags.ProfFlags.retainerSelector );
627 if (b) return rtsTrue;
634 #endif /* PROFILING */
637 /* -----------------------------------------------------------------------------
638 * Aggregate the heap census info for biographical profiling
639 * -------------------------------------------------------------------------- */
642 aggregateCensusInfo( void )
646 counter *c, *d, *ctrs;
649 if (!doingLDVProfiling()) return;
651 // Aggregate the LDV counters when displaying by biography.
652 if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
653 int void_total, drag_total;
655 // Now we compute void_total and drag_total for each census
658 for (t = 1; t < era; t++) { // note: start at 1, not 0
659 void_total += censuses[t].void_total;
660 drag_total += censuses[t].drag_total;
661 censuses[t].void_total = void_total;
662 censuses[t].drag_total = drag_total;
663 ASSERT( censuses[t].void_total <= censuses[t].not_used );
664 ASSERT( censuses[t].drag_total <= censuses[t].used );
670 // otherwise... we're doing a heap profile that is restricted to
671 // some combination of lag, drag, void or use. We've kept all the
672 // census info for all censuses so far, but we still need to
673 // aggregate the counters forwards.
676 acc = allocHashTable();
679 for (t = 1; t < era; t++) {
681 // first look through all the counters we're aggregating
682 for (c = ctrs; c != NULL; c = c->next) {
683 // if one of the totals is non-zero, then this closure
684 // type must be present in the heap at this census time...
685 d = lookupHashTable(censuses[t].hash, (StgWord)c->identity);
688 // if this closure identity isn't present in the
689 // census for this time period, then our running
690 // totals *must* be zero.
691 ASSERT(c->c.ldv.void_total == 0 && c->c.ldv.drag_total == 0);
693 // debugCCS(c->identity);
694 // debugBelch(" census=%d void_total=%d drag_total=%d\n",
695 // t, c->c.ldv.void_total, c->c.ldv.drag_total);
697 d->c.ldv.void_total += c->c.ldv.void_total;
698 d->c.ldv.drag_total += c->c.ldv.drag_total;
699 c->c.ldv.void_total = d->c.ldv.void_total;
700 c->c.ldv.drag_total = d->c.ldv.drag_total;
702 ASSERT( c->c.ldv.void_total >= 0 );
703 ASSERT( c->c.ldv.drag_total >= 0 );
707 // now look through the counters in this census to find new ones
708 for (c = censuses[t].ctrs; c != NULL; c = c->next) {
709 d = lookupHashTable(acc, (StgWord)c->identity);
711 d = arenaAlloc( arena, sizeof(counter) );
713 insertHashTable( acc, (StgWord)c->identity, d );
714 d->identity = c->identity;
717 d->c.ldv.void_total = c->c.ldv.void_total;
718 d->c.ldv.drag_total = c->c.ldv.drag_total;
720 ASSERT( c->c.ldv.void_total >= 0 );
721 ASSERT( c->c.ldv.drag_total >= 0 );
725 freeHashTable(acc, NULL);
730 /* -----------------------------------------------------------------------------
731 * Print out the results of a heap census.
732 * -------------------------------------------------------------------------- */
734 dumpCensus( Census *census )
739 printSample(rtsTrue, census->time);
742 if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
743 fprintf(hp_file, "VOID\t%lu\n", (unsigned long)(census->void_total) * sizeof(W_));
744 fprintf(hp_file, "LAG\t%lu\n",
745 (unsigned long)(census->not_used - census->void_total) * sizeof(W_));
746 fprintf(hp_file, "USE\t%lu\n",
747 (unsigned long)(census->used - census->drag_total) * sizeof(W_));
748 fprintf(hp_file, "INHERENT_USE\t%lu\n",
749 (unsigned long)(census->prim) * sizeof(W_));
750 fprintf(hp_file, "DRAG\t%lu\n",
751 (unsigned long)(census->drag_total) * sizeof(W_));
752 printSample(rtsFalse, census->time);
757 for (ctr = census->ctrs; ctr != NULL; ctr = ctr->next) {
760 if (RtsFlags.ProfFlags.bioSelector != NULL) {
762 if (strMatchesSelector("lag", RtsFlags.ProfFlags.bioSelector))
763 count += ctr->c.ldv.not_used - ctr->c.ldv.void_total;
764 if (strMatchesSelector("drag", RtsFlags.ProfFlags.bioSelector))
765 count += ctr->c.ldv.drag_total;
766 if (strMatchesSelector("void", RtsFlags.ProfFlags.bioSelector))
767 count += ctr->c.ldv.void_total;
768 if (strMatchesSelector("use", RtsFlags.ProfFlags.bioSelector))
769 count += ctr->c.ldv.used - ctr->c.ldv.drag_total;
773 count = ctr->c.resid;
776 ASSERT( count >= 0 );
778 if (count == 0) continue;
780 #ifdef DEBUG_HEAP_PROF
781 switch (RtsFlags.ProfFlags.doHeapProfile) {
782 case HEAP_BY_INFOPTR:
783 fprintf(hp_file, "%s", lookupGHCName(ctr->identity));
785 case HEAP_BY_CLOSURE_TYPE:
786 fprintf(hp_file, "%s", (char *)ctr->identity);
792 switch (RtsFlags.ProfFlags.doHeapProfile) {
794 fprint_ccs(hp_file, (CostCentreStack *)ctr->identity, 25);
799 fprintf(hp_file, "%s", (char *)ctr->identity);
801 case HEAP_BY_RETAINER:
803 RetainerSet *rs = (RetainerSet *)ctr->identity;
805 // it might be the distinguished retainer set rs_MANY:
806 if (rs == &rs_MANY) {
807 fprintf(hp_file, "MANY");
811 // Mark this retainer set by negating its id, because it
812 // has appeared in at least one census. We print the
813 // values of all such retainer sets into the log file at
814 // the end. A retainer set may exist but not feature in
815 // any censuses if it arose as the intermediate retainer
816 // set for some closure during retainer set calculation.
820 // report in the unit of bytes: * sizeof(StgWord)
821 printRetainerSetShort(hp_file, rs);
825 barf("dumpCensus; doHeapProfile");
829 fprintf(hp_file, "\t%lu\n", (unsigned long)count * sizeof(W_));
832 printSample(rtsFalse, census->time);
835 /* -----------------------------------------------------------------------------
836 * Code to perform a heap census.
837 * -------------------------------------------------------------------------- */
839 heapCensusChain( Census *census, bdescr *bd )
849 for (; bd != NULL; bd = bd->link) {
851 // HACK: ignore pinned blocks, because they contain gaps.
852 // It's not clear exactly what we'd like to do here, since we
853 // can't tell which objects in the block are actually alive.
854 // Perhaps the whole block should be counted as SYSTEM memory.
855 if (bd->flags & BF_PINNED) {
860 while (p < bd->free) {
861 info = get_itbl((StgClosure *)p);
864 switch (info->type) {
867 size = thunk_sizeW_fromITBL(info);
873 size = sizeofW(StgThunkHeader) + 2;
879 size = sizeofW(StgThunkHeader) + 1;
886 case IND_OLDGEN_PERM:
888 case SE_CAF_BLACKHOLE:
892 case CONSTR_CHARLIKE:
903 size = sizeW_fromITBL(info);
907 // Special case/Delicate Hack: INDs don't normally
908 // appear, since we're doing this heap census right
909 // after GC. However, GarbageCollect() also does
910 // resurrectThreads(), which can update some
911 // blackholes when it calls raiseAsync() on the
912 // resurrected threads. So we know that any IND will
913 // be the size of a BLACKHOLE.
914 size = BLACKHOLE_sizeW();
919 size = bco_sizeW((StgBCO *)p);
928 size = sizeW_fromITBL(info);
932 size = ap_sizeW((StgAP *)p);
936 size = pap_sizeW((StgPAP *)p);
940 size = ap_stack_sizeW((StgAP_STACK *)p);
945 size = arr_words_sizeW(stgCast(StgArrWords*,p));
948 case MUT_ARR_PTRS_CLEAN:
949 case MUT_ARR_PTRS_DIRTY:
950 case MUT_ARR_PTRS_FROZEN:
951 case MUT_ARR_PTRS_FROZEN0:
953 size = mut_arr_ptrs_sizeW((StgMutArrPtrs *)p);
958 #ifdef DEBUG_HEAP_PROF
959 size = tso_sizeW((StgTSO *)p);
962 if (RtsFlags.ProfFlags.includeTSOs) {
963 size = tso_sizeW((StgTSO *)p);
966 // Skip this TSO and move on to the next object
967 p += tso_sizeW((StgTSO *)p);
974 size = sizeofW(StgTRecHeader);
977 case TVAR_WAIT_QUEUE:
979 size = sizeofW(StgTVarWaitQueue);
984 size = sizeofW(StgTVar);
989 size = sizeofW(StgTRecChunk);
993 barf("heapCensus, unknown object: %d", info->type);
998 #ifdef DEBUG_HEAP_PROF
1001 // subtract the profiling overhead
1002 real_size = size - sizeofW(StgProfHeader);
1005 if (closureSatisfiesConstraints((StgClosure*)p)) {
1007 if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
1009 census->prim += real_size;
1010 else if ((LDVW(p) & LDV_STATE_MASK) == LDV_STATE_CREATE)
1011 census->not_used += real_size;
1013 census->used += real_size;
1017 identity = closureIdentity((StgClosure *)p);
1019 if (identity != NULL) {
1020 ctr = lookupHashTable( census->hash, (StgWord)identity );
1023 if (RtsFlags.ProfFlags.bioSelector != NULL) {
1025 ctr->c.ldv.prim += real_size;
1026 else if ((LDVW(p) & LDV_STATE_MASK) == LDV_STATE_CREATE)
1027 ctr->c.ldv.not_used += real_size;
1029 ctr->c.ldv.used += real_size;
1033 ctr->c.resid += real_size;
1036 ctr = arenaAlloc( census->arena, sizeof(counter) );
1038 insertHashTable( census->hash, (StgWord)identity, ctr );
1039 ctr->identity = identity;
1040 ctr->next = census->ctrs;
1044 if (RtsFlags.ProfFlags.bioSelector != NULL) {
1046 ctr->c.ldv.prim = real_size;
1047 else if ((LDVW(p) & LDV_STATE_MASK) == LDV_STATE_CREATE)
1048 ctr->c.ldv.not_used = real_size;
1050 ctr->c.ldv.used = real_size;
1054 ctr->c.resid = real_size;
1072 census = &censuses[era];
1073 census->time = mut_user_time();
1075 // calculate retainer sets if necessary
1077 if (doingRetainerProfiling()) {
1083 stat_startHeapCensus();
1086 // Traverse the heap, collecting the census info
1088 // First the small_alloc_list: we have to fix the free pointer at
1089 // the end by calling tidyAllocatedLists() first.
1090 tidyAllocateLists();
1091 heapCensusChain( census, small_alloc_list );
1093 // Now traverse the heap in each generation/step.
1094 if (RtsFlags.GcFlags.generations == 1) {
1095 heapCensusChain( census, g0s0->blocks );
1097 for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
1098 for (s = 0; s < generations[g].n_steps; s++) {
1099 heapCensusChain( census, generations[g].steps[s].blocks );
1100 // Are we interested in large objects? might be
1101 // confusing to include the stack in a heap profile.
1102 heapCensusChain( census, generations[g].steps[s].large_objects );
1107 // dump out the census info
1109 // We can't generate any info for LDV profiling until
1110 // the end of the run...
1111 if (!doingLDVProfiling())
1112 dumpCensus( census );
1114 dumpCensus( census );
1118 // free our storage, unless we're keeping all the census info for
1119 // future restriction by biography.
1121 if (RtsFlags.ProfFlags.bioSelector == NULL)
1124 freeHashTable( census->hash, NULL/* don't free the elements */ );
1125 arenaFree( census->arena );
1126 census->hash = NULL;
1127 census->arena = NULL;
1130 // we're into the next time period now
1134 stat_endHeapCensus();
1138 #endif /* PROFILING || DEBUG_HEAP_PROF */