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"
23 /* -----------------------------------------------------------------------------
24 * era stores the current time period. It is the same as the
25 * number of censuses that have been performed.
28 * era must be no longer than LDV_SHIFT (15 or 30) bits.
30 * era is initialized to 1 in initHeapProfiling().
32 * max_era is initialized to 2^LDV_SHIFT in initHeapProfiling().
33 * When era reaches max_era, the profiling stops because a closure can
34 * store only up to (max_era - 1) as its creation or last use time.
35 * -------------------------------------------------------------------------- */
39 /* -----------------------------------------------------------------------------
42 * For most heap profiles each closure identity gets a simple count
43 * of live words in the heap at each census. However, if we're
44 * selecting by biography, then we have to keep the various
45 * lag/drag/void counters for each identity.
46 * -------------------------------------------------------------------------- */
47 typedef struct _counter {
52 int prim; // total size of 'inherently used' closures
53 int not_used; // total size of 'never used' closures
54 int used; // total size of 'used at least once' closures
55 int void_total; // current total size of 'destroyed without being used' closures
56 int drag_total; // current total size of 'used at least once and waiting to die'
59 struct _counter *next;
63 initLDVCtr( counter *ctr )
66 ctr->c.ldv.not_used = 0;
68 ctr->c.ldv.void_total = 0;
69 ctr->c.ldv.drag_total = 0;
73 double time; // the time in MUT time when the census is made
78 // for LDV profiling, when just displaying by LDV
86 static Census *censuses = NULL;
87 static nat n_censuses = 0;
90 static void aggregateCensusInfo( void );
93 static void dumpCensus( Census *census );
95 static rtsBool closureSatisfiesConstraints( StgClosure* p );
97 /* ----------------------------------------------------------------------------
98 * Find the "closure identity", which is a unique pointer reresenting
99 * the band to which this closure's heap space is attributed in the
101 * ------------------------------------------------------------------------- */
103 closureIdentity( StgClosure *p )
105 switch (RtsFlags.ProfFlags.doHeapProfile) {
109 return p->header.prof.ccs;
111 return p->header.prof.ccs->cc->module;
113 return GET_PROF_DESC(get_itbl(p));
115 return GET_PROF_TYPE(get_itbl(p));
116 case HEAP_BY_RETAINER:
117 // AFAIK, the only closures in the heap which might not have a
118 // valid retainer set are DEAD_WEAK closures.
119 if (isRetainerSetFieldValid(p))
120 return retainerSetOf(p);
125 case HEAP_BY_CLOSURE_TYPE:
129 switch (info->type) {
137 case CONSTR_NOCAF_STATIC:
138 return GET_CON_DESC(itbl_to_con_itbl(info));
140 return closure_type_names[info->type];
146 barf("closureIdentity");
150 /* --------------------------------------------------------------------------
151 * Profiling type predicates
152 * ----------------------------------------------------------------------- */
154 STATIC_INLINE rtsBool
155 doingLDVProfiling( void )
157 return (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV
158 || RtsFlags.ProfFlags.bioSelector != NULL);
161 STATIC_INLINE rtsBool
162 doingRetainerProfiling( void )
164 return (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_RETAINER
165 || RtsFlags.ProfFlags.retainerSelector != NULL);
167 #endif /* PROFILING */
169 // Precesses a closure 'c' being destroyed whose size is 'size'.
170 // Make sure that LDV_recordDead() is not invoked on 'inherently used' closures
171 // such as TSO; they should not be involved in computing dragNew or voidNew.
173 // Even though era is checked in both LdvCensusForDead() and
174 // LdvCensusKillAll(), we still need to make sure that era is > 0 because
175 // LDV_recordDead() may be called from elsewhere in the runtime system. E.g.,
176 // when a thunk is replaced by an indirection object.
180 LDV_recordDead( StgClosure *c, nat size )
186 if (era > 0 && closureSatisfiesConstraints(c)) {
187 size -= sizeofW(StgProfHeader);
188 ASSERT(LDVW(c) != 0);
189 if ((LDVW((c)) & LDV_STATE_MASK) == LDV_STATE_CREATE) {
190 t = (LDVW((c)) & LDV_CREATE_MASK) >> LDV_SHIFT;
192 if (RtsFlags.ProfFlags.bioSelector == NULL) {
193 censuses[t].void_total += (int)size;
194 censuses[era].void_total -= (int)size;
195 ASSERT(censuses[t].void_total < censuses[t].not_used);
197 id = closureIdentity(c);
198 ctr = lookupHashTable(censuses[t].hash, (StgWord)id);
199 ASSERT( ctr != NULL );
200 ctr->c.ldv.void_total += (int)size;
201 ctr = lookupHashTable(censuses[era].hash, (StgWord)id);
203 ctr = arenaAlloc(censuses[era].arena, sizeof(counter));
205 insertHashTable(censuses[era].hash, (StgWord)id, ctr);
207 ctr->next = censuses[era].ctrs;
208 censuses[era].ctrs = ctr;
210 ctr->c.ldv.void_total -= (int)size;
214 t = LDVW((c)) & LDV_LAST_MASK;
216 if (RtsFlags.ProfFlags.bioSelector == NULL) {
217 censuses[t+1].drag_total += size;
218 censuses[era].drag_total -= size;
221 id = closureIdentity(c);
222 ctr = lookupHashTable(censuses[t+1].hash, (StgWord)id);
223 ASSERT( ctr != NULL );
224 ctr->c.ldv.drag_total += (int)size;
225 ctr = lookupHashTable(censuses[era].hash, (StgWord)id);
227 ctr = arenaAlloc(censuses[era].arena, sizeof(counter));
229 insertHashTable(censuses[era].hash, (StgWord)id, ctr);
231 ctr->next = censuses[era].ctrs;
232 censuses[era].ctrs = ctr;
234 ctr->c.ldv.drag_total -= (int)size;
242 /* --------------------------------------------------------------------------
243 * Initialize censuses[era];
244 * ----------------------------------------------------------------------- */
247 initEra(Census *census)
249 census->hash = allocHashTable();
251 census->arena = newArena();
253 census->not_used = 0;
256 census->void_total = 0;
257 census->drag_total = 0;
261 freeEra(Census *census)
263 if (RtsFlags.ProfFlags.bioSelector != NULL)
264 // when bioSelector==NULL, these are freed in heapCensus()
266 arenaFree(census->arena);
267 freeHashTable(census->hash, NULL);
271 /* --------------------------------------------------------------------------
272 * Increases era by 1 and initialize census[era].
273 * Reallocates gi[] and increases its size if needed.
274 * ----------------------------------------------------------------------- */
280 if (doingLDVProfiling()) {
283 if (era == max_era) {
284 errorBelch("maximum number of censuses reached; use +RTS -i to reduce");
285 stg_exit(EXIT_FAILURE);
288 if (era == n_censuses) {
290 censuses = stgReallocBytes(censuses, sizeof(Census) * n_censuses,
294 #endif /* PROFILING */
296 initEra( &censuses[era] );
299 /* ----------------------------------------------------------------------------
300 * Heap profiling by info table
301 * ------------------------------------------------------------------------- */
303 #if !defined(PROFILING)
305 static char *hp_filename;
307 void initProfiling1 (void)
311 void freeProfiling1 (void)
315 void initProfiling2 (void)
319 prog = stgMallocBytes(strlen(prog_name) + 1, "initProfiling2");
320 strcpy(prog, prog_name);
321 #ifdef mingw32_HOST_OS
322 // on Windows, drop the .exe suffix if there is one
325 suff = strrchr(prog,'.');
326 if (suff != NULL && !strcmp(suff,".exe")) {
332 if (RtsFlags.ProfFlags.doHeapProfile) {
333 /* Initialise the log file name */
334 hp_filename = stgMallocBytes(strlen(prog) + 6, "hpFileName");
335 sprintf(hp_filename, "%s.hp", prog);
337 /* open the log file */
338 if ((hp_file = fopen(hp_filename, "w")) == NULL) {
339 debugBelch("Can't open profiling report file %s\n",
341 RtsFlags.ProfFlags.doHeapProfile = 0;
351 void endProfiling( void )
355 #endif /* !PROFILING */
358 printSample(rtsBool beginSample, StgDouble sampleValue)
360 StgDouble fractionalPart, integralPart;
361 fractionalPart = modf(sampleValue, &integralPart);
362 fprintf(hp_file, "%s %" FMT_Word64 ".%02" FMT_Word64 "\n",
363 (beginSample ? "BEGIN_SAMPLE" : "END_SAMPLE"),
364 (StgWord64)integralPart, (StgWord64)(fractionalPart * 100));
367 /* --------------------------------------------------------------------------
368 * Initialize the heap profilier
369 * ----------------------------------------------------------------------- */
371 initHeapProfiling(void)
373 if (! RtsFlags.ProfFlags.doHeapProfile) {
378 if (doingLDVProfiling() && doingRetainerProfiling()) {
379 errorBelch("cannot mix -hb and -hr");
380 stg_exit(EXIT_FAILURE);
384 // we only count eras if we're doing LDV profiling. Otherwise era
387 if (doingLDVProfiling()) {
395 // max_era = 2^LDV_SHIFT
396 max_era = 1 << LDV_SHIFT;
399 censuses = stgMallocBytes(sizeof(Census) * n_censuses, "initHeapProfiling");
401 initEra( &censuses[era] );
403 /* initProfilingLogFile(); */
404 fprintf(hp_file, "JOB \"%s", prog_name);
409 for(count = 1; count < prog_argc; count++)
410 fprintf(hp_file, " %s", prog_argv[count]);
411 fprintf(hp_file, " +RTS");
412 for(count = 0; count < rts_argc; count++)
413 fprintf(hp_file, " %s", rts_argv[count]);
415 #endif /* PROFILING */
417 fprintf(hp_file, "\"\n" );
419 fprintf(hp_file, "DATE \"%s\"\n", time_str());
421 fprintf(hp_file, "SAMPLE_UNIT \"seconds\"\n");
422 fprintf(hp_file, "VALUE_UNIT \"bytes\"\n");
424 printSample(rtsTrue, 0);
425 printSample(rtsFalse, 0);
428 if (doingRetainerProfiling()) {
429 initRetainerProfiling();
437 endHeapProfiling(void)
441 if (! RtsFlags.ProfFlags.doHeapProfile) {
446 if (doingRetainerProfiling()) {
447 endRetainerProfiling();
452 if (doingLDVProfiling()) {
455 aggregateCensusInfo();
456 for (t = 1; t < era; t++) {
457 dumpCensus( &censuses[t] );
463 if (doingLDVProfiling()) {
465 for (t = 1; t <= era; t++) {
466 freeEra( &censuses[t] );
469 freeEra( &censuses[0] );
472 freeEra( &censuses[0] );
477 seconds = mut_user_time();
478 printSample(rtsTrue, seconds);
479 printSample(rtsFalse, seconds);
487 buf_append(char *p, const char *q, char *end)
491 for (m = 0; p < end; p++, q++, m++) {
493 if (*q == '\0') { break; }
499 fprint_ccs(FILE *fp, CostCentreStack *ccs, nat max_length)
501 char buf[max_length+1], *p, *buf_end;
503 // MAIN on its own gets printed as "MAIN", otherwise we ignore MAIN.
504 if (ccs == CCS_MAIN) {
509 fprintf(fp, "(%ld)", ccs->ccsID);
512 buf_end = buf + max_length + 1;
514 // keep printing components of the stack until we run out of space
515 // in the buffer. If we run out of space, end with "...".
516 for (; ccs != NULL && ccs != CCS_MAIN; ccs = ccs->prevStack) {
518 // CAF cost centres print as M.CAF, but we leave the module
519 // name out of all the others to save space.
520 if (!strcmp(ccs->cc->label,"CAF")) {
521 p += buf_append(p, ccs->cc->module, buf_end);
522 p += buf_append(p, ".CAF", buf_end);
524 p += buf_append(p, ccs->cc->label, buf_end);
525 if (ccs->prevStack != NULL && ccs->prevStack != CCS_MAIN) {
526 p += buf_append(p, "/", buf_end);
531 sprintf(buf+max_length-4, "...");
535 fprintf(fp, "%s", buf);
539 strMatchesSelector( char* str, char* sel )
542 // debugBelch("str_matches_selector %s %s\n", str, sel);
544 // Compare str against wherever we've got to in sel.
546 while (*p != '\0' && *sel != ',' && *sel != '\0' && *p == *sel) {
549 // Match if all of str used and have reached the end of a sel fragment.
550 if (*p == '\0' && (*sel == ',' || *sel == '\0'))
553 // No match. Advance sel to the start of the next elem.
554 while (*sel != ',' && *sel != '\0') sel++;
555 if (*sel == ',') sel++;
557 /* Run out of sel ?? */
558 if (*sel == '\0') return rtsFalse;
562 #endif /* PROFILING */
564 /* -----------------------------------------------------------------------------
565 * Figure out whether a closure should be counted in this census, by
566 * testing against all the specified constraints.
567 * -------------------------------------------------------------------------- */
569 closureSatisfiesConstraints( StgClosure* p )
571 #if !defined(PROFILING)
572 (void)p; /* keep gcc -Wall happy */
577 // The CCS has a selected field to indicate whether this closure is
578 // deselected by not being mentioned in the module, CC, or CCS
580 if (!p->header.prof.ccs->selected) {
584 if (RtsFlags.ProfFlags.descrSelector) {
585 b = strMatchesSelector( (GET_PROF_DESC(get_itbl((StgClosure *)p))),
586 RtsFlags.ProfFlags.descrSelector );
587 if (!b) return rtsFalse;
589 if (RtsFlags.ProfFlags.typeSelector) {
590 b = strMatchesSelector( (GET_PROF_TYPE(get_itbl((StgClosure *)p))),
591 RtsFlags.ProfFlags.typeSelector );
592 if (!b) return rtsFalse;
594 if (RtsFlags.ProfFlags.retainerSelector) {
597 // We must check that the retainer set is valid here. One
598 // reason it might not be valid is if this closure is a
599 // a newly deceased weak pointer (i.e. a DEAD_WEAK), since
600 // these aren't reached by the retainer profiler's traversal.
601 if (isRetainerSetFieldValid((StgClosure *)p)) {
602 rs = retainerSetOf((StgClosure *)p);
604 for (i = 0; i < rs->num; i++) {
605 b = strMatchesSelector( rs->element[i]->cc->label,
606 RtsFlags.ProfFlags.retainerSelector );
607 if (b) return rtsTrue;
614 #endif /* PROFILING */
617 /* -----------------------------------------------------------------------------
618 * Aggregate the heap census info for biographical profiling
619 * -------------------------------------------------------------------------- */
622 aggregateCensusInfo( void )
626 counter *c, *d, *ctrs;
629 if (!doingLDVProfiling()) return;
631 // Aggregate the LDV counters when displaying by biography.
632 if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
633 int void_total, drag_total;
635 // Now we compute void_total and drag_total for each census
636 // After the program has finished, the void_total field of
637 // each census contains the count of words that were *created*
638 // in this era and were eventually void. Conversely, if a
639 // void closure was destroyed in this era, it will be
640 // represented by a negative count of words in void_total.
642 // To get the count of live words that are void at each
643 // census, just propagate the void_total count forwards:
647 for (t = 1; t < era; t++) { // note: start at 1, not 0
648 void_total += censuses[t].void_total;
649 drag_total += censuses[t].drag_total;
650 censuses[t].void_total = void_total;
651 censuses[t].drag_total = drag_total;
653 ASSERT( censuses[t].void_total <= censuses[t].not_used );
654 // should be true because: void_total is the count of
655 // live words that are void at this census, which *must*
656 // be less than the number of live words that have not
659 ASSERT( censuses[t].drag_total <= censuses[t].used );
660 // similar reasoning as above.
666 // otherwise... we're doing a heap profile that is restricted to
667 // some combination of lag, drag, void or use. We've kept all the
668 // census info for all censuses so far, but we still need to
669 // aggregate the counters forwards.
672 acc = allocHashTable();
675 for (t = 1; t < era; t++) {
677 // first look through all the counters we're aggregating
678 for (c = ctrs; c != NULL; c = c->next) {
679 // if one of the totals is non-zero, then this closure
680 // type must be present in the heap at this census time...
681 d = lookupHashTable(censuses[t].hash, (StgWord)c->identity);
684 // if this closure identity isn't present in the
685 // census for this time period, then our running
686 // totals *must* be zero.
687 ASSERT(c->c.ldv.void_total == 0 && c->c.ldv.drag_total == 0);
689 // debugCCS(c->identity);
690 // debugBelch(" census=%d void_total=%d drag_total=%d\n",
691 // t, c->c.ldv.void_total, c->c.ldv.drag_total);
693 d->c.ldv.void_total += c->c.ldv.void_total;
694 d->c.ldv.drag_total += c->c.ldv.drag_total;
695 c->c.ldv.void_total = d->c.ldv.void_total;
696 c->c.ldv.drag_total = d->c.ldv.drag_total;
698 ASSERT( c->c.ldv.void_total >= 0 );
699 ASSERT( c->c.ldv.drag_total >= 0 );
703 // now look through the counters in this census to find new ones
704 for (c = censuses[t].ctrs; c != NULL; c = c->next) {
705 d = lookupHashTable(acc, (StgWord)c->identity);
707 d = arenaAlloc( arena, sizeof(counter) );
709 insertHashTable( acc, (StgWord)c->identity, d );
710 d->identity = c->identity;
713 d->c.ldv.void_total = c->c.ldv.void_total;
714 d->c.ldv.drag_total = c->c.ldv.drag_total;
716 ASSERT( c->c.ldv.void_total >= 0 );
717 ASSERT( c->c.ldv.drag_total >= 0 );
721 freeHashTable(acc, NULL);
726 /* -----------------------------------------------------------------------------
727 * Print out the results of a heap census.
728 * -------------------------------------------------------------------------- */
730 dumpCensus( Census *census )
735 printSample(rtsTrue, census->time);
738 if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
739 fprintf(hp_file, "VOID\t%lu\n", (unsigned long)(census->void_total) * sizeof(W_));
740 fprintf(hp_file, "LAG\t%lu\n",
741 (unsigned long)(census->not_used - census->void_total) * sizeof(W_));
742 fprintf(hp_file, "USE\t%lu\n",
743 (unsigned long)(census->used - census->drag_total) * sizeof(W_));
744 fprintf(hp_file, "INHERENT_USE\t%lu\n",
745 (unsigned long)(census->prim) * sizeof(W_));
746 fprintf(hp_file, "DRAG\t%lu\n",
747 (unsigned long)(census->drag_total) * sizeof(W_));
748 printSample(rtsFalse, census->time);
753 for (ctr = census->ctrs; ctr != NULL; ctr = ctr->next) {
756 if (RtsFlags.ProfFlags.bioSelector != NULL) {
758 if (strMatchesSelector("lag", RtsFlags.ProfFlags.bioSelector))
759 count += ctr->c.ldv.not_used - ctr->c.ldv.void_total;
760 if (strMatchesSelector("drag", RtsFlags.ProfFlags.bioSelector))
761 count += ctr->c.ldv.drag_total;
762 if (strMatchesSelector("void", RtsFlags.ProfFlags.bioSelector))
763 count += ctr->c.ldv.void_total;
764 if (strMatchesSelector("use", RtsFlags.ProfFlags.bioSelector))
765 count += ctr->c.ldv.used - ctr->c.ldv.drag_total;
769 count = ctr->c.resid;
772 ASSERT( count >= 0 );
774 if (count == 0) continue;
776 #if !defined(PROFILING)
777 switch (RtsFlags.ProfFlags.doHeapProfile) {
778 case HEAP_BY_CLOSURE_TYPE:
779 fprintf(hp_file, "%s", (char *)ctr->identity);
785 switch (RtsFlags.ProfFlags.doHeapProfile) {
787 fprint_ccs(hp_file, (CostCentreStack *)ctr->identity, RtsFlags.ProfFlags.ccsLength);
792 fprintf(hp_file, "%s", (char *)ctr->identity);
794 case HEAP_BY_RETAINER:
796 RetainerSet *rs = (RetainerSet *)ctr->identity;
798 // it might be the distinguished retainer set rs_MANY:
799 if (rs == &rs_MANY) {
800 fprintf(hp_file, "MANY");
804 // Mark this retainer set by negating its id, because it
805 // has appeared in at least one census. We print the
806 // values of all such retainer sets into the log file at
807 // the end. A retainer set may exist but not feature in
808 // any censuses if it arose as the intermediate retainer
809 // set for some closure during retainer set calculation.
813 // report in the unit of bytes: * sizeof(StgWord)
814 printRetainerSetShort(hp_file, rs);
818 barf("dumpCensus; doHeapProfile");
822 fprintf(hp_file, "\t%lu\n", (unsigned long)count * sizeof(W_));
825 printSample(rtsFalse, census->time);
828 /* -----------------------------------------------------------------------------
829 * Code to perform a heap census.
830 * -------------------------------------------------------------------------- */
832 heapCensusChain( Census *census, bdescr *bd )
842 for (; bd != NULL; bd = bd->link) {
844 // HACK: ignore pinned blocks, because they contain gaps.
845 // It's not clear exactly what we'd like to do here, since we
846 // can't tell which objects in the block are actually alive.
847 // Perhaps the whole block should be counted as SYSTEM memory.
848 if (bd->flags & BF_PINNED) {
853 while (p < bd->free) {
854 info = get_itbl((StgClosure *)p);
857 switch (info->type) {
860 size = thunk_sizeW_fromITBL(info);
866 size = sizeofW(StgThunkHeader) + 2;
872 size = sizeofW(StgThunkHeader) + 1;
879 case IND_OLDGEN_PERM:
892 size = sizeW_fromITBL(info);
896 // Special case/Delicate Hack: INDs don't normally
897 // appear, since we're doing this heap census right
898 // after GC. However, GarbageCollect() also does
899 // resurrectThreads(), which can update some
900 // blackholes when it calls raiseAsync() on the
901 // resurrected threads. So we know that any IND will
902 // be the size of a BLACKHOLE.
903 size = BLACKHOLE_sizeW();
908 size = bco_sizeW((StgBCO *)p);
918 size = sizeW_fromITBL(info);
922 size = ap_sizeW((StgAP *)p);
926 size = pap_sizeW((StgPAP *)p);
930 size = ap_stack_sizeW((StgAP_STACK *)p);
935 size = arr_words_sizeW((StgArrWords*)p);
938 case MUT_ARR_PTRS_CLEAN:
939 case MUT_ARR_PTRS_DIRTY:
940 case MUT_ARR_PTRS_FROZEN:
941 case MUT_ARR_PTRS_FROZEN0:
943 size = mut_arr_ptrs_sizeW((StgMutArrPtrs *)p);
949 if (RtsFlags.ProfFlags.includeTSOs) {
950 size = tso_sizeW((StgTSO *)p);
953 // Skip this TSO and move on to the next object
954 p += tso_sizeW((StgTSO *)p);
958 size = tso_sizeW((StgTSO *)p);
964 size = sizeofW(StgTRecHeader);
967 case TVAR_WATCH_QUEUE:
969 size = sizeofW(StgTVarWatchQueue);
972 case INVARIANT_CHECK_QUEUE:
974 size = sizeofW(StgInvariantCheckQueue);
977 case ATOMIC_INVARIANT:
979 size = sizeofW(StgAtomicInvariant);
984 size = sizeofW(StgTVar);
989 size = sizeofW(StgTRecChunk);
993 barf("heapCensus, unknown object: %d", info->type);
999 // subtract the profiling overhead
1000 real_size = size - sizeofW(StgProfHeader);
1005 if (closureSatisfiesConstraints((StgClosure*)p)) {
1007 if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
1009 census->prim += real_size;
1010 else if ((LDVW(p) & LDV_STATE_MASK) == LDV_STATE_CREATE)
1011 census->not_used += real_size;
1013 census->used += real_size;
1017 identity = closureIdentity((StgClosure *)p);
1019 if (identity != NULL) {
1020 ctr = lookupHashTable( census->hash, (StgWord)identity );
1023 if (RtsFlags.ProfFlags.bioSelector != NULL) {
1025 ctr->c.ldv.prim += real_size;
1026 else if ((LDVW(p) & LDV_STATE_MASK) == LDV_STATE_CREATE)
1027 ctr->c.ldv.not_used += real_size;
1029 ctr->c.ldv.used += real_size;
1033 ctr->c.resid += real_size;
1036 ctr = arenaAlloc( census->arena, sizeof(counter) );
1038 insertHashTable( census->hash, (StgWord)identity, ctr );
1039 ctr->identity = identity;
1040 ctr->next = census->ctrs;
1044 if (RtsFlags.ProfFlags.bioSelector != NULL) {
1046 ctr->c.ldv.prim = real_size;
1047 else if ((LDVW(p) & LDV_STATE_MASK) == LDV_STATE_CREATE)
1048 ctr->c.ldv.not_used = real_size;
1050 ctr->c.ldv.used = real_size;
1054 ctr->c.resid = real_size;
1072 census = &censuses[era];
1073 census->time = mut_user_time();
1075 // calculate retainer sets if necessary
1077 if (doingRetainerProfiling()) {
1083 stat_startHeapCensus();
1086 // Traverse the heap, collecting the census info
1087 if (RtsFlags.GcFlags.generations == 1) {
1088 heapCensusChain( census, g0s0->blocks );
1090 for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
1091 for (s = 0; s < generations[g].n_steps; s++) {
1092 heapCensusChain( census, generations[g].steps[s].blocks );
1093 // Are we interested in large objects? might be
1094 // confusing to include the stack in a heap profile.
1095 heapCensusChain( census, generations[g].steps[s].large_objects );
1100 // dump out the census info
1102 // We can't generate any info for LDV profiling until
1103 // the end of the run...
1104 if (!doingLDVProfiling())
1105 dumpCensus( census );
1107 dumpCensus( census );
1111 // free our storage, unless we're keeping all the census info for
1112 // future restriction by biography.
1114 if (RtsFlags.ProfFlags.bioSelector == NULL)
1116 freeHashTable( census->hash, NULL/* don't free the elements */ );
1117 arenaFree( census->arena );
1118 census->hash = NULL;
1119 census->arena = NULL;
1123 // we're into the next time period now
1127 stat_endHeapCensus();