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",
151 "MUT_ARR_PTRS_CLEAN",
152 "MUT_ARR_PTRS_DIRTY",
153 "MUT_ARR_PTRS_FROZEN0",
154 "MUT_ARR_PTRS_FROZEN",
167 "INVARIANT_CHECK_QUEUE",
179 /* ----------------------------------------------------------------------------
180 * Find the "closure identity", which is a unique pointer reresenting
181 * the band to which this closure's heap space is attributed in the
183 * ------------------------------------------------------------------------- */
185 closureIdentity( StgClosure *p )
187 switch (RtsFlags.ProfFlags.doHeapProfile) {
191 return p->header.prof.ccs;
193 return p->header.prof.ccs->cc->module;
195 return GET_PROF_DESC(get_itbl(p));
197 return GET_PROF_TYPE(get_itbl(p));
198 case HEAP_BY_RETAINER:
199 // AFAIK, the only closures in the heap which might not have a
200 // valid retainer set are DEAD_WEAK closures.
201 if (isRetainerSetFieldValid(p))
202 return retainerSetOf(p);
207 case HEAP_BY_CLOSURE_TYPE:
211 switch (info->type) {
219 case CONSTR_NOCAF_STATIC:
220 return GET_CON_DESC(itbl_to_con_itbl(info));
222 return type_names[info->type];
228 barf("closureIdentity");
232 /* --------------------------------------------------------------------------
233 * Profiling type predicates
234 * ----------------------------------------------------------------------- */
236 STATIC_INLINE rtsBool
237 doingLDVProfiling( void )
239 return (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV
240 || RtsFlags.ProfFlags.bioSelector != NULL);
243 STATIC_INLINE rtsBool
244 doingRetainerProfiling( void )
246 return (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_RETAINER
247 || RtsFlags.ProfFlags.retainerSelector != NULL);
249 #endif /* PROFILING */
251 // Precesses a closure 'c' being destroyed whose size is 'size'.
252 // Make sure that LDV_recordDead() is not invoked on 'inherently used' closures
253 // such as TSO; they should not be involved in computing dragNew or voidNew.
255 // Even though era is checked in both LdvCensusForDead() and
256 // LdvCensusKillAll(), we still need to make sure that era is > 0 because
257 // LDV_recordDead() may be called from elsewhere in the runtime system. E.g.,
258 // when a thunk is replaced by an indirection object.
262 LDV_recordDead( StgClosure *c, nat size )
268 if (era > 0 && closureSatisfiesConstraints(c)) {
269 size -= sizeofW(StgProfHeader);
270 ASSERT(LDVW(c) != 0);
271 if ((LDVW((c)) & LDV_STATE_MASK) == LDV_STATE_CREATE) {
272 t = (LDVW((c)) & LDV_CREATE_MASK) >> LDV_SHIFT;
274 if (RtsFlags.ProfFlags.bioSelector == NULL) {
275 censuses[t].void_total += (int)size;
276 censuses[era].void_total -= (int)size;
277 ASSERT(censuses[t].void_total < censuses[t].not_used);
279 id = closureIdentity(c);
280 ctr = lookupHashTable(censuses[t].hash, (StgWord)id);
281 ASSERT( ctr != NULL );
282 ctr->c.ldv.void_total += (int)size;
283 ctr = lookupHashTable(censuses[era].hash, (StgWord)id);
285 ctr = arenaAlloc(censuses[era].arena, sizeof(counter));
287 insertHashTable(censuses[era].hash, (StgWord)id, ctr);
289 ctr->next = censuses[era].ctrs;
290 censuses[era].ctrs = ctr;
292 ctr->c.ldv.void_total -= (int)size;
296 t = LDVW((c)) & LDV_LAST_MASK;
298 if (RtsFlags.ProfFlags.bioSelector == NULL) {
299 censuses[t+1].drag_total += size;
300 censuses[era].drag_total -= size;
303 id = closureIdentity(c);
304 ctr = lookupHashTable(censuses[t+1].hash, (StgWord)id);
305 ASSERT( ctr != NULL );
306 ctr->c.ldv.drag_total += (int)size;
307 ctr = lookupHashTable(censuses[era].hash, (StgWord)id);
309 ctr = arenaAlloc(censuses[era].arena, sizeof(counter));
311 insertHashTable(censuses[era].hash, (StgWord)id, ctr);
313 ctr->next = censuses[era].ctrs;
314 censuses[era].ctrs = ctr;
316 ctr->c.ldv.drag_total -= (int)size;
324 /* --------------------------------------------------------------------------
325 * Initialize censuses[era];
326 * ----------------------------------------------------------------------- */
329 initEra(Census *census)
331 census->hash = allocHashTable();
333 census->arena = newArena();
335 census->not_used = 0;
338 census->void_total = 0;
339 census->drag_total = 0;
343 freeEra(Census *census)
345 if (RtsFlags.ProfFlags.bioSelector != NULL)
346 // when bioSelector==NULL, these are freed in heapCensus()
348 arenaFree(census->arena);
349 freeHashTable(census->hash, NULL);
353 /* --------------------------------------------------------------------------
354 * Increases era by 1 and initialize census[era].
355 * Reallocates gi[] and increases its size if needed.
356 * ----------------------------------------------------------------------- */
362 if (doingLDVProfiling()) {
365 if (era == max_era) {
366 errorBelch("maximum number of censuses reached; use +RTS -i to reduce");
367 stg_exit(EXIT_FAILURE);
370 if (era == n_censuses) {
372 censuses = stgReallocBytes(censuses, sizeof(Census) * n_censuses,
376 #endif /* PROFILING */
378 initEra( &censuses[era] );
381 /* ----------------------------------------------------------------------------
382 * Heap profiling by info table
383 * ------------------------------------------------------------------------- */
385 #if !defined(PROFILING)
387 static char *hp_filename;
389 void initProfiling1 (void)
393 void freeProfiling1 (void)
397 void initProfiling2 (void)
399 if (RtsFlags.ProfFlags.doHeapProfile) {
400 /* Initialise the log file name */
401 hp_filename = stgMallocBytes(strlen(prog_name) + 6, "hpFileName");
402 sprintf(hp_filename, "%s.hp", prog_name);
404 /* open the log file */
405 if ((hp_file = fopen(hp_filename, "w")) == NULL) {
406 debugBelch("Can't open profiling report file %s\n",
408 RtsFlags.ProfFlags.doHeapProfile = 0;
416 void endProfiling( void )
420 #endif /* !PROFILING */
423 printSample(rtsBool beginSample, StgDouble sampleValue)
425 StgDouble fractionalPart, integralPart;
426 fractionalPart = modf(sampleValue, &integralPart);
427 fprintf(hp_file, "%s %" FMT_Word64 ".%02" FMT_Word64 "\n",
428 (beginSample ? "BEGIN_SAMPLE" : "END_SAMPLE"),
429 (StgWord64)integralPart, (StgWord64)(fractionalPart * 100));
432 /* --------------------------------------------------------------------------
433 * Initialize the heap profilier
434 * ----------------------------------------------------------------------- */
436 initHeapProfiling(void)
438 if (! RtsFlags.ProfFlags.doHeapProfile) {
443 if (doingLDVProfiling() && doingRetainerProfiling()) {
444 errorBelch("cannot mix -hb and -hr");
445 stg_exit(EXIT_FAILURE);
449 // we only count eras if we're doing LDV profiling. Otherwise era
452 if (doingLDVProfiling()) {
460 // max_era = 2^LDV_SHIFT
461 max_era = 1 << LDV_SHIFT;
464 censuses = stgMallocBytes(sizeof(Census) * n_censuses, "initHeapProfiling");
466 initEra( &censuses[era] );
468 /* initProfilingLogFile(); */
469 fprintf(hp_file, "JOB \"%s", prog_name);
474 for(count = 1; count < prog_argc; count++)
475 fprintf(hp_file, " %s", prog_argv[count]);
476 fprintf(hp_file, " +RTS");
477 for(count = 0; count < rts_argc; count++)
478 fprintf(hp_file, " %s", rts_argv[count]);
480 #endif /* PROFILING */
482 fprintf(hp_file, "\"\n" );
484 fprintf(hp_file, "DATE \"%s\"\n", time_str());
486 fprintf(hp_file, "SAMPLE_UNIT \"seconds\"\n");
487 fprintf(hp_file, "VALUE_UNIT \"bytes\"\n");
489 printSample(rtsTrue, 0);
490 printSample(rtsFalse, 0);
493 if (doingRetainerProfiling()) {
494 initRetainerProfiling();
502 endHeapProfiling(void)
506 if (! RtsFlags.ProfFlags.doHeapProfile) {
511 if (doingRetainerProfiling()) {
512 endRetainerProfiling();
517 if (doingLDVProfiling()) {
520 aggregateCensusInfo();
521 for (t = 1; t < era; t++) {
522 dumpCensus( &censuses[t] );
528 if (doingLDVProfiling()) {
530 for (t = 1; t <= era; t++) {
531 freeEra( &censuses[t] );
534 freeEra( &censuses[0] );
537 freeEra( &censuses[0] );
542 seconds = mut_user_time();
543 printSample(rtsTrue, seconds);
544 printSample(rtsFalse, seconds);
552 buf_append(char *p, const char *q, char *end)
556 for (m = 0; p < end; p++, q++, m++) {
558 if (*q == '\0') { break; }
564 fprint_ccs(FILE *fp, CostCentreStack *ccs, nat max_length)
566 char buf[max_length+1], *p, *buf_end;
568 // MAIN on its own gets printed as "MAIN", otherwise we ignore MAIN.
569 if (ccs == CCS_MAIN) {
574 fprintf(fp, "(%ld)", ccs->ccsID);
577 buf_end = buf + max_length + 1;
579 // keep printing components of the stack until we run out of space
580 // in the buffer. If we run out of space, end with "...".
581 for (; ccs != NULL && ccs != CCS_MAIN; ccs = ccs->prevStack) {
583 // CAF cost centres print as M.CAF, but we leave the module
584 // name out of all the others to save space.
585 if (!strcmp(ccs->cc->label,"CAF")) {
586 p += buf_append(p, ccs->cc->module, buf_end);
587 p += buf_append(p, ".CAF", buf_end);
589 p += buf_append(p, ccs->cc->label, buf_end);
590 if (ccs->prevStack != NULL && ccs->prevStack != CCS_MAIN) {
591 p += buf_append(p, "/", buf_end);
596 sprintf(buf+max_length-4, "...");
600 fprintf(fp, "%s", buf);
602 #endif /* PROFILING */
605 strMatchesSelector( char* str, char* sel )
608 // debugBelch("str_matches_selector %s %s\n", str, sel);
610 // Compare str against wherever we've got to in sel.
612 while (*p != '\0' && *sel != ',' && *sel != '\0' && *p == *sel) {
615 // Match if all of str used and have reached the end of a sel fragment.
616 if (*p == '\0' && (*sel == ',' || *sel == '\0'))
619 // No match. Advance sel to the start of the next elem.
620 while (*sel != ',' && *sel != '\0') sel++;
621 if (*sel == ',') sel++;
623 /* Run out of sel ?? */
624 if (*sel == '\0') return rtsFalse;
628 /* -----------------------------------------------------------------------------
629 * Figure out whether a closure should be counted in this census, by
630 * testing against all the specified constraints.
631 * -------------------------------------------------------------------------- */
633 closureSatisfiesConstraints( StgClosure* p )
635 #if !defined(PROFILING)
636 (void)p; /* keep gcc -Wall happy */
641 // The CCS has a selected field to indicate whether this closure is
642 // deselected by not being mentioned in the module, CC, or CCS
644 if (!p->header.prof.ccs->selected) {
648 if (RtsFlags.ProfFlags.descrSelector) {
649 b = strMatchesSelector( (GET_PROF_DESC(get_itbl((StgClosure *)p))),
650 RtsFlags.ProfFlags.descrSelector );
651 if (!b) return rtsFalse;
653 if (RtsFlags.ProfFlags.typeSelector) {
654 b = strMatchesSelector( (GET_PROF_TYPE(get_itbl((StgClosure *)p))),
655 RtsFlags.ProfFlags.typeSelector );
656 if (!b) return rtsFalse;
658 if (RtsFlags.ProfFlags.retainerSelector) {
661 // We must check that the retainer set is valid here. One
662 // reason it might not be valid is if this closure is a
663 // a newly deceased weak pointer (i.e. a DEAD_WEAK), since
664 // these aren't reached by the retainer profiler's traversal.
665 if (isRetainerSetFieldValid((StgClosure *)p)) {
666 rs = retainerSetOf((StgClosure *)p);
668 for (i = 0; i < rs->num; i++) {
669 b = strMatchesSelector( rs->element[i]->cc->label,
670 RtsFlags.ProfFlags.retainerSelector );
671 if (b) return rtsTrue;
678 #endif /* PROFILING */
681 /* -----------------------------------------------------------------------------
682 * Aggregate the heap census info for biographical profiling
683 * -------------------------------------------------------------------------- */
686 aggregateCensusInfo( void )
690 counter *c, *d, *ctrs;
693 if (!doingLDVProfiling()) return;
695 // Aggregate the LDV counters when displaying by biography.
696 if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
697 int void_total, drag_total;
699 // Now we compute void_total and drag_total for each census
700 // After the program has finished, the void_total field of
701 // each census contains the count of words that were *created*
702 // in this era and were eventually void. Conversely, if a
703 // void closure was destroyed in this era, it will be
704 // represented by a negative count of words in void_total.
706 // To get the count of live words that are void at each
707 // census, just propagate the void_total count forwards:
711 for (t = 1; t < era; t++) { // note: start at 1, not 0
712 void_total += censuses[t].void_total;
713 drag_total += censuses[t].drag_total;
714 censuses[t].void_total = void_total;
715 censuses[t].drag_total = drag_total;
717 ASSERT( censuses[t].void_total <= censuses[t].not_used );
718 // should be true because: void_total is the count of
719 // live words that are void at this census, which *must*
720 // be less than the number of live words that have not
723 ASSERT( censuses[t].drag_total <= censuses[t].used );
724 // similar reasoning as above.
730 // otherwise... we're doing a heap profile that is restricted to
731 // some combination of lag, drag, void or use. We've kept all the
732 // census info for all censuses so far, but we still need to
733 // aggregate the counters forwards.
736 acc = allocHashTable();
739 for (t = 1; t < era; t++) {
741 // first look through all the counters we're aggregating
742 for (c = ctrs; c != NULL; c = c->next) {
743 // if one of the totals is non-zero, then this closure
744 // type must be present in the heap at this census time...
745 d = lookupHashTable(censuses[t].hash, (StgWord)c->identity);
748 // if this closure identity isn't present in the
749 // census for this time period, then our running
750 // totals *must* be zero.
751 ASSERT(c->c.ldv.void_total == 0 && c->c.ldv.drag_total == 0);
753 // debugCCS(c->identity);
754 // debugBelch(" census=%d void_total=%d drag_total=%d\n",
755 // t, c->c.ldv.void_total, c->c.ldv.drag_total);
757 d->c.ldv.void_total += c->c.ldv.void_total;
758 d->c.ldv.drag_total += c->c.ldv.drag_total;
759 c->c.ldv.void_total = d->c.ldv.void_total;
760 c->c.ldv.drag_total = d->c.ldv.drag_total;
762 ASSERT( c->c.ldv.void_total >= 0 );
763 ASSERT( c->c.ldv.drag_total >= 0 );
767 // now look through the counters in this census to find new ones
768 for (c = censuses[t].ctrs; c != NULL; c = c->next) {
769 d = lookupHashTable(acc, (StgWord)c->identity);
771 d = arenaAlloc( arena, sizeof(counter) );
773 insertHashTable( acc, (StgWord)c->identity, d );
774 d->identity = c->identity;
777 d->c.ldv.void_total = c->c.ldv.void_total;
778 d->c.ldv.drag_total = c->c.ldv.drag_total;
780 ASSERT( c->c.ldv.void_total >= 0 );
781 ASSERT( c->c.ldv.drag_total >= 0 );
785 freeHashTable(acc, NULL);
790 /* -----------------------------------------------------------------------------
791 * Print out the results of a heap census.
792 * -------------------------------------------------------------------------- */
794 dumpCensus( Census *census )
799 printSample(rtsTrue, census->time);
802 if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
803 fprintf(hp_file, "VOID\t%lu\n", (unsigned long)(census->void_total) * sizeof(W_));
804 fprintf(hp_file, "LAG\t%lu\n",
805 (unsigned long)(census->not_used - census->void_total) * sizeof(W_));
806 fprintf(hp_file, "USE\t%lu\n",
807 (unsigned long)(census->used - census->drag_total) * sizeof(W_));
808 fprintf(hp_file, "INHERENT_USE\t%lu\n",
809 (unsigned long)(census->prim) * sizeof(W_));
810 fprintf(hp_file, "DRAG\t%lu\n",
811 (unsigned long)(census->drag_total) * sizeof(W_));
812 printSample(rtsFalse, census->time);
817 for (ctr = census->ctrs; ctr != NULL; ctr = ctr->next) {
820 if (RtsFlags.ProfFlags.bioSelector != NULL) {
822 if (strMatchesSelector("lag", RtsFlags.ProfFlags.bioSelector))
823 count += ctr->c.ldv.not_used - ctr->c.ldv.void_total;
824 if (strMatchesSelector("drag", RtsFlags.ProfFlags.bioSelector))
825 count += ctr->c.ldv.drag_total;
826 if (strMatchesSelector("void", RtsFlags.ProfFlags.bioSelector))
827 count += ctr->c.ldv.void_total;
828 if (strMatchesSelector("use", RtsFlags.ProfFlags.bioSelector))
829 count += ctr->c.ldv.used - ctr->c.ldv.drag_total;
833 count = ctr->c.resid;
836 ASSERT( count >= 0 );
838 if (count == 0) continue;
840 #if !defined(PROFILING)
841 switch (RtsFlags.ProfFlags.doHeapProfile) {
842 case HEAP_BY_CLOSURE_TYPE:
843 fprintf(hp_file, "%s", (char *)ctr->identity);
849 switch (RtsFlags.ProfFlags.doHeapProfile) {
851 fprint_ccs(hp_file, (CostCentreStack *)ctr->identity, RtsFlags.ProfFlags.ccsLength);
856 fprintf(hp_file, "%s", (char *)ctr->identity);
858 case HEAP_BY_RETAINER:
860 RetainerSet *rs = (RetainerSet *)ctr->identity;
862 // it might be the distinguished retainer set rs_MANY:
863 if (rs == &rs_MANY) {
864 fprintf(hp_file, "MANY");
868 // Mark this retainer set by negating its id, because it
869 // has appeared in at least one census. We print the
870 // values of all such retainer sets into the log file at
871 // the end. A retainer set may exist but not feature in
872 // any censuses if it arose as the intermediate retainer
873 // set for some closure during retainer set calculation.
877 // report in the unit of bytes: * sizeof(StgWord)
878 printRetainerSetShort(hp_file, rs);
882 barf("dumpCensus; doHeapProfile");
886 fprintf(hp_file, "\t%lu\n", (unsigned long)count * sizeof(W_));
889 printSample(rtsFalse, census->time);
892 /* -----------------------------------------------------------------------------
893 * Code to perform a heap census.
894 * -------------------------------------------------------------------------- */
896 heapCensusChain( Census *census, bdescr *bd )
906 for (; bd != NULL; bd = bd->link) {
908 // HACK: ignore pinned blocks, because they contain gaps.
909 // It's not clear exactly what we'd like to do here, since we
910 // can't tell which objects in the block are actually alive.
911 // Perhaps the whole block should be counted as SYSTEM memory.
912 if (bd->flags & BF_PINNED) {
917 while (p < bd->free) {
918 info = get_itbl((StgClosure *)p);
921 switch (info->type) {
924 size = thunk_sizeW_fromITBL(info);
930 size = sizeofW(StgThunkHeader) + 2;
936 size = sizeofW(StgThunkHeader) + 1;
943 case IND_OLDGEN_PERM:
945 case SE_CAF_BLACKHOLE:
958 size = sizeW_fromITBL(info);
962 // Special case/Delicate Hack: INDs don't normally
963 // appear, since we're doing this heap census right
964 // after GC. However, GarbageCollect() also does
965 // resurrectThreads(), which can update some
966 // blackholes when it calls raiseAsync() on the
967 // resurrected threads. So we know that any IND will
968 // be the size of a BLACKHOLE.
969 size = BLACKHOLE_sizeW();
974 size = bco_sizeW((StgBCO *)p);
983 size = sizeW_fromITBL(info);
987 size = ap_sizeW((StgAP *)p);
991 size = pap_sizeW((StgPAP *)p);
995 size = ap_stack_sizeW((StgAP_STACK *)p);
1000 size = arr_words_sizeW(stgCast(StgArrWords*,p));
1003 case MUT_ARR_PTRS_CLEAN:
1004 case MUT_ARR_PTRS_DIRTY:
1005 case MUT_ARR_PTRS_FROZEN:
1006 case MUT_ARR_PTRS_FROZEN0:
1008 size = mut_arr_ptrs_sizeW((StgMutArrPtrs *)p);
1014 if (RtsFlags.ProfFlags.includeTSOs) {
1015 size = tso_sizeW((StgTSO *)p);
1018 // Skip this TSO and move on to the next object
1019 p += tso_sizeW((StgTSO *)p);
1023 size = tso_sizeW((StgTSO *)p);
1029 size = sizeofW(StgTRecHeader);
1032 case TVAR_WATCH_QUEUE:
1034 size = sizeofW(StgTVarWatchQueue);
1037 case INVARIANT_CHECK_QUEUE:
1039 size = sizeofW(StgInvariantCheckQueue);
1042 case ATOMIC_INVARIANT:
1044 size = sizeofW(StgAtomicInvariant);
1049 size = sizeofW(StgTVar);
1054 size = sizeofW(StgTRecChunk);
1058 barf("heapCensus, unknown object: %d", info->type);
1064 // subtract the profiling overhead
1065 real_size = size - sizeofW(StgProfHeader);
1070 if (closureSatisfiesConstraints((StgClosure*)p)) {
1072 if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
1074 census->prim += real_size;
1075 else if ((LDVW(p) & LDV_STATE_MASK) == LDV_STATE_CREATE)
1076 census->not_used += real_size;
1078 census->used += real_size;
1082 identity = closureIdentity((StgClosure *)p);
1084 if (identity != NULL) {
1085 ctr = lookupHashTable( census->hash, (StgWord)identity );
1088 if (RtsFlags.ProfFlags.bioSelector != NULL) {
1090 ctr->c.ldv.prim += real_size;
1091 else if ((LDVW(p) & LDV_STATE_MASK) == LDV_STATE_CREATE)
1092 ctr->c.ldv.not_used += real_size;
1094 ctr->c.ldv.used += real_size;
1098 ctr->c.resid += real_size;
1101 ctr = arenaAlloc( census->arena, sizeof(counter) );
1103 insertHashTable( census->hash, (StgWord)identity, ctr );
1104 ctr->identity = identity;
1105 ctr->next = census->ctrs;
1109 if (RtsFlags.ProfFlags.bioSelector != NULL) {
1111 ctr->c.ldv.prim = real_size;
1112 else if ((LDVW(p) & LDV_STATE_MASK) == LDV_STATE_CREATE)
1113 ctr->c.ldv.not_used = real_size;
1115 ctr->c.ldv.used = real_size;
1119 ctr->c.resid = real_size;
1137 census = &censuses[era];
1138 census->time = mut_user_time();
1140 // calculate retainer sets if necessary
1142 if (doingRetainerProfiling()) {
1148 stat_startHeapCensus();
1151 // Traverse the heap, collecting the census info
1153 // First the small_alloc_list: we have to fix the free pointer at
1154 // the end by calling tidyAllocatedLists() first.
1155 tidyAllocateLists();
1156 heapCensusChain( census, small_alloc_list );
1158 // Now traverse the heap in each generation/step.
1159 if (RtsFlags.GcFlags.generations == 1) {
1160 heapCensusChain( census, g0s0->blocks );
1162 for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
1163 for (s = 0; s < generations[g].n_steps; s++) {
1164 heapCensusChain( census, generations[g].steps[s].blocks );
1165 // Are we interested in large objects? might be
1166 // confusing to include the stack in a heap profile.
1167 heapCensusChain( census, generations[g].steps[s].large_objects );
1172 // dump out the census info
1174 // We can't generate any info for LDV profiling until
1175 // the end of the run...
1176 if (!doingLDVProfiling())
1177 dumpCensus( census );
1179 dumpCensus( census );
1183 // free our storage, unless we're keeping all the census info for
1184 // future restriction by biography.
1186 if (RtsFlags.ProfFlags.bioSelector == NULL)
1188 freeHashTable( census->hash, NULL/* don't free the elements */ );
1189 arenaFree( census->arena );
1190 census->hash = NULL;
1191 census->arena = NULL;
1195 // we're into the next time period now
1199 stat_endHeapCensus();