1 /* ----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2003
5 * Support for heap profiling
7 * --------------------------------------------------------------------------*/
9 #include "PosixSource.h"
13 #include "Profiling.h"
17 #include "RetainerProfile.h"
18 #include "LdvProfile.h"
24 /* -----------------------------------------------------------------------------
25 * era stores the current time period. It is the same as the
26 * number of censuses that have been performed.
29 * era must be no longer than LDV_SHIFT (15 or 30) bits.
31 * era is initialized to 1 in initHeapProfiling().
33 * max_era is initialized to 2^LDV_SHIFT in initHeapProfiling().
34 * When era reaches max_era, the profiling stops because a closure can
35 * store only up to (max_era - 1) as its creation or last use time.
36 * -------------------------------------------------------------------------- */
40 /* -----------------------------------------------------------------------------
43 * For most heap profiles each closure identity gets a simple count
44 * of live words in the heap at each census. However, if we're
45 * selecting by biography, then we have to keep the various
46 * lag/drag/void counters for each identity.
47 * -------------------------------------------------------------------------- */
48 typedef struct _counter {
53 int prim; // total size of 'inherently used' closures
54 int not_used; // total size of 'never used' closures
55 int used; // total size of 'used at least once' closures
56 int void_total; // current total size of 'destroyed without being used' closures
57 int drag_total; // current total size of 'used at least once and waiting to die'
60 struct _counter *next;
64 initLDVCtr( counter *ctr )
67 ctr->c.ldv.not_used = 0;
69 ctr->c.ldv.void_total = 0;
70 ctr->c.ldv.drag_total = 0;
74 double time; // the time in MUT time when the census is made
79 // for LDV profiling, when just displaying by LDV
87 static Census *censuses = NULL;
88 static nat n_censuses = 0;
91 static void aggregateCensusInfo( void );
94 static void dumpCensus( Census *census );
96 static rtsBool closureSatisfiesConstraints( StgClosure* p );
98 /* ----------------------------------------------------------------------------
99 * Find the "closure identity", which is a unique pointer reresenting
100 * the band to which this closure's heap space is attributed in the
102 * ------------------------------------------------------------------------- */
104 closureIdentity( StgClosure *p )
106 switch (RtsFlags.ProfFlags.doHeapProfile) {
110 return p->header.prof.ccs;
112 return p->header.prof.ccs->cc->module;
114 return GET_PROF_DESC(get_itbl(p));
116 return GET_PROF_TYPE(get_itbl(p));
117 case HEAP_BY_RETAINER:
118 // AFAIK, the only closures in the heap which might not have a
119 // valid retainer set are DEAD_WEAK closures.
120 if (isRetainerSetFieldValid(p))
121 return retainerSetOf(p);
126 case HEAP_BY_CLOSURE_TYPE:
130 switch (info->type) {
138 case CONSTR_NOCAF_STATIC:
139 return GET_CON_DESC(itbl_to_con_itbl(info));
141 return closure_type_names[info->type];
147 barf("closureIdentity");
151 /* --------------------------------------------------------------------------
152 * Profiling type predicates
153 * ----------------------------------------------------------------------- */
155 STATIC_INLINE rtsBool
156 doingLDVProfiling( void )
158 return (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV
159 || RtsFlags.ProfFlags.bioSelector != NULL);
162 STATIC_INLINE rtsBool
163 doingRetainerProfiling( void )
165 return (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_RETAINER
166 || RtsFlags.ProfFlags.retainerSelector != NULL);
168 #endif /* PROFILING */
170 // Precesses a closure 'c' being destroyed whose size is 'size'.
171 // Make sure that LDV_recordDead() is not invoked on 'inherently used' closures
172 // such as TSO; they should not be involved in computing dragNew or voidNew.
174 // Even though era is checked in both LdvCensusForDead() and
175 // LdvCensusKillAll(), we still need to make sure that era is > 0 because
176 // LDV_recordDead() may be called from elsewhere in the runtime system. E.g.,
177 // when a thunk is replaced by an indirection object.
181 LDV_recordDead( StgClosure *c, nat size )
187 if (era > 0 && closureSatisfiesConstraints(c)) {
188 size -= sizeofW(StgProfHeader);
189 ASSERT(LDVW(c) != 0);
190 if ((LDVW((c)) & LDV_STATE_MASK) == LDV_STATE_CREATE) {
191 t = (LDVW((c)) & LDV_CREATE_MASK) >> LDV_SHIFT;
193 if (RtsFlags.ProfFlags.bioSelector == NULL) {
194 censuses[t].void_total += (int)size;
195 censuses[era].void_total -= (int)size;
196 ASSERT(censuses[t].void_total < censuses[t].not_used);
198 id = closureIdentity(c);
199 ctr = lookupHashTable(censuses[t].hash, (StgWord)id);
200 ASSERT( ctr != NULL );
201 ctr->c.ldv.void_total += (int)size;
202 ctr = lookupHashTable(censuses[era].hash, (StgWord)id);
204 ctr = arenaAlloc(censuses[era].arena, sizeof(counter));
206 insertHashTable(censuses[era].hash, (StgWord)id, ctr);
208 ctr->next = censuses[era].ctrs;
209 censuses[era].ctrs = ctr;
211 ctr->c.ldv.void_total -= (int)size;
215 t = LDVW((c)) & LDV_LAST_MASK;
217 if (RtsFlags.ProfFlags.bioSelector == NULL) {
218 censuses[t+1].drag_total += size;
219 censuses[era].drag_total -= size;
222 id = closureIdentity(c);
223 ctr = lookupHashTable(censuses[t+1].hash, (StgWord)id);
224 ASSERT( ctr != NULL );
225 ctr->c.ldv.drag_total += (int)size;
226 ctr = lookupHashTable(censuses[era].hash, (StgWord)id);
228 ctr = arenaAlloc(censuses[era].arena, sizeof(counter));
230 insertHashTable(censuses[era].hash, (StgWord)id, ctr);
232 ctr->next = censuses[era].ctrs;
233 censuses[era].ctrs = ctr;
235 ctr->c.ldv.drag_total -= (int)size;
243 /* --------------------------------------------------------------------------
244 * Initialize censuses[era];
245 * ----------------------------------------------------------------------- */
248 initEra(Census *census)
250 census->hash = allocHashTable();
252 census->arena = newArena();
254 census->not_used = 0;
257 census->void_total = 0;
258 census->drag_total = 0;
262 freeEra(Census *census)
264 if (RtsFlags.ProfFlags.bioSelector != NULL)
265 // when bioSelector==NULL, these are freed in heapCensus()
267 arenaFree(census->arena);
268 freeHashTable(census->hash, NULL);
272 /* --------------------------------------------------------------------------
273 * Increases era by 1 and initialize census[era].
274 * Reallocates gi[] and increases its size if needed.
275 * ----------------------------------------------------------------------- */
281 if (doingLDVProfiling()) {
284 if (era == max_era) {
285 errorBelch("maximum number of censuses reached; use +RTS -i to reduce");
286 stg_exit(EXIT_FAILURE);
289 if (era == n_censuses) {
291 censuses = stgReallocBytes(censuses, sizeof(Census) * n_censuses,
295 #endif /* PROFILING */
297 initEra( &censuses[era] );
300 /* ----------------------------------------------------------------------------
301 * Heap profiling by info table
302 * ------------------------------------------------------------------------- */
304 #if !defined(PROFILING)
306 static char *hp_filename;
308 void initProfiling1 (void)
312 void freeProfiling1 (void)
316 void initProfiling2 (void)
320 prog = stgMallocBytes(strlen(prog_name) + 1, "initProfiling2");
321 strcpy(prog, prog_name);
322 #ifdef mingw32_HOST_OS
323 // on Windows, drop the .exe suffix if there is one
326 suff = strrchr(prog,'.');
327 if (suff != NULL && !strcmp(suff,".exe")) {
333 if (RtsFlags.ProfFlags.doHeapProfile) {
334 /* Initialise the log file name */
335 hp_filename = stgMallocBytes(strlen(prog) + 6, "hpFileName");
336 sprintf(hp_filename, "%s.hp", prog);
338 /* open the log file */
339 if ((hp_file = fopen(hp_filename, "w")) == NULL) {
340 debugBelch("Can't open profiling report file %s\n",
342 RtsFlags.ProfFlags.doHeapProfile = 0;
352 void endProfiling( void )
356 #endif /* !PROFILING */
359 printSample(rtsBool beginSample, StgDouble sampleValue)
361 StgDouble fractionalPart, integralPart;
362 fractionalPart = modf(sampleValue, &integralPart);
363 fprintf(hp_file, "%s %" FMT_Word64 ".%02" FMT_Word64 "\n",
364 (beginSample ? "BEGIN_SAMPLE" : "END_SAMPLE"),
365 (StgWord64)integralPart, (StgWord64)(fractionalPart * 100));
368 /* --------------------------------------------------------------------------
369 * Initialize the heap profilier
370 * ----------------------------------------------------------------------- */
372 initHeapProfiling(void)
374 if (! RtsFlags.ProfFlags.doHeapProfile) {
379 if (doingLDVProfiling() && doingRetainerProfiling()) {
380 errorBelch("cannot mix -hb and -hr");
381 stg_exit(EXIT_FAILURE);
385 // we only count eras if we're doing LDV profiling. Otherwise era
388 if (doingLDVProfiling()) {
396 // max_era = 2^LDV_SHIFT
397 max_era = 1 << LDV_SHIFT;
400 censuses = stgMallocBytes(sizeof(Census) * n_censuses, "initHeapProfiling");
402 initEra( &censuses[era] );
404 /* initProfilingLogFile(); */
405 fprintf(hp_file, "JOB \"%s", prog_name);
410 for(count = 1; count < prog_argc; count++)
411 fprintf(hp_file, " %s", prog_argv[count]);
412 fprintf(hp_file, " +RTS");
413 for(count = 0; count < rts_argc; count++)
414 fprintf(hp_file, " %s", rts_argv[count]);
416 #endif /* PROFILING */
418 fprintf(hp_file, "\"\n" );
420 fprintf(hp_file, "DATE \"%s\"\n", time_str());
422 fprintf(hp_file, "SAMPLE_UNIT \"seconds\"\n");
423 fprintf(hp_file, "VALUE_UNIT \"bytes\"\n");
425 printSample(rtsTrue, 0);
426 printSample(rtsFalse, 0);
429 if (doingRetainerProfiling()) {
430 initRetainerProfiling();
438 endHeapProfiling(void)
442 if (! RtsFlags.ProfFlags.doHeapProfile) {
447 if (doingRetainerProfiling()) {
448 endRetainerProfiling();
453 if (doingLDVProfiling()) {
456 aggregateCensusInfo();
457 for (t = 1; t < era; t++) {
458 dumpCensus( &censuses[t] );
464 if (doingLDVProfiling()) {
466 for (t = 1; t <= era; t++) {
467 freeEra( &censuses[t] );
470 freeEra( &censuses[0] );
473 freeEra( &censuses[0] );
478 seconds = mut_user_time();
479 printSample(rtsTrue, seconds);
480 printSample(rtsFalse, seconds);
488 buf_append(char *p, const char *q, char *end)
492 for (m = 0; p < end; p++, q++, m++) {
494 if (*q == '\0') { break; }
500 fprint_ccs(FILE *fp, CostCentreStack *ccs, nat max_length)
502 char buf[max_length+1], *p, *buf_end;
504 // MAIN on its own gets printed as "MAIN", otherwise we ignore MAIN.
505 if (ccs == CCS_MAIN) {
510 fprintf(fp, "(%ld)", ccs->ccsID);
513 buf_end = buf + max_length + 1;
515 // keep printing components of the stack until we run out of space
516 // in the buffer. If we run out of space, end with "...".
517 for (; ccs != NULL && ccs != CCS_MAIN; ccs = ccs->prevStack) {
519 // CAF cost centres print as M.CAF, but we leave the module
520 // name out of all the others to save space.
521 if (!strcmp(ccs->cc->label,"CAF")) {
522 p += buf_append(p, ccs->cc->module, buf_end);
523 p += buf_append(p, ".CAF", buf_end);
525 p += buf_append(p, ccs->cc->label, buf_end);
526 if (ccs->prevStack != NULL && ccs->prevStack != CCS_MAIN) {
527 p += buf_append(p, "/", buf_end);
532 sprintf(buf+max_length-4, "...");
536 fprintf(fp, "%s", buf);
540 strMatchesSelector( char* str, char* sel )
543 // debugBelch("str_matches_selector %s %s\n", str, sel);
545 // Compare str against wherever we've got to in sel.
547 while (*p != '\0' && *sel != ',' && *sel != '\0' && *p == *sel) {
550 // Match if all of str used and have reached the end of a sel fragment.
551 if (*p == '\0' && (*sel == ',' || *sel == '\0'))
554 // No match. Advance sel to the start of the next elem.
555 while (*sel != ',' && *sel != '\0') sel++;
556 if (*sel == ',') sel++;
558 /* Run out of sel ?? */
559 if (*sel == '\0') return rtsFalse;
563 #endif /* PROFILING */
565 /* -----------------------------------------------------------------------------
566 * Figure out whether a closure should be counted in this census, by
567 * testing against all the specified constraints.
568 * -------------------------------------------------------------------------- */
570 closureSatisfiesConstraints( StgClosure* p )
572 #if !defined(PROFILING)
573 (void)p; /* keep gcc -Wall happy */
578 // The CCS has a selected field to indicate whether this closure is
579 // deselected by not being mentioned in the module, CC, or CCS
581 if (!p->header.prof.ccs->selected) {
585 if (RtsFlags.ProfFlags.descrSelector) {
586 b = strMatchesSelector( (GET_PROF_DESC(get_itbl((StgClosure *)p))),
587 RtsFlags.ProfFlags.descrSelector );
588 if (!b) return rtsFalse;
590 if (RtsFlags.ProfFlags.typeSelector) {
591 b = strMatchesSelector( (GET_PROF_TYPE(get_itbl((StgClosure *)p))),
592 RtsFlags.ProfFlags.typeSelector );
593 if (!b) return rtsFalse;
595 if (RtsFlags.ProfFlags.retainerSelector) {
598 // We must check that the retainer set is valid here. One
599 // reason it might not be valid is if this closure is a
600 // a newly deceased weak pointer (i.e. a DEAD_WEAK), since
601 // these aren't reached by the retainer profiler's traversal.
602 if (isRetainerSetFieldValid((StgClosure *)p)) {
603 rs = retainerSetOf((StgClosure *)p);
605 for (i = 0; i < rs->num; i++) {
606 b = strMatchesSelector( rs->element[i]->cc->label,
607 RtsFlags.ProfFlags.retainerSelector );
608 if (b) return rtsTrue;
615 #endif /* PROFILING */
618 /* -----------------------------------------------------------------------------
619 * Aggregate the heap census info for biographical profiling
620 * -------------------------------------------------------------------------- */
623 aggregateCensusInfo( void )
627 counter *c, *d, *ctrs;
630 if (!doingLDVProfiling()) return;
632 // Aggregate the LDV counters when displaying by biography.
633 if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
634 int void_total, drag_total;
636 // Now we compute void_total and drag_total for each census
637 // After the program has finished, the void_total field of
638 // each census contains the count of words that were *created*
639 // in this era and were eventually void. Conversely, if a
640 // void closure was destroyed in this era, it will be
641 // represented by a negative count of words in void_total.
643 // To get the count of live words that are void at each
644 // census, just propagate the void_total count forwards:
648 for (t = 1; t < era; t++) { // note: start at 1, not 0
649 void_total += censuses[t].void_total;
650 drag_total += censuses[t].drag_total;
651 censuses[t].void_total = void_total;
652 censuses[t].drag_total = drag_total;
654 ASSERT( censuses[t].void_total <= censuses[t].not_used );
655 // should be true because: void_total is the count of
656 // live words that are void at this census, which *must*
657 // be less than the number of live words that have not
660 ASSERT( censuses[t].drag_total <= censuses[t].used );
661 // similar reasoning as above.
667 // otherwise... we're doing a heap profile that is restricted to
668 // some combination of lag, drag, void or use. We've kept all the
669 // census info for all censuses so far, but we still need to
670 // aggregate the counters forwards.
673 acc = allocHashTable();
676 for (t = 1; t < era; t++) {
678 // first look through all the counters we're aggregating
679 for (c = ctrs; c != NULL; c = c->next) {
680 // if one of the totals is non-zero, then this closure
681 // type must be present in the heap at this census time...
682 d = lookupHashTable(censuses[t].hash, (StgWord)c->identity);
685 // if this closure identity isn't present in the
686 // census for this time period, then our running
687 // totals *must* be zero.
688 ASSERT(c->c.ldv.void_total == 0 && c->c.ldv.drag_total == 0);
690 // debugCCS(c->identity);
691 // debugBelch(" census=%d void_total=%d drag_total=%d\n",
692 // t, c->c.ldv.void_total, c->c.ldv.drag_total);
694 d->c.ldv.void_total += c->c.ldv.void_total;
695 d->c.ldv.drag_total += c->c.ldv.drag_total;
696 c->c.ldv.void_total = d->c.ldv.void_total;
697 c->c.ldv.drag_total = d->c.ldv.drag_total;
699 ASSERT( c->c.ldv.void_total >= 0 );
700 ASSERT( c->c.ldv.drag_total >= 0 );
704 // now look through the counters in this census to find new ones
705 for (c = censuses[t].ctrs; c != NULL; c = c->next) {
706 d = lookupHashTable(acc, (StgWord)c->identity);
708 d = arenaAlloc( arena, sizeof(counter) );
710 insertHashTable( acc, (StgWord)c->identity, d );
711 d->identity = c->identity;
714 d->c.ldv.void_total = c->c.ldv.void_total;
715 d->c.ldv.drag_total = c->c.ldv.drag_total;
717 ASSERT( c->c.ldv.void_total >= 0 );
718 ASSERT( c->c.ldv.drag_total >= 0 );
722 freeHashTable(acc, NULL);
727 /* -----------------------------------------------------------------------------
728 * Print out the results of a heap census.
729 * -------------------------------------------------------------------------- */
731 dumpCensus( Census *census )
736 printSample(rtsTrue, census->time);
739 if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
740 fprintf(hp_file, "VOID\t%lu\n", (unsigned long)(census->void_total) * sizeof(W_));
741 fprintf(hp_file, "LAG\t%lu\n",
742 (unsigned long)(census->not_used - census->void_total) * sizeof(W_));
743 fprintf(hp_file, "USE\t%lu\n",
744 (unsigned long)(census->used - census->drag_total) * sizeof(W_));
745 fprintf(hp_file, "INHERENT_USE\t%lu\n",
746 (unsigned long)(census->prim) * sizeof(W_));
747 fprintf(hp_file, "DRAG\t%lu\n",
748 (unsigned long)(census->drag_total) * sizeof(W_));
749 printSample(rtsFalse, census->time);
754 for (ctr = census->ctrs; ctr != NULL; ctr = ctr->next) {
757 if (RtsFlags.ProfFlags.bioSelector != NULL) {
759 if (strMatchesSelector("lag", RtsFlags.ProfFlags.bioSelector))
760 count += ctr->c.ldv.not_used - ctr->c.ldv.void_total;
761 if (strMatchesSelector("drag", RtsFlags.ProfFlags.bioSelector))
762 count += ctr->c.ldv.drag_total;
763 if (strMatchesSelector("void", RtsFlags.ProfFlags.bioSelector))
764 count += ctr->c.ldv.void_total;
765 if (strMatchesSelector("use", RtsFlags.ProfFlags.bioSelector))
766 count += ctr->c.ldv.used - ctr->c.ldv.drag_total;
770 count = ctr->c.resid;
773 ASSERT( count >= 0 );
775 if (count == 0) continue;
777 #if !defined(PROFILING)
778 switch (RtsFlags.ProfFlags.doHeapProfile) {
779 case HEAP_BY_CLOSURE_TYPE:
780 fprintf(hp_file, "%s", (char *)ctr->identity);
786 switch (RtsFlags.ProfFlags.doHeapProfile) {
788 fprint_ccs(hp_file, (CostCentreStack *)ctr->identity, RtsFlags.ProfFlags.ccsLength);
793 fprintf(hp_file, "%s", (char *)ctr->identity);
795 case HEAP_BY_RETAINER:
797 RetainerSet *rs = (RetainerSet *)ctr->identity;
799 // it might be the distinguished retainer set rs_MANY:
800 if (rs == &rs_MANY) {
801 fprintf(hp_file, "MANY");
805 // Mark this retainer set by negating its id, because it
806 // has appeared in at least one census. We print the
807 // values of all such retainer sets into the log file at
808 // the end. A retainer set may exist but not feature in
809 // any censuses if it arose as the intermediate retainer
810 // set for some closure during retainer set calculation.
814 // report in the unit of bytes: * sizeof(StgWord)
815 printRetainerSetShort(hp_file, rs);
819 barf("dumpCensus; doHeapProfile");
823 fprintf(hp_file, "\t%lu\n", (unsigned long)count * sizeof(W_));
826 printSample(rtsFalse, census->time);
829 /* -----------------------------------------------------------------------------
830 * Code to perform a heap census.
831 * -------------------------------------------------------------------------- */
833 heapCensusChain( Census *census, bdescr *bd )
843 for (; bd != NULL; bd = bd->link) {
845 // HACK: ignore pinned blocks, because they contain gaps.
846 // It's not clear exactly what we'd like to do here, since we
847 // can't tell which objects in the block are actually alive.
848 // Perhaps the whole block should be counted as SYSTEM memory.
849 if (bd->flags & BF_PINNED) {
854 while (p < bd->free) {
855 info = get_itbl((StgClosure *)p);
858 switch (info->type) {
861 size = thunk_sizeW_fromITBL(info);
867 size = sizeofW(StgThunkHeader) + 2;
873 size = sizeofW(StgThunkHeader) + 1;
880 case IND_OLDGEN_PERM:
893 size = sizeW_fromITBL(info);
897 // Special case/Delicate Hack: INDs don't normally
898 // appear, since we're doing this heap census right
899 // after GC. However, GarbageCollect() also does
900 // resurrectThreads(), which can update some
901 // blackholes when it calls raiseAsync() on the
902 // resurrected threads. So we know that any IND will
903 // be the size of a BLACKHOLE.
904 size = BLACKHOLE_sizeW();
909 size = bco_sizeW((StgBCO *)p);
919 size = sizeW_fromITBL(info);
923 size = ap_sizeW((StgAP *)p);
927 size = pap_sizeW((StgPAP *)p);
931 size = ap_stack_sizeW((StgAP_STACK *)p);
936 size = arr_words_sizeW((StgArrWords*)p);
939 case MUT_ARR_PTRS_CLEAN:
940 case MUT_ARR_PTRS_DIRTY:
941 case MUT_ARR_PTRS_FROZEN:
942 case MUT_ARR_PTRS_FROZEN0:
944 size = mut_arr_ptrs_sizeW((StgMutArrPtrs *)p);
950 if (RtsFlags.ProfFlags.includeTSOs) {
951 size = tso_sizeW((StgTSO *)p);
954 // Skip this TSO and move on to the next object
955 p += tso_sizeW((StgTSO *)p);
959 size = tso_sizeW((StgTSO *)p);
965 size = sizeofW(StgTRecHeader);
968 case TVAR_WATCH_QUEUE:
970 size = sizeofW(StgTVarWatchQueue);
973 case INVARIANT_CHECK_QUEUE:
975 size = sizeofW(StgInvariantCheckQueue);
978 case ATOMIC_INVARIANT:
980 size = sizeofW(StgAtomicInvariant);
985 size = sizeofW(StgTVar);
990 size = sizeofW(StgTRecChunk);
994 barf("heapCensus, unknown object: %d", info->type);
1000 // subtract the profiling overhead
1001 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
1088 if (RtsFlags.GcFlags.generations == 1) {
1089 heapCensusChain( census, g0->steps[0].blocks );
1091 for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
1092 for (s = 0; s < generations[g].n_steps; s++) {
1093 heapCensusChain( census, generations[g].steps[s].blocks );
1094 // Are we interested in large objects? might be
1095 // confusing to include the stack in a heap profile.
1096 heapCensusChain( census, generations[g].steps[s].large_objects );
1101 // dump out the census info
1103 // We can't generate any info for LDV profiling until
1104 // the end of the run...
1105 if (!doingLDVProfiling())
1106 dumpCensus( census );
1108 dumpCensus( census );
1112 // free our storage, unless we're keeping all the census info for
1113 // future restriction by biography.
1115 if (RtsFlags.ProfFlags.bioSelector == NULL)
1117 freeHashTable( census->hash, NULL/* don't free the elements */ );
1118 arenaFree( census->arena );
1119 census->hash = NULL;
1120 census->arena = NULL;
1124 // we're into the next time period now
1128 stat_endHeapCensus();