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"
26 /* -----------------------------------------------------------------------------
27 * era stores the current time period. It is the same as the
28 * number of censuses that have been performed.
31 * era must be no longer than LDV_SHIFT (15 or 30) bits.
33 * era is initialized to 1 in initHeapProfiling().
35 * max_era is initialized to 2^LDV_SHIFT in initHeapProfiling().
36 * When era reaches max_era, the profiling stops because a closure can
37 * store only up to (max_era - 1) as its creation or last use time.
38 * -------------------------------------------------------------------------- */
42 /* -----------------------------------------------------------------------------
45 * For most heap profiles each closure identity gets a simple count
46 * of live words in the heap at each census. However, if we're
47 * selecting by biography, then we have to keep the various
48 * lag/drag/void counters for each identity.
49 * -------------------------------------------------------------------------- */
50 typedef struct _counter {
55 int prim; // total size of 'inherently used' closures
56 int not_used; // total size of 'never used' closures
57 int used; // total size of 'used at least once' closures
58 int void_total; // current total size of 'destroyed without being used' closures
59 int drag_total; // current total size of 'used at least once and waiting to die'
62 struct _counter *next;
66 initLDVCtr( counter *ctr )
69 ctr->c.ldv.not_used = 0;
71 ctr->c.ldv.void_total = 0;
72 ctr->c.ldv.drag_total = 0;
76 double time; // the time in MUT time when the census is made
81 // for LDV profiling, when just displaying by LDV
89 static Census *censuses = NULL;
90 static nat n_censuses = 0;
93 static void aggregateCensusInfo( void );
96 static void dumpCensus( Census *census );
98 /* ----------------------------------------------------------------------------
99 Closure Type Profiling;
100 ------------------------------------------------------------------------- */
103 static char *type_names[] = {
112 "CONSTR_NOCAF_STATIC",
152 "MUT_ARR_PTRS_CLEAN",
153 "MUT_ARR_PTRS_DIRTY",
154 "MUT_ARR_PTRS_FROZEN0",
155 "MUT_ARR_PTRS_FROZEN",
168 "INVARIANT_CHECK_QUEUE",
180 /* ----------------------------------------------------------------------------
181 * Find the "closure identity", which is a unique pointer reresenting
182 * the band to which this closure's heap space is attributed in the
184 * ------------------------------------------------------------------------- */
186 closureIdentity( StgClosure *p )
188 switch (RtsFlags.ProfFlags.doHeapProfile) {
192 return p->header.prof.ccs;
194 return p->header.prof.ccs->cc->module;
196 return GET_PROF_DESC(get_itbl(p));
198 return GET_PROF_TYPE(get_itbl(p));
199 case HEAP_BY_RETAINER:
200 // AFAIK, the only closures in the heap which might not have a
201 // valid retainer set are DEAD_WEAK closures.
202 if (isRetainerSetFieldValid(p))
203 return retainerSetOf(p);
208 case HEAP_BY_CLOSURE_TYPE:
212 switch (info->type) {
220 case CONSTR_NOCAF_STATIC:
221 return GET_CON_DESC(itbl_to_con_itbl(info));
223 return type_names[info->type];
229 barf("closureIdentity");
233 /* --------------------------------------------------------------------------
234 * Profiling type predicates
235 * ----------------------------------------------------------------------- */
237 STATIC_INLINE rtsBool
238 doingLDVProfiling( void )
240 return (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV
241 || RtsFlags.ProfFlags.bioSelector != NULL);
244 STATIC_INLINE rtsBool
245 doingRetainerProfiling( void )
247 return (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_RETAINER
248 || RtsFlags.ProfFlags.retainerSelector != NULL);
250 #endif /* PROFILING */
252 // Precesses a closure 'c' being destroyed whose size is 'size'.
253 // Make sure that LDV_recordDead() is not invoked on 'inherently used' closures
254 // such as TSO; they should not be involved in computing dragNew or voidNew.
256 // Even though era is checked in both LdvCensusForDead() and
257 // LdvCensusKillAll(), we still need to make sure that era is > 0 because
258 // LDV_recordDead() may be called from elsewhere in the runtime system. E.g.,
259 // when a thunk is replaced by an indirection object.
263 LDV_recordDead( StgClosure *c, nat size )
269 if (era > 0 && closureSatisfiesConstraints(c)) {
270 size -= sizeofW(StgProfHeader);
271 ASSERT(LDVW(c) != 0);
272 if ((LDVW((c)) & LDV_STATE_MASK) == LDV_STATE_CREATE) {
273 t = (LDVW((c)) & LDV_CREATE_MASK) >> LDV_SHIFT;
275 if (RtsFlags.ProfFlags.bioSelector == NULL) {
276 censuses[t].void_total += (int)size;
277 censuses[era].void_total -= (int)size;
278 ASSERT(censuses[t].void_total < censuses[t].not_used);
280 id = closureIdentity(c);
281 ctr = lookupHashTable(censuses[t].hash, (StgWord)id);
282 ASSERT( ctr != NULL );
283 ctr->c.ldv.void_total += (int)size;
284 ctr = lookupHashTable(censuses[era].hash, (StgWord)id);
286 ctr = arenaAlloc(censuses[era].arena, sizeof(counter));
288 insertHashTable(censuses[era].hash, (StgWord)id, ctr);
290 ctr->next = censuses[era].ctrs;
291 censuses[era].ctrs = ctr;
293 ctr->c.ldv.void_total -= (int)size;
297 t = LDVW((c)) & LDV_LAST_MASK;
299 if (RtsFlags.ProfFlags.bioSelector == NULL) {
300 censuses[t+1].drag_total += size;
301 censuses[era].drag_total -= size;
304 id = closureIdentity(c);
305 ctr = lookupHashTable(censuses[t+1].hash, (StgWord)id);
306 ASSERT( ctr != NULL );
307 ctr->c.ldv.drag_total += (int)size;
308 ctr = lookupHashTable(censuses[era].hash, (StgWord)id);
310 ctr = arenaAlloc(censuses[era].arena, sizeof(counter));
312 insertHashTable(censuses[era].hash, (StgWord)id, ctr);
314 ctr->next = censuses[era].ctrs;
315 censuses[era].ctrs = ctr;
317 ctr->c.ldv.drag_total -= (int)size;
325 /* --------------------------------------------------------------------------
326 * Initialize censuses[era];
327 * ----------------------------------------------------------------------- */
330 initEra(Census *census)
332 census->hash = allocHashTable();
334 census->arena = newArena();
336 census->not_used = 0;
339 census->void_total = 0;
340 census->drag_total = 0;
344 freeEra(Census *census)
346 if (RtsFlags.ProfFlags.bioSelector != NULL)
347 // when bioSelector==NULL, these are freed in heapCensus()
349 arenaFree(census->arena);
350 freeHashTable(census->hash, NULL);
354 /* --------------------------------------------------------------------------
355 * Increases era by 1 and initialize census[era].
356 * Reallocates gi[] and increases its size if needed.
357 * ----------------------------------------------------------------------- */
363 if (doingLDVProfiling()) {
366 if (era == max_era) {
367 errorBelch("maximum number of censuses reached; use +RTS -i to reduce");
368 stg_exit(EXIT_FAILURE);
371 if (era == n_censuses) {
373 censuses = stgReallocBytes(censuses, sizeof(Census) * n_censuses,
377 #endif /* PROFILING */
379 initEra( &censuses[era] );
382 /* ----------------------------------------------------------------------------
383 * Heap profiling by info table
384 * ------------------------------------------------------------------------- */
386 #if !defined(PROFILING)
388 static char *hp_filename;
390 void initProfiling1 (void)
394 void freeProfiling1 (void)
398 void initProfiling2 (void)
400 if (RtsFlags.ProfFlags.doHeapProfile) {
401 /* Initialise the log file name */
402 hp_filename = stgMallocBytes(strlen(prog_name) + 6, "hpFileName");
403 sprintf(hp_filename, "%s.hp", prog_name);
405 /* open the log file */
406 if ((hp_file = fopen(hp_filename, "w")) == NULL) {
407 debugBelch("Can't open profiling report file %s\n",
409 RtsFlags.ProfFlags.doHeapProfile = 0;
417 void endProfiling( void )
421 #endif /* !PROFILING */
424 printSample(rtsBool beginSample, StgDouble sampleValue)
426 StgDouble fractionalPart, integralPart;
427 fractionalPart = modf(sampleValue, &integralPart);
428 fprintf(hp_file, "%s %" FMT_Word64 ".%02" FMT_Word64 "\n",
429 (beginSample ? "BEGIN_SAMPLE" : "END_SAMPLE"),
430 (StgWord64)integralPart, (StgWord64)(fractionalPart * 100));
433 /* --------------------------------------------------------------------------
434 * Initialize the heap profilier
435 * ----------------------------------------------------------------------- */
437 initHeapProfiling(void)
439 if (! RtsFlags.ProfFlags.doHeapProfile) {
444 if (doingLDVProfiling() && doingRetainerProfiling()) {
445 errorBelch("cannot mix -hb and -hr");
446 stg_exit(EXIT_FAILURE);
450 // we only count eras if we're doing LDV profiling. Otherwise era
453 if (doingLDVProfiling()) {
461 // max_era = 2^LDV_SHIFT
462 max_era = 1 << LDV_SHIFT;
465 censuses = stgMallocBytes(sizeof(Census) * n_censuses, "initHeapProfiling");
467 initEra( &censuses[era] );
469 /* initProfilingLogFile(); */
470 fprintf(hp_file, "JOB \"%s", prog_name);
475 for(count = 1; count < prog_argc; count++)
476 fprintf(hp_file, " %s", prog_argv[count]);
477 fprintf(hp_file, " +RTS");
478 for(count = 0; count < rts_argc; count++)
479 fprintf(hp_file, " %s", rts_argv[count]);
481 #endif /* PROFILING */
483 fprintf(hp_file, "\"\n" );
485 fprintf(hp_file, "DATE \"%s\"\n", time_str());
487 fprintf(hp_file, "SAMPLE_UNIT \"seconds\"\n");
488 fprintf(hp_file, "VALUE_UNIT \"bytes\"\n");
490 printSample(rtsTrue, 0);
491 printSample(rtsFalse, 0);
494 if (doingRetainerProfiling()) {
495 initRetainerProfiling();
503 endHeapProfiling(void)
507 if (! RtsFlags.ProfFlags.doHeapProfile) {
512 if (doingRetainerProfiling()) {
513 endRetainerProfiling();
518 if (doingLDVProfiling()) {
521 aggregateCensusInfo();
522 for (t = 1; t < era; t++) {
523 dumpCensus( &censuses[t] );
529 if (doingLDVProfiling()) {
531 for (t = 1; t <= era; t++) {
532 freeEra( &censuses[t] );
535 freeEra( &censuses[0] );
538 freeEra( &censuses[0] );
543 seconds = mut_user_time();
544 printSample(rtsTrue, seconds);
545 printSample(rtsFalse, seconds);
553 buf_append(char *p, const char *q, char *end)
557 for (m = 0; p < end; p++, q++, m++) {
559 if (*q == '\0') { break; }
565 fprint_ccs(FILE *fp, CostCentreStack *ccs, nat max_length)
567 char buf[max_length+1], *p, *buf_end;
569 // MAIN on its own gets printed as "MAIN", otherwise we ignore MAIN.
570 if (ccs == CCS_MAIN) {
575 fprintf(fp, "(%ld)", ccs->ccsID);
578 buf_end = buf + max_length + 1;
580 // keep printing components of the stack until we run out of space
581 // in the buffer. If we run out of space, end with "...".
582 for (; ccs != NULL && ccs != CCS_MAIN; ccs = ccs->prevStack) {
584 // CAF cost centres print as M.CAF, but we leave the module
585 // name out of all the others to save space.
586 if (!strcmp(ccs->cc->label,"CAF")) {
587 p += buf_append(p, ccs->cc->module, buf_end);
588 p += buf_append(p, ".CAF", buf_end);
590 p += buf_append(p, ccs->cc->label, buf_end);
591 if (ccs->prevStack != NULL && ccs->prevStack != CCS_MAIN) {
592 p += buf_append(p, "/", buf_end);
597 sprintf(buf+max_length-4, "...");
601 fprintf(fp, "%s", buf);
603 #endif /* PROFILING */
606 strMatchesSelector( char* str, char* sel )
609 // debugBelch("str_matches_selector %s %s\n", str, sel);
611 // Compare str against wherever we've got to in sel.
613 while (*p != '\0' && *sel != ',' && *sel != '\0' && *p == *sel) {
616 // Match if all of str used and have reached the end of a sel fragment.
617 if (*p == '\0' && (*sel == ',' || *sel == '\0'))
620 // No match. Advance sel to the start of the next elem.
621 while (*sel != ',' && *sel != '\0') sel++;
622 if (*sel == ',') sel++;
624 /* Run out of sel ?? */
625 if (*sel == '\0') return rtsFalse;
629 /* -----------------------------------------------------------------------------
630 * Figure out whether a closure should be counted in this census, by
631 * testing against all the specified constraints.
632 * -------------------------------------------------------------------------- */
634 closureSatisfiesConstraints( StgClosure* p )
636 #if !defined(PROFILING)
637 (void)p; /* keep gcc -Wall happy */
642 // The CCS has a selected field to indicate whether this closure is
643 // deselected by not being mentioned in the module, CC, or CCS
645 if (!p->header.prof.ccs->selected) {
649 if (RtsFlags.ProfFlags.descrSelector) {
650 b = strMatchesSelector( (GET_PROF_DESC(get_itbl((StgClosure *)p))),
651 RtsFlags.ProfFlags.descrSelector );
652 if (!b) return rtsFalse;
654 if (RtsFlags.ProfFlags.typeSelector) {
655 b = strMatchesSelector( (GET_PROF_TYPE(get_itbl((StgClosure *)p))),
656 RtsFlags.ProfFlags.typeSelector );
657 if (!b) return rtsFalse;
659 if (RtsFlags.ProfFlags.retainerSelector) {
662 // We must check that the retainer set is valid here. One
663 // reason it might not be valid is if this closure is a
664 // a newly deceased weak pointer (i.e. a DEAD_WEAK), since
665 // these aren't reached by the retainer profiler's traversal.
666 if (isRetainerSetFieldValid((StgClosure *)p)) {
667 rs = retainerSetOf((StgClosure *)p);
669 for (i = 0; i < rs->num; i++) {
670 b = strMatchesSelector( rs->element[i]->cc->label,
671 RtsFlags.ProfFlags.retainerSelector );
672 if (b) return rtsTrue;
679 #endif /* PROFILING */
682 /* -----------------------------------------------------------------------------
683 * Aggregate the heap census info for biographical profiling
684 * -------------------------------------------------------------------------- */
687 aggregateCensusInfo( void )
691 counter *c, *d, *ctrs;
694 if (!doingLDVProfiling()) return;
696 // Aggregate the LDV counters when displaying by biography.
697 if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
698 int void_total, drag_total;
700 // Now we compute void_total and drag_total for each census
701 // After the program has finished, the void_total field of
702 // each census contains the count of words that were *created*
703 // in this era and were eventually void. Conversely, if a
704 // void closure was destroyed in this era, it will be
705 // represented by a negative count of words in void_total.
707 // To get the count of live words that are void at each
708 // census, just propagate the void_total count forwards:
712 for (t = 1; t < era; t++) { // note: start at 1, not 0
713 void_total += censuses[t].void_total;
714 drag_total += censuses[t].drag_total;
715 censuses[t].void_total = void_total;
716 censuses[t].drag_total = drag_total;
718 ASSERT( censuses[t].void_total <= censuses[t].not_used );
719 // should be true because: void_total is the count of
720 // live words that are void at this census, which *must*
721 // be less than the number of live words that have not
724 ASSERT( censuses[t].drag_total <= censuses[t].used );
725 // similar reasoning as above.
731 // otherwise... we're doing a heap profile that is restricted to
732 // some combination of lag, drag, void or use. We've kept all the
733 // census info for all censuses so far, but we still need to
734 // aggregate the counters forwards.
737 acc = allocHashTable();
740 for (t = 1; t < era; t++) {
742 // first look through all the counters we're aggregating
743 for (c = ctrs; c != NULL; c = c->next) {
744 // if one of the totals is non-zero, then this closure
745 // type must be present in the heap at this census time...
746 d = lookupHashTable(censuses[t].hash, (StgWord)c->identity);
749 // if this closure identity isn't present in the
750 // census for this time period, then our running
751 // totals *must* be zero.
752 ASSERT(c->c.ldv.void_total == 0 && c->c.ldv.drag_total == 0);
754 // debugCCS(c->identity);
755 // debugBelch(" census=%d void_total=%d drag_total=%d\n",
756 // t, c->c.ldv.void_total, c->c.ldv.drag_total);
758 d->c.ldv.void_total += c->c.ldv.void_total;
759 d->c.ldv.drag_total += c->c.ldv.drag_total;
760 c->c.ldv.void_total = d->c.ldv.void_total;
761 c->c.ldv.drag_total = d->c.ldv.drag_total;
763 ASSERT( c->c.ldv.void_total >= 0 );
764 ASSERT( c->c.ldv.drag_total >= 0 );
768 // now look through the counters in this census to find new ones
769 for (c = censuses[t].ctrs; c != NULL; c = c->next) {
770 d = lookupHashTable(acc, (StgWord)c->identity);
772 d = arenaAlloc( arena, sizeof(counter) );
774 insertHashTable( acc, (StgWord)c->identity, d );
775 d->identity = c->identity;
778 d->c.ldv.void_total = c->c.ldv.void_total;
779 d->c.ldv.drag_total = c->c.ldv.drag_total;
781 ASSERT( c->c.ldv.void_total >= 0 );
782 ASSERT( c->c.ldv.drag_total >= 0 );
786 freeHashTable(acc, NULL);
791 /* -----------------------------------------------------------------------------
792 * Print out the results of a heap census.
793 * -------------------------------------------------------------------------- */
795 dumpCensus( Census *census )
800 printSample(rtsTrue, census->time);
803 if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
804 fprintf(hp_file, "VOID\t%lu\n", (unsigned long)(census->void_total) * sizeof(W_));
805 fprintf(hp_file, "LAG\t%lu\n",
806 (unsigned long)(census->not_used - census->void_total) * sizeof(W_));
807 fprintf(hp_file, "USE\t%lu\n",
808 (unsigned long)(census->used - census->drag_total) * sizeof(W_));
809 fprintf(hp_file, "INHERENT_USE\t%lu\n",
810 (unsigned long)(census->prim) * sizeof(W_));
811 fprintf(hp_file, "DRAG\t%lu\n",
812 (unsigned long)(census->drag_total) * sizeof(W_));
813 printSample(rtsFalse, census->time);
818 for (ctr = census->ctrs; ctr != NULL; ctr = ctr->next) {
821 if (RtsFlags.ProfFlags.bioSelector != NULL) {
823 if (strMatchesSelector("lag", RtsFlags.ProfFlags.bioSelector))
824 count += ctr->c.ldv.not_used - ctr->c.ldv.void_total;
825 if (strMatchesSelector("drag", RtsFlags.ProfFlags.bioSelector))
826 count += ctr->c.ldv.drag_total;
827 if (strMatchesSelector("void", RtsFlags.ProfFlags.bioSelector))
828 count += ctr->c.ldv.void_total;
829 if (strMatchesSelector("use", RtsFlags.ProfFlags.bioSelector))
830 count += ctr->c.ldv.used - ctr->c.ldv.drag_total;
834 count = ctr->c.resid;
837 ASSERT( count >= 0 );
839 if (count == 0) continue;
841 #if !defined(PROFILING)
842 switch (RtsFlags.ProfFlags.doHeapProfile) {
843 case HEAP_BY_CLOSURE_TYPE:
844 fprintf(hp_file, "%s", (char *)ctr->identity);
850 switch (RtsFlags.ProfFlags.doHeapProfile) {
852 fprint_ccs(hp_file, (CostCentreStack *)ctr->identity, RtsFlags.ProfFlags.ccsLength);
857 fprintf(hp_file, "%s", (char *)ctr->identity);
859 case HEAP_BY_RETAINER:
861 RetainerSet *rs = (RetainerSet *)ctr->identity;
863 // it might be the distinguished retainer set rs_MANY:
864 if (rs == &rs_MANY) {
865 fprintf(hp_file, "MANY");
869 // Mark this retainer set by negating its id, because it
870 // has appeared in at least one census. We print the
871 // values of all such retainer sets into the log file at
872 // the end. A retainer set may exist but not feature in
873 // any censuses if it arose as the intermediate retainer
874 // set for some closure during retainer set calculation.
878 // report in the unit of bytes: * sizeof(StgWord)
879 printRetainerSetShort(hp_file, rs);
883 barf("dumpCensus; doHeapProfile");
887 fprintf(hp_file, "\t%lu\n", (unsigned long)count * sizeof(W_));
890 printSample(rtsFalse, census->time);
893 /* -----------------------------------------------------------------------------
894 * Code to perform a heap census.
895 * -------------------------------------------------------------------------- */
897 heapCensusChain( Census *census, bdescr *bd )
907 for (; bd != NULL; bd = bd->link) {
909 // HACK: ignore pinned blocks, because they contain gaps.
910 // It's not clear exactly what we'd like to do here, since we
911 // can't tell which objects in the block are actually alive.
912 // Perhaps the whole block should be counted as SYSTEM memory.
913 if (bd->flags & BF_PINNED) {
918 while (p < bd->free) {
919 info = get_itbl((StgClosure *)p);
922 switch (info->type) {
925 size = thunk_sizeW_fromITBL(info);
931 size = sizeofW(StgThunkHeader) + 2;
937 size = sizeofW(StgThunkHeader) + 1;
944 case IND_OLDGEN_PERM:
946 case SE_CAF_BLACKHOLE:
959 size = sizeW_fromITBL(info);
963 // Special case/Delicate Hack: INDs don't normally
964 // appear, since we're doing this heap census right
965 // after GC. However, GarbageCollect() also does
966 // resurrectThreads(), which can update some
967 // blackholes when it calls raiseAsync() on the
968 // resurrected threads. So we know that any IND will
969 // be the size of a BLACKHOLE.
970 size = BLACKHOLE_sizeW();
975 size = bco_sizeW((StgBCO *)p);
985 size = sizeW_fromITBL(info);
989 size = ap_sizeW((StgAP *)p);
993 size = pap_sizeW((StgPAP *)p);
997 size = ap_stack_sizeW((StgAP_STACK *)p);
1002 size = arr_words_sizeW(stgCast(StgArrWords*,p));
1005 case MUT_ARR_PTRS_CLEAN:
1006 case MUT_ARR_PTRS_DIRTY:
1007 case MUT_ARR_PTRS_FROZEN:
1008 case MUT_ARR_PTRS_FROZEN0:
1010 size = mut_arr_ptrs_sizeW((StgMutArrPtrs *)p);
1016 if (RtsFlags.ProfFlags.includeTSOs) {
1017 size = tso_sizeW((StgTSO *)p);
1020 // Skip this TSO and move on to the next object
1021 p += tso_sizeW((StgTSO *)p);
1025 size = tso_sizeW((StgTSO *)p);
1031 size = sizeofW(StgTRecHeader);
1034 case TVAR_WATCH_QUEUE:
1036 size = sizeofW(StgTVarWatchQueue);
1039 case INVARIANT_CHECK_QUEUE:
1041 size = sizeofW(StgInvariantCheckQueue);
1044 case ATOMIC_INVARIANT:
1046 size = sizeofW(StgAtomicInvariant);
1051 size = sizeofW(StgTVar);
1056 size = sizeofW(StgTRecChunk);
1060 barf("heapCensus, unknown object: %d", info->type);
1066 // subtract the profiling overhead
1067 real_size = size - sizeofW(StgProfHeader);
1072 if (closureSatisfiesConstraints((StgClosure*)p)) {
1074 if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
1076 census->prim += real_size;
1077 else if ((LDVW(p) & LDV_STATE_MASK) == LDV_STATE_CREATE)
1078 census->not_used += real_size;
1080 census->used += real_size;
1084 identity = closureIdentity((StgClosure *)p);
1086 if (identity != NULL) {
1087 ctr = lookupHashTable( census->hash, (StgWord)identity );
1090 if (RtsFlags.ProfFlags.bioSelector != NULL) {
1092 ctr->c.ldv.prim += real_size;
1093 else if ((LDVW(p) & LDV_STATE_MASK) == LDV_STATE_CREATE)
1094 ctr->c.ldv.not_used += real_size;
1096 ctr->c.ldv.used += real_size;
1100 ctr->c.resid += real_size;
1103 ctr = arenaAlloc( census->arena, sizeof(counter) );
1105 insertHashTable( census->hash, (StgWord)identity, ctr );
1106 ctr->identity = identity;
1107 ctr->next = census->ctrs;
1111 if (RtsFlags.ProfFlags.bioSelector != NULL) {
1113 ctr->c.ldv.prim = real_size;
1114 else if ((LDVW(p) & LDV_STATE_MASK) == LDV_STATE_CREATE)
1115 ctr->c.ldv.not_used = real_size;
1117 ctr->c.ldv.used = real_size;
1121 ctr->c.resid = real_size;
1139 census = &censuses[era];
1140 census->time = mut_user_time();
1142 // calculate retainer sets if necessary
1144 if (doingRetainerProfiling()) {
1150 stat_startHeapCensus();
1153 // Traverse the heap, collecting the census info
1154 if (RtsFlags.GcFlags.generations == 1) {
1155 heapCensusChain( census, g0s0->blocks );
1157 for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
1158 for (s = 0; s < generations[g].n_steps; s++) {
1159 heapCensusChain( census, generations[g].steps[s].blocks );
1160 // Are we interested in large objects? might be
1161 // confusing to include the stack in a heap profile.
1162 heapCensusChain( census, generations[g].steps[s].large_objects );
1167 // dump out the census info
1169 // We can't generate any info for LDV profiling until
1170 // the end of the run...
1171 if (!doingLDVProfiling())
1172 dumpCensus( census );
1174 dumpCensus( census );
1178 // free our storage, unless we're keeping all the census info for
1179 // future restriction by biography.
1181 if (RtsFlags.ProfFlags.bioSelector == NULL)
1183 freeHashTable( census->hash, NULL/* don't free the elements */ );
1184 arenaFree( census->arena );
1185 census->hash = NULL;
1186 census->arena = NULL;
1190 // we're into the next time period now
1194 stat_endHeapCensus();