1 /* -----------------------------------------------------------------------------
2 * $Id: DebugProf.c,v 1.7 1999/09/15 13:45:16 simonmar Exp $
4 * (c) The GHC Team 1998-1999
6 * Simple Heap Profiling
8 * ---------------------------------------------------------------------------*/
12 #include "BlockAlloc.h"
13 #include "DebugProf.h"
18 #if defined(DEBUG) && ! defined(PROFILING)
20 char prof_filename[128];
23 static void clear_table_data(void);
24 static void fprint_data(FILE *fp);
26 /* -----------------------------------------------------------------------------
28 -------------------------------------------------------------------------- */
31 heapCensus(bdescr *bd)
34 const StgInfoTable *info;
38 /* usertime() isn't very accurate, since it includes garbage
39 * collection time. We really want elapsed_mutator_time or
43 fprintf(prof_file, "BEGIN_SAMPLE %0.2f\n", time);
47 while (p < bd->free) {
48 info = get_itbl((StgClosure *)p);
52 size = bco_sizeW((StgBCO *)p);
69 case CONSTR_NOCAF_STATIC:
73 size = sizeW_fromITBL(info);
77 size = sizeofW(StgHeader) + MIN_UPD_SIZE;
82 size = sizeofW(StgInd);
85 case AP_UPD: /* we can treat this as being the same as a PAP */
87 size = pap_sizeW((StgPAP *)p);
91 size = arr_words_sizeW(stgCast(StgArrWords*,p));
95 case MUT_ARR_PTRS_FROZEN:
96 size = mut_arr_ptrs_sizeW((StgMutArrPtrs *)p);
100 size = tso_sizeW((StgTSO *)p);
106 switch (RtsFlags.ProfFlags.doHeapProfile) {
107 case HEAP_BY_INFOPTR:
108 add_data((void *)(*p), size * sizeof(W_));
110 case HEAP_BY_CLOSURE_TYPE:
111 closure_types[info->type] += size * sizeof(W_);
119 switch (RtsFlags.ProfFlags.doHeapProfile) {
120 case HEAP_BY_INFOPTR:
121 fprint_data(prof_file);
123 case HEAP_BY_CLOSURE_TYPE:
124 fprint_closure_types(prof_file);
128 fprintf(prof_file, "END_SAMPLE %0.2f\n", time);