[project @ 2001-09-20 16:01:23 by simonpj]
[ghc-hetmet.git] / ghc / rts / ProfHeap.c
index 02b714e..5597792 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: ProfHeap.c,v 1.21 2001/03/14 11:18:18 sewardj Exp $
+ * $Id: ProfHeap.c,v 1.25 2001/08/14 13:40:09 sewardj Exp $
  *
  * (c) The GHC Team, 1998-2000
  *
@@ -15,6 +15,7 @@
 
 #if defined(PROFILING) || defined(DEBUG_HEAP_PROF)
 
+#include "PosixSource.h"
 #include "Rts.h"
 #include "RtsUtils.h"
 #include "RtsFlags.h"
@@ -308,7 +309,7 @@ fprint_data(FILE *fp)
     nat i;
     for (i = 0; i < SYMBOL_HASH_SIZE; i++) {
        if (symbol_hash[i].data > 0) {
-           fprintf(fp, "   %s %d\n", symbol_hash[i].name, symbol_hash[i].data);
+           fprintf(fp, "   %s %lu\n", symbol_hash[i].name, (unsigned long)symbol_hash[i].data);
        }
     }
 }
@@ -392,7 +393,7 @@ fprint_closure_types(FILE *fp)
 
   for (i = 0; i < N_CLOSURE_TYPES; i++) {
     if (closure_types[i]) {
-      fprintf(fp, "   %s %d\n", type_names[i], closure_types[i]);
+      fprintf(fp, "   %s %lu\n", type_names[i], (unsigned long)closure_types[i]);
     }
   }
 }
@@ -510,6 +511,8 @@ rtsBool satisfies_constraints ( StgClosure* p )
 #endif /* PROFILING */
 
 
+static double time_of_last_heapCensus = 0.0;
+
 void
 heapCensus(void)
 {
@@ -518,7 +521,10 @@ heapCensus(void)
   StgDouble time;
   nat size;
   StgPtr p;
-  
+#ifdef PROFILING
+  nat elapsed;
+#endif
+    
 #ifdef DEBUG_HEAP_PROF
   switch (RtsFlags.ProfFlags.doHeapProfile) {
   case HEAP_BY_INFOPTR:
@@ -536,6 +542,21 @@ heapCensus(void)
 #endif
 
 #ifdef PROFILING
+  /*
+   * We only continue iff we've waited long enough,
+   * otherwise, we just dont do the census.
+   */
+
+  time = mut_user_time_during_GC();  
+  elapsed = (time - time_of_last_heapCensus) * 1000;
+  if (elapsed < RtsFlags.ProfFlags.profileFrequency) {
+      return;
+    }
+  time_of_last_heapCensus = time;
+#endif
+
+
+#ifdef PROFILING
   switch (RtsFlags.ProfFlags.doHeapProfile) {
   case NO_HEAP_PROFILING:
       return;
@@ -555,9 +576,8 @@ heapCensus(void)
 
   /* Only do heap profiling in a two-space heap */
   ASSERT(RtsFlags.GcFlags.generations == 1);
-  bd = g0s0->to_space;
+  bd = g0s0->to_blocks;
 
-  time = mut_user_time_during_GC();
   fprintf(hp_file, "BEGIN_SAMPLE %0.2f\n", time);
   
   while (bd != NULL) {