Revert "rts: add Emacs 'Local Variables' to every .c file"
[ghc.git] / rts / ProfHeap.c
index 56c4451..9079c2b 100644 (file)
@@ -51,11 +51,11 @@ typedef struct _counter {
     union {
        nat resid;
        struct {
-           int prim;     // total size of 'inherently used' closures
-           int not_used; // total size of 'never used' closures
-           int used;     // total size of 'used at least once' closures
-           int void_total;  // current total size of 'destroyed without being used' closures
-           int drag_total;  // current total size of 'used at least once and waiting to die'
+           long prim;     // total size of 'inherently used' closures
+           long not_used; // total size of 'never used' closures
+           long used;     // total size of 'used at least once' closures
+           long void_total;  // current total size of 'destroyed without being used' closures
+           long drag_total;  // current total size of 'used at least once and waiting to die'
        } ldv;
     } c;
     struct _counter *next;
@@ -78,11 +78,11 @@ typedef struct {
     Arena     * arena;
 
     // for LDV profiling, when just displaying by LDV
-    int       prim;
-    int       not_used;
-    int       used;
-    int       void_total;
-    int       drag_total;
+    long       prim;
+    long       not_used;
+    long       used;
+    long       void_total;
+    long       drag_total;
 } Census;
 
 static Census *censuses = NULL;
@@ -97,7 +97,7 @@ static void dumpCensus( Census *census );
 static rtsBool closureSatisfiesConstraints( StgClosure* p );
 
 /* ----------------------------------------------------------------------------
- * Find the "closure identity", which is a unique pointer reresenting
+ * Find the "closure identity", which is a unique pointer representing
  * the band to which this closure's heap space is attributed in the
  * heap profile.
  * ------------------------------------------------------------------------- */
@@ -192,14 +192,14 @@ LDV_recordDead( StgClosure *c, nat size )
            t = (LDVW((c)) & LDV_CREATE_MASK) >> LDV_SHIFT;
            if (t < era) {
                if (RtsFlags.ProfFlags.bioSelector == NULL) {
-                   censuses[t].void_total   += (int)size;
-                   censuses[era].void_total -= (int)size;
+                    censuses[t].void_total   += (long)size;
+                    censuses[era].void_total -= (long)size;
                    ASSERT(censuses[t].void_total < censuses[t].not_used);
                } else {
                    id = closureIdentity(c);
                    ctr = lookupHashTable(censuses[t].hash, (StgWord)id);
                    ASSERT( ctr != NULL );
-                   ctr->c.ldv.void_total += (int)size;
+                    ctr->c.ldv.void_total += (long)size;
                    ctr = lookupHashTable(censuses[era].hash, (StgWord)id);
                    if (ctr == NULL) {
                        ctr = arenaAlloc(censuses[era].arena, sizeof(counter));
@@ -209,7 +209,7 @@ LDV_recordDead( StgClosure *c, nat size )
                        ctr->next = censuses[era].ctrs;
                        censuses[era].ctrs = ctr;
                    }
-                   ctr->c.ldv.void_total -= (int)size;
+                    ctr->c.ldv.void_total -= (long)size;
                }
            }
        } else {
@@ -223,7 +223,7 @@ LDV_recordDead( StgClosure *c, nat size )
                    id = closureIdentity(c);
                    ctr = lookupHashTable(censuses[t+1].hash, (StgWord)id);
                    ASSERT( ctr != NULL );
-                   ctr->c.ldv.drag_total += (int)size;
+                    ctr->c.ldv.drag_total += (long)size;
                    ctr = lookupHashTable(censuses[era].hash, (StgWord)id);
                    if (ctr == NULL) {
                        ctr = arenaAlloc(censuses[era].arena, sizeof(counter));
@@ -233,7 +233,7 @@ LDV_recordDead( StgClosure *c, nat size )
                        ctr->next = censuses[era].ctrs;
                        censuses[era].ctrs = ctr;
                    }
-                   ctr->c.ldv.drag_total -= (int)size;
+                    ctr->c.ldv.drag_total -= (long)size;
                }
            }
        }
@@ -262,12 +262,8 @@ initEra(Census *census)
 STATIC_INLINE void
 freeEra(Census *census)
 {
-    if (RtsFlags.ProfFlags.bioSelector != NULL)
-        // when bioSelector==NULL, these are freed in heapCensus()
-    {
-        arenaFree(census->arena);
-        freeHashTable(census->hash, NULL);
-    }
+    arenaFree(census->arena);
+    freeHashTable(census->hash, NULL);
 }
 
 /* --------------------------------------------------------------------------
@@ -335,16 +331,17 @@ void initProfiling2 (void)
     /* Initialise the log file name */
     hp_filename = stgMallocBytes(strlen(prog) + 6, "hpFileName");
     sprintf(hp_filename, "%s.hp", prog);
-    
+
     /* open the log file */
     if ((hp_file = fopen(hp_filename, "w")) == NULL) {
-      debugBelch("Can't open profiling report file %s\n", 
+      debugBelch("Can't open profiling report file %s\n",
              hp_filename);
       RtsFlags.ProfFlags.doHeapProfile = 0;
+      stgFree(prog);
       return;
     }
   }
-  
+
   stgFree(prog);
 
   initHeapProfiling();
@@ -364,6 +361,9 @@ printSample(rtsBool beginSample, StgDouble sampleValue)
     fprintf(hp_file, "%s %" FMT_Word64 ".%02" FMT_Word64 "\n",
             (beginSample ? "BEGIN_SAMPLE" : "END_SAMPLE"),
             (StgWord64)integralPart, (StgWord64)(fractionalPart * 100));
+    if (!beginSample) {
+        fflush(hp_file);
+    }
 }
 
 /* --------------------------------------------------------------------------
@@ -464,8 +464,12 @@ endHeapProfiling(void)
 #ifdef PROFILING
     if (doingLDVProfiling()) {
         nat t;
-        for (t = 1; t <= era; t++) {
-            freeEra( &censuses[t] );
+        if (RtsFlags.ProfFlags.bioSelector != NULL) {
+            for (t = 1; t <= era; t++) {
+                freeEra( &censuses[t] );
+            }
+        } else {
+            freeEra( &censuses[era] );
         }
     } else {
         freeEra( &censuses[0] );
@@ -632,7 +636,7 @@ aggregateCensusInfo( void )
 
     // Aggregate the LDV counters when displaying by biography.
     if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_LDV) {
-       int void_total, drag_total;
+        long void_total, drag_total;
 
        // Now we compute void_total and drag_total for each census
        // After the program has finished, the void_total field of
@@ -732,7 +736,7 @@ static void
 dumpCensus( Census *census )
 {
     counter *ctr;
-    int count;
+    long count;
 
     printSample(rtsTrue, census->time);
 
@@ -821,7 +825,7 @@ dumpCensus( Census *census )
        }
 #endif
 
-       fprintf(hp_file, "\t%lu\n", (unsigned long)count * sizeof(W_));
+       fprintf(hp_file, "\t%" FMT_SizeT "\n", (W_)count * sizeof(W_));
     }
 
     printSample(rtsFalse, census->time);
@@ -988,7 +992,8 @@ heapCensusChain( Census *census, bdescr *bd )
 
             case MVAR_CLEAN:
             case MVAR_DIRTY:
-           case WEAK:
+            case TVAR:
+            case WEAK:
            case PRIM:
            case MUT_PRIM:
            case MUT_VAR_CLEAN:
@@ -1021,6 +1026,14 @@ heapCensusChain( Census *census, bdescr *bd )
                prim = rtsTrue;
                size = mut_arr_ptrs_sizeW((StgMutArrPtrs *)p);
                break;
+
+           case SMALL_MUT_ARR_PTRS_CLEAN:
+           case SMALL_MUT_ARR_PTRS_DIRTY:
+           case SMALL_MUT_ARR_PTRS_FROZEN:
+           case SMALL_MUT_ARR_PTRS_FROZEN0:
+               prim = rtsTrue;
+               size = small_mut_arr_ptrs_sizeW((StgSmallMutArrPtrs *)p);
+               break;
                
            case TSO:
                prim = rtsTrue;
@@ -1070,8 +1083,7 @@ heapCensusChain( Census *census, bdescr *bd )
     }
 }
 
-void
-heapCensus( Ticks t )
+void heapCensus (Time t)
 {
   nat g, n;
   Census *census;
@@ -1122,8 +1134,7 @@ heapCensus( Ticks t )
 #ifdef PROFILING
   if (RtsFlags.ProfFlags.bioSelector == NULL)
   {
-      freeHashTable( census->hash, NULL/* don't free the elements */ );
-      arenaFree( census->arena );
+      freeEra(census);
       census->hash = NULL;
       census->arena = NULL;
   }