[project @ 2000-11-13 14:40:36 by simonmar]
[ghc-hetmet.git] / ghc / rts / ProfHeap.c
index 7013498..6792a11 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: ProfHeap.c,v 1.11 2000/04/05 15:32:08 simonmar Exp $
+ * $Id: ProfHeap.c,v 1.18 2000/11/13 14:40:37 simonmar Exp $
  *
  * (c) The GHC Team, 1998-2000
  *
@@ -32,8 +32,6 @@ static void clear_table_data(void);
 static void fprint_data(FILE *fp);
 #endif
 
-char prof_filename[128];       /* urk */
-
 /* -----------------------------------------------------------------------------
  * Hash tables.
  *
@@ -52,6 +50,7 @@ char prof_filename[128];      /* urk */
  *
  * -------------------------------------------------------------------------- */
 
+#ifdef PROFILING
 typedef struct _ctr {
     const char *str;
     unsigned long mem_resid;
@@ -144,11 +143,12 @@ reportCtrResid(FILE *fp)
        }
     }
 }
+#endif /* PROFILING */
 
 /* -------------------------------------------------------------------------- */
 
 #ifdef DEBUG_HEAP_PROF
-FILE *prof_file;
+FILE *hp_file;
 
 void initProfiling1( void )
 {
@@ -172,14 +172,14 @@ initHeapProfiling(void)
         return 0;
     }
 
-    fprintf(prof_file, "JOB \"%s\"\n", prog_argv[0]);
-    fprintf(prof_file, "DATE \"%s\"\n", time_str());
+    fprintf(hp_file, "JOB \"%s\"\n", prog_argv[0]);
+    fprintf(hp_file, "DATE \"%s\"\n", time_str());
 
-    fprintf(prof_file, "SAMPLE_UNIT \"seconds\"\n");
-    fprintf(prof_file, "VALUE_UNIT \"bytes\"\n");
+    fprintf(hp_file, "SAMPLE_UNIT \"seconds\"\n");
+    fprintf(hp_file, "VALUE_UNIT \"bytes\"\n");
 
-    fprintf(prof_file, "BEGIN_SAMPLE 0.00\n");
-    fprintf(prof_file, "END_SAMPLE 0.00\n");
+    fprintf(hp_file, "BEGIN_SAMPLE 0.00\n");
+    fprintf(hp_file, "END_SAMPLE 0.00\n");
 
 #ifdef DEBUG_HEAP_PROF
     DEBUG_LoadSymbols(prog_argv[0]);
@@ -203,9 +203,9 @@ endHeapProfiling(void)
     }
 
     seconds = mut_user_time();
-    fprintf(prof_file, "BEGIN_SAMPLE %0.2f\n", seconds);
-    fprintf(prof_file, "END_SAMPLE %0.2f\n", seconds);
-    fclose(prof_file);
+    fprintf(hp_file, "BEGIN_SAMPLE %0.2f\n", seconds);
+    fprintf(hp_file, "END_SAMPLE %0.2f\n", seconds);
+    fclose(hp_file);
 }
 
 #ifdef DEBUG_HEAP_PROF
@@ -483,7 +483,7 @@ heapCensus(void)
   bd = g0s0->to_space;
 
   time = mut_user_time_during_GC();
-  fprintf(prof_file, "BEGIN_SAMPLE %0.2f\n", time);
+  fprintf(hp_file, "BEGIN_SAMPLE %0.2f\n", time);
   
   while (bd != NULL) {
     p = bd->start;
@@ -496,9 +496,10 @@ heapCensus(void)
        break;
        
       case CONSTR:
-       if (((StgClosure *)p)->header.info == &DEAD_WEAK_info) {
-         size = sizeofW(StgWeak);
-         break;
+       if (((StgClosure *)p)->header.info == &stg_DEAD_WEAK_info
+           && !(LOOKS_LIKE_GHC_INFO(*(p + sizeW_fromITBL(info))))) {
+           size = sizeofW(StgWeak);
+           break;
        }
        /* else, fall through... */
 
@@ -602,10 +603,10 @@ heapCensus(void)
 #ifdef DEBUG_HEAP_PROF
   switch (RtsFlags.ProfFlags.doHeapProfile) {
   case HEAP_BY_INFOPTR:
-    fprint_data(prof_file);
+    fprint_data(hp_file);
     break;
   case HEAP_BY_CLOSURE_TYPE:
-    fprint_closure_types(prof_file);
+    fprint_closure_types(hp_file);
     break;
   }
 #endif
@@ -613,19 +614,19 @@ heapCensus(void)
 #ifdef PROFILING
   switch (RtsFlags.ProfFlags.doHeapProfile) {
   case HEAP_BY_CCS:
-      reportCCSResid(prof_file,CCS_MAIN);
+      reportCCSResid(hp_file,CCS_MAIN);
       break;
   case HEAP_BY_MOD:
   case HEAP_BY_DESCR:
   case HEAP_BY_TYPE:
-      reportCtrResid(prof_file);
+      reportCtrResid(hp_file);
       break;
   default:
       barf("heapCensus; doHeapProfile");
   }
 #endif
 
-  fprintf(prof_file, "END_SAMPLE %0.2f\n", time);
+  fprintf(hp_file, "END_SAMPLE %0.2f\n", time);
 }    
 
 #endif /* PROFILING || DEBUG_HEAP_PROF */