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"
27 #include "RetainerProfile.h"
28 #include "LdvProfile.h"
36 /* -----------------------------------------------------------------------------
37 * era stores the current time period. It is the same as the
38 * number of censuses that have been performed.
41 * era must be no longer than LDV_SHIFT (15 or 30) bits.
43 * era is initialized to 1 in initHeapProfiling().
45 * max_era is initialized to 2^LDV_SHIFT in initHeapProfiling().
46 * When era reaches max_era, the profiling stops because a closure can
47 * store only up to (max_era - 1) as its creation or last use time.
48 * -------------------------------------------------------------------------- */
52 /* -----------------------------------------------------------------------------
55 * For most heap profiles each closure identity gets a simple count
56 * of live words in the heap at each census. However, if we're
57 * selecting by biography, then we have to keep the various
58 * lag/drag/void counters for each identity.
59 * -------------------------------------------------------------------------- */
60 typedef struct _counter {
65 int prim; // total size of 'inherently used' closures
66 int not_used; // total size of 'never used' closures
67 int used; // total size of 'used at least once' closures
68 int void_total; // current total size of 'destroyed without being used' closures
69 int drag_total; // current total size of 'used at least once and waiting to die'
72 struct _counter *next;
76 initLDVCtr( counter *ctr )
79 ctr->c.ldv.not_used = 0;
81 ctr->c.ldv.void_total = 0;
82 ctr->c.ldv.drag_total = 0;
86 double time; // the time in MUT time when the census is made
91 // for LDV profiling, when just displaying by LDV
99 static Census *censuses = NULL;
100 static nat n_censuses = 0;
103 static void aggregateCensusInfo( void );
106 static void dumpCensus( Census *census );
108 /* -----------------------------------------------------------------------------
109 Closure Type Profiling;
111 PROBABLY TOTALLY OUT OF DATE -- ToDo (SDM)
112 -------------------------------------------------------------------------- */
114 #ifdef DEBUG_HEAP_PROF
115 static char *type_names[] = {
121 , "CONSTR_NOCAF_STATIC"
158 , "MUT_ARR_PTRS_FROZEN"
171 #endif /* DEBUG_HEAP_PROF */
173 /* -----------------------------------------------------------------------------
174 * Find the "closure identity", which is a unique pointer reresenting
175 * the band to which this closure's heap space is attributed in the
177 * ------------------------------------------------------------------------- */
179 closureIdentity( StgClosure *p )
181 switch (RtsFlags.ProfFlags.doHeapProfile) {
185 return p->header.prof.ccs;
187 return p->header.prof.ccs->cc->module;
189 return get_itbl(p)->prof.closure_desc;
191 return get_itbl(p)->prof.closure_type;
192 case HEAP_BY_RETAINER:
193 // AFAIK, the only closures in the heap which might not have a
194 // valid retainer set are DEAD_WEAK closures.
195 if (isRetainerSetFieldValid(p))
196 return retainerSetOf(p);
201 case HEAP_BY_INFOPTR:
202 return (void *)((StgClosure *)p)->header.info;
203 case HEAP_BY_CLOSURE_TYPE:
204 return type_names[get_itbl(p)->type];
208 barf("closureIdentity");
212 /* --------------------------------------------------------------------------
213 * Profiling type predicates
214 * ----------------------------------------------------------------------- */
216 STATIC_INLINE rtsBool
217 doingLDVProfiling( void )
219 return (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV
220 || RtsFlags.ProfFlags.bioSelector != NULL);
223 STATIC_INLINE rtsBool
224 doingRetainerProfiling( void )
226 return (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_RETAINER
227 || RtsFlags.ProfFlags.retainerSelector != NULL);
229 #endif /* PROFILING */
231 // Precesses a closure 'c' being destroyed whose size is 'size'.
232 // Make sure that LDV_recordDead() is not invoked on 'inherently used' closures
233 // such as TSO; they should not be involved in computing dragNew or voidNew.
235 // Even though era is checked in both LdvCensusForDead() and
236 // LdvCensusKillAll(), we still need to make sure that era is > 0 because
237 // LDV_recordDead() may be called from elsewhere in the runtime system. E.g.,
238 // when a thunk is replaced by an indirection object.
242 LDV_recordDead( StgClosure *c, nat size )
248 if (era > 0 && closureSatisfiesConstraints(c)) {
249 size -= sizeofW(StgProfHeader);
250 ASSERT(LDVW(c) != 0);
251 if ((LDVW((c)) & LDV_STATE_MASK) == LDV_STATE_CREATE) {
252 t = (LDVW((c)) & LDV_CREATE_MASK) >> LDV_SHIFT;
254 if (RtsFlags.ProfFlags.bioSelector == NULL) {
255 censuses[t].void_total += (int)size;
256 censuses[era].void_total -= (int)size;
258 id = closureIdentity(c);
259 ctr = lookupHashTable(censuses[t].hash, (StgWord)id);
260 ASSERT( ctr != NULL );
261 ctr->c.ldv.void_total += (int)size;
262 ctr = lookupHashTable(censuses[era].hash, (StgWord)id);
264 ctr = arenaAlloc(censuses[era].arena, sizeof(counter));
266 insertHashTable(censuses[era].hash, (StgWord)id, ctr);
268 ctr->next = censuses[era].ctrs;
269 censuses[era].ctrs = ctr;
271 ctr->c.ldv.void_total -= (int)size;
275 t = LDVW((c)) & LDV_LAST_MASK;
277 if (RtsFlags.ProfFlags.bioSelector == NULL) {
278 censuses[t+1].drag_total += size;
279 censuses[era].drag_total -= size;
282 id = closureIdentity(c);
283 ctr = lookupHashTable(censuses[t+1].hash, (StgWord)id);
284 ASSERT( ctr != NULL );
285 ctr->c.ldv.drag_total += (int)size;
286 ctr = lookupHashTable(censuses[era].hash, (StgWord)id);
288 ctr = arenaAlloc(censuses[era].arena, sizeof(counter));
290 insertHashTable(censuses[era].hash, (StgWord)id, ctr);
292 ctr->next = censuses[era].ctrs;
293 censuses[era].ctrs = ctr;
295 ctr->c.ldv.drag_total -= (int)size;
303 /* --------------------------------------------------------------------------
304 * Initialize censuses[era];
305 * ----------------------------------------------------------------------- */
307 initEra(Census *census)
309 census->hash = allocHashTable();
311 census->arena = newArena();
313 census->not_used = 0;
316 census->void_total = 0;
317 census->drag_total = 0;
320 /* --------------------------------------------------------------------------
321 * Increases era by 1 and initialize census[era].
322 * Reallocates gi[] and increases its size if needed.
323 * ----------------------------------------------------------------------- */
328 if (doingLDVProfiling()) {
331 if (era == max_era) {
332 errorBelch("maximum number of censuses reached; use +RTS -i to reduce");
333 stg_exit(EXIT_FAILURE);
336 if (era == n_censuses) {
338 censuses = stgReallocBytes(censuses, sizeof(Census) * n_censuses,
342 #endif /* PROFILING */
344 initEra( &censuses[era] );
347 /* -----------------------------------------------------------------------------
348 * DEBUG heap profiling, by info table
349 * -------------------------------------------------------------------------- */
351 #ifdef DEBUG_HEAP_PROF
353 static char *hp_filename;
355 void initProfiling1( void )
359 void initProfiling2( void )
361 if (RtsFlags.ProfFlags.doHeapProfile) {
362 /* Initialise the log file name */
363 hp_filename = stgMallocBytes(strlen(prog_name) + 6, "hpFileName");
364 sprintf(hp_filename, "%s.hp", prog_name);
366 /* open the log file */
367 if ((hp_file = fopen(hp_filename, "w")) == NULL) {
368 debugBelch("Can't open profiling report file %s\n",
370 RtsFlags.ProfFlags.doHeapProfile = 0;
378 void endProfiling( void )
382 #endif /* DEBUG_HEAP_PROF */
385 printSample(rtsBool beginSample, StgDouble sampleValue)
387 StgDouble fractionalPart, integralPart;
388 fractionalPart = modf(sampleValue, &integralPart);
389 fprintf(hp_file, "%s %d.%02d\n",
390 (beginSample ? "BEGIN_SAMPLE" : "END_SAMPLE"),
391 (int)integralPart, (int)(fractionalPart * 100 + 0.5));
394 /* --------------------------------------------------------------------------
395 * Initialize the heap profilier
396 * ----------------------------------------------------------------------- */
398 initHeapProfiling(void)
400 if (! RtsFlags.ProfFlags.doHeapProfile) {
405 if (doingLDVProfiling() && doingRetainerProfiling()) {
406 errorBelch("cannot mix -hb and -hr");
411 // we only count eras if we're doing LDV profiling. Otherwise era
414 if (doingLDVProfiling()) {
422 { // max_era = 2^LDV_SHIFT
425 for (p = 0; p < LDV_SHIFT; p++)
430 censuses = stgMallocBytes(sizeof(Census) * n_censuses, "initHeapProfiling");
432 initEra( &censuses[era] );
434 /* initProfilingLogFile(); */
435 fprintf(hp_file, "JOB \"%s", prog_name);
440 for(count = 1; count < prog_argc; count++)
441 fprintf(hp_file, " %s", prog_argv[count]);
442 fprintf(hp_file, " +RTS");
443 for(count = 0; count < rts_argc; count++)
444 fprintf(hp_file, " %s", rts_argv[count]);
446 #endif /* PROFILING */
448 fprintf(hp_file, "\"\n" );
450 fprintf(hp_file, "DATE \"%s\"\n", time_str());
452 fprintf(hp_file, "SAMPLE_UNIT \"seconds\"\n");
453 fprintf(hp_file, "VALUE_UNIT \"bytes\"\n");
455 printSample(rtsTrue, 0);
456 printSample(rtsFalse, 0);
458 #ifdef DEBUG_HEAP_PROF
459 DEBUG_LoadSymbols(prog_name);
463 if (doingRetainerProfiling()) {
464 initRetainerProfiling();
472 endHeapProfiling(void)
476 if (! RtsFlags.ProfFlags.doHeapProfile) {
481 if (doingRetainerProfiling()) {
482 endRetainerProfiling();
487 if (doingLDVProfiling()) {
490 aggregateCensusInfo();
491 for (t = 1; t < era; t++) {
492 dumpCensus( &censuses[t] );
497 seconds = mut_user_time();
498 printSample(rtsTrue, seconds);
499 printSample(rtsFalse, seconds);
507 buf_append(char *p, const char *q, char *end)
511 for (m = 0; p < end; p++, q++, m++) {
513 if (*q == '\0') { break; }
519 fprint_ccs(FILE *fp, CostCentreStack *ccs, nat max_length)
521 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, "...");
556 next_offset += written;
559 fprintf(fp, "%s", buf);
561 #endif /* PROFILING */
564 strMatchesSelector( char* str, char* sel )
567 // debugBelch("str_matches_selector %s %s\n", str, sel);
569 // Compare str against wherever we've got to in sel.
571 while (*p != '\0' && *sel != ',' && *sel != '\0' && *p == *sel) {
574 // Match if all of str used and have reached the end of a sel fragment.
575 if (*p == '\0' && (*sel == ',' || *sel == '\0'))
578 // No match. Advance sel to the start of the next elem.
579 while (*sel != ',' && *sel != '\0') sel++;
580 if (*sel == ',') sel++;
582 /* Run out of sel ?? */
583 if (*sel == '\0') return rtsFalse;
587 /* -----------------------------------------------------------------------------
588 * Figure out whether a closure should be counted in this census, by
589 * testing against all the specified constraints.
590 * -------------------------------------------------------------------------- */
592 closureSatisfiesConstraints( StgClosure* p )
594 #ifdef DEBUG_HEAP_PROF
595 (void)p; /* keep gcc -Wall happy */
600 // The CCS has a selected field to indicate whether this closure is
601 // deselected by not being mentioned in the module, CC, or CCS
603 if (!p->header.prof.ccs->selected) {
607 if (RtsFlags.ProfFlags.descrSelector) {
608 b = strMatchesSelector( (get_itbl((StgClosure *)p))->prof.closure_desc,
609 RtsFlags.ProfFlags.descrSelector );
610 if (!b) return rtsFalse;
612 if (RtsFlags.ProfFlags.typeSelector) {
613 b = strMatchesSelector( (get_itbl((StgClosure *)p))->prof.closure_type,
614 RtsFlags.ProfFlags.typeSelector );
615 if (!b) return rtsFalse;
617 if (RtsFlags.ProfFlags.retainerSelector) {
620 // We must check that the retainer set is valid here. One
621 // reason it might not be valid is if this closure is a
622 // a newly deceased weak pointer (i.e. a DEAD_WEAK), since
623 // these aren't reached by the retainer profiler's traversal.
624 if (isRetainerSetFieldValid((StgClosure *)p)) {
625 rs = retainerSetOf((StgClosure *)p);
627 for (i = 0; i < rs->num; i++) {
628 b = strMatchesSelector( rs->element[i]->cc->label,
629 RtsFlags.ProfFlags.retainerSelector );
630 if (b) return rtsTrue;
637 #endif /* PROFILING */
640 /* -----------------------------------------------------------------------------
641 * Aggregate the heap census info for biographical profiling
642 * -------------------------------------------------------------------------- */
645 aggregateCensusInfo( void )
649 counter *c, *d, *ctrs;
652 if (!doingLDVProfiling()) return;
654 // Aggregate the LDV counters when displaying by biography.
655 if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
656 int void_total, drag_total;
658 // Now we compute void_total and drag_total for each census
661 for (t = 1; t < era; t++) { // note: start at 1, not 0
662 void_total += censuses[t].void_total;
663 drag_total += censuses[t].drag_total;
664 censuses[t].void_total = void_total;
665 censuses[t].drag_total = drag_total;
666 ASSERT( censuses[t].void_total <= censuses[t].not_used );
667 ASSERT( censuses[t].drag_total <= censuses[t].used );
673 // otherwise... we're doing a heap profile that is restricted to
674 // some combination of lag, drag, void or use. We've kept all the
675 // census info for all censuses so far, but we still need to
676 // aggregate the counters forwards.
679 acc = allocHashTable();
682 for (t = 1; t < era; t++) {
684 // first look through all the counters we're aggregating
685 for (c = ctrs; c != NULL; c = c->next) {
686 // if one of the totals is non-zero, then this closure
687 // type must be present in the heap at this census time...
688 d = lookupHashTable(censuses[t].hash, (StgWord)c->identity);
691 // if this closure identity isn't present in the
692 // census for this time period, then our running
693 // totals *must* be zero.
694 ASSERT(c->c.ldv.void_total == 0 && c->c.ldv.drag_total == 0);
696 // debugCCS(c->identity);
697 // debugBelch(" census=%d void_total=%d drag_total=%d\n",
698 // t, c->c.ldv.void_total, c->c.ldv.drag_total);
700 d->c.ldv.void_total += c->c.ldv.void_total;
701 d->c.ldv.drag_total += c->c.ldv.drag_total;
702 c->c.ldv.void_total = d->c.ldv.void_total;
703 c->c.ldv.drag_total = d->c.ldv.drag_total;
705 ASSERT( c->c.ldv.void_total >= 0 );
706 ASSERT( c->c.ldv.drag_total >= 0 );
710 // now look through the counters in this census to find new ones
711 for (c = censuses[t].ctrs; c != NULL; c = c->next) {
712 d = lookupHashTable(acc, (StgWord)c->identity);
714 d = arenaAlloc( arena, sizeof(counter) );
716 insertHashTable( acc, (StgWord)c->identity, d );
717 d->identity = c->identity;
720 d->c.ldv.void_total = c->c.ldv.void_total;
721 d->c.ldv.drag_total = c->c.ldv.drag_total;
723 ASSERT( c->c.ldv.void_total >= 0 );
724 ASSERT( c->c.ldv.drag_total >= 0 );
728 freeHashTable(acc, NULL);
733 /* -----------------------------------------------------------------------------
734 * Print out the results of a heap census.
735 * -------------------------------------------------------------------------- */
737 dumpCensus( Census *census )
742 printSample(rtsTrue, census->time);
745 if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
746 fprintf(hp_file, "VOID\t%lu\n", (unsigned long)(census->void_total) * sizeof(W_));
747 fprintf(hp_file, "LAG\t%lu\n",
748 (unsigned long)(census->not_used - census->void_total) * sizeof(W_));
749 fprintf(hp_file, "USE\t%lu\n",
750 (unsigned long)(census->used - census->drag_total) * sizeof(W_));
751 fprintf(hp_file, "INHERENT_USE\t%lu\n",
752 (unsigned long)(census->prim) * sizeof(W_));
753 fprintf(hp_file, "DRAG\t%lu\n",
754 (unsigned long)(census->drag_total) * sizeof(W_));
755 printSample(rtsFalse, census->time);
760 for (ctr = census->ctrs; ctr != NULL; ctr = ctr->next) {
763 if (RtsFlags.ProfFlags.bioSelector != NULL) {
765 if (strMatchesSelector("lag", RtsFlags.ProfFlags.bioSelector))
766 count += ctr->c.ldv.not_used - ctr->c.ldv.void_total;
767 if (strMatchesSelector("drag", RtsFlags.ProfFlags.bioSelector))
768 count += ctr->c.ldv.drag_total;
769 if (strMatchesSelector("void", RtsFlags.ProfFlags.bioSelector))
770 count += ctr->c.ldv.void_total;
771 if (strMatchesSelector("use", RtsFlags.ProfFlags.bioSelector))
772 count += ctr->c.ldv.used - ctr->c.ldv.drag_total;
776 count = ctr->c.resid;
779 ASSERT( count >= 0 );
781 if (count == 0) continue;
783 #ifdef DEBUG_HEAP_PROF
784 switch (RtsFlags.ProfFlags.doHeapProfile) {
785 case HEAP_BY_INFOPTR:
786 fprintf(hp_file, "%s", lookupGHCName(ctr->identity));
788 case HEAP_BY_CLOSURE_TYPE:
789 fprintf(hp_file, "%s", (char *)ctr->identity);
795 switch (RtsFlags.ProfFlags.doHeapProfile) {
797 fprint_ccs(hp_file, (CostCentreStack *)ctr->identity, 25);
802 fprintf(hp_file, "%s", (char *)ctr->identity);
804 case HEAP_BY_RETAINER:
806 RetainerSet *rs = (RetainerSet *)ctr->identity;
808 // it might be the distinguished retainer set rs_MANY:
809 if (rs == &rs_MANY) {
810 fprintf(hp_file, "MANY");
814 // Mark this retainer set by negating its id, because it
815 // has appeared in at least one census. We print the
816 // values of all such retainer sets into the log file at
817 // the end. A retainer set may exist but not feature in
818 // any censuses if it arose as the intermediate retainer
819 // set for some closure during retainer set calculation.
823 // report in the unit of bytes: * sizeof(StgWord)
824 printRetainerSetShort(hp_file, rs);
828 barf("dumpCensus; doHeapProfile");
832 fprintf(hp_file, "\t%lu\n", (unsigned long)count * sizeof(W_));
835 printSample(rtsFalse, census->time);
838 /* -----------------------------------------------------------------------------
839 * Code to perform a heap census.
840 * -------------------------------------------------------------------------- */
842 heapCensusChain( Census *census, bdescr *bd )
852 for (; bd != NULL; bd = bd->link) {
854 // HACK: ignore pinned blocks, because they contain gaps.
855 // It's not clear exactly what we'd like to do here, since we
856 // can't tell which objects in the block are actually alive.
857 // Perhaps the whole block should be counted as SYSTEM memory.
858 if (bd->flags & BF_PINNED) {
863 while (p < bd->free) {
864 info = get_itbl((StgClosure *)p);
867 switch (info->type) {
870 size = thunk_sizeW_fromITBL(info);
876 size = sizeofW(StgHeader) + stg_max(MIN_UPD_SIZE,2);
882 size = sizeofW(StgHeader) + stg_max(MIN_UPD_SIZE,1);
889 case IND_OLDGEN_PERM:
891 case SE_CAF_BLACKHOLE:
895 case CONSTR_CHARLIKE:
906 size = sizeW_fromITBL(info);
910 // Special case/Delicate Hack: INDs don't normally
911 // appear, since we're doing this heap census right
912 // after GC. However, GarbageCollect() also does
913 // resurrectThreads(), which can update some
914 // blackholes when it calls raiseAsync() on the
915 // resurrected threads. So we know that any IND will
916 // be the size of a BLACKHOLE.
917 size = BLACKHOLE_sizeW();
922 size = bco_sizeW((StgBCO *)p);
930 size = sizeW_fromITBL(info);
934 size = ap_sizeW((StgAP *)p);
938 size = pap_sizeW((StgPAP *)p);
942 size = ap_stack_sizeW((StgAP_STACK *)p);
947 size = arr_words_sizeW(stgCast(StgArrWords*,p));
951 case MUT_ARR_PTRS_FROZEN:
952 case MUT_ARR_PTRS_FROZEN0:
954 size = mut_arr_ptrs_sizeW((StgMutArrPtrs *)p);
959 #ifdef DEBUG_HEAP_PROF
960 size = tso_sizeW((StgTSO *)p);
963 if (RtsFlags.ProfFlags.includeTSOs) {
964 size = tso_sizeW((StgTSO *)p);
967 // Skip this TSO and move on to the next object
968 p += tso_sizeW((StgTSO *)p);
975 size = sizeofW(StgTRecHeader);
978 case TVAR_WAIT_QUEUE:
980 size = sizeofW(StgTVarWaitQueue);
985 size = sizeofW(StgTVar);
990 size = sizeofW(StgTRecChunk);
994 barf("heapCensus, unknown object: %d", info->type);
999 #ifdef DEBUG_HEAP_PROF
1002 // subtract the profiling overhead
1003 real_size = size - sizeofW(StgProfHeader);
1006 if (closureSatisfiesConstraints((StgClosure*)p)) {
1008 if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
1010 census->prim += real_size;
1011 else if ((LDVW(p) & LDV_STATE_MASK) == LDV_STATE_CREATE)
1012 census->not_used += real_size;
1014 census->used += real_size;
1018 identity = closureIdentity((StgClosure *)p);
1020 if (identity != NULL) {
1021 ctr = lookupHashTable( census->hash, (StgWord)identity );
1024 if (RtsFlags.ProfFlags.bioSelector != NULL) {
1026 ctr->c.ldv.prim += real_size;
1027 else if ((LDVW(p) & LDV_STATE_MASK) == LDV_STATE_CREATE)
1028 ctr->c.ldv.not_used += real_size;
1030 ctr->c.ldv.used += real_size;
1034 ctr->c.resid += real_size;
1037 ctr = arenaAlloc( census->arena, sizeof(counter) );
1039 insertHashTable( census->hash, (StgWord)identity, ctr );
1040 ctr->identity = identity;
1041 ctr->next = census->ctrs;
1045 if (RtsFlags.ProfFlags.bioSelector != NULL) {
1047 ctr->c.ldv.prim = real_size;
1048 else if ((LDVW(p) & LDV_STATE_MASK) == LDV_STATE_CREATE)
1049 ctr->c.ldv.not_used = real_size;
1051 ctr->c.ldv.used = real_size;
1055 ctr->c.resid = real_size;
1073 census = &censuses[era];
1074 census->time = mut_user_time();
1076 // calculate retainer sets if necessary
1078 if (doingRetainerProfiling()) {
1084 stat_startHeapCensus();
1087 // Traverse the heap, collecting the census info
1089 // First the small_alloc_list: we have to fix the free pointer at
1090 // the end by calling tidyAllocatedLists() first.
1091 tidyAllocateLists();
1092 heapCensusChain( census, small_alloc_list );
1094 // Now traverse the heap in each generation/step.
1095 if (RtsFlags.GcFlags.generations == 1) {
1096 heapCensusChain( census, g0s0->blocks );
1098 for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
1099 for (s = 0; s < generations[g].n_steps; s++) {
1100 heapCensusChain( census, generations[g].steps[s].blocks );
1101 // Are we interested in large objects? might be
1102 // confusing to include the stack in a heap profile.
1103 heapCensusChain( census, generations[g].steps[s].large_objects );
1108 // dump out the census info
1110 // We can't generate any info for LDV profiling until
1111 // the end of the run...
1112 if (!doingLDVProfiling())
1113 dumpCensus( census );
1115 dumpCensus( census );
1119 // free our storage, unless we're keeping all the census info for
1120 // future restriction by biography.
1122 if (RtsFlags.ProfFlags.bioSelector == NULL)
1125 freeHashTable( census->hash, NULL/* don't free the elements */ );
1126 arenaFree( census->arena );
1127 census->hash = NULL;
1128 census->arena = NULL;
1131 // we're into the next time period now
1135 stat_endHeapCensus();
1139 #endif /* PROFILING || DEBUG_HEAP_PROF */