Eliminate atomic_inc_by and instead medofiy atomic_inc.
[ghc.git] / rts / ProfHeap.c
index 9d95b4c..f094038 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;
                }
            }
        }
@@ -364,6 +364,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);
+    }
 }
 
 /* --------------------------------------------------------------------------
@@ -632,7 +635,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 +735,7 @@ static void
 dumpCensus( Census *census )
 {
     counter *ctr;
-    int count;
+    long count;
 
     printSample(rtsTrue, census->time);
 
@@ -821,7 +824,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);
@@ -919,12 +922,12 @@ heapCensusChain( Census *census, bdescr *bd )
     for (; bd != NULL; bd = bd->link) {
 
         // HACK: pretend a pinned block is just one big ARR_WORDS
-        // owned by CCS_SYSTEM.  These blocks can be full of holes due
+        // owned by CCS_PINNED.  These blocks can be full of holes due
         // to alignment constraints so we can't traverse the memory
         // and do a proper census.
         if (bd->flags & BF_PINNED) {
             StgClosure arr;
-            SET_HDR(&arr, &stg_ARR_WORDS_info, CCS_SYSTEM);
+            SET_HDR(&arr, &stg_ARR_WORDS_info, CCS_PINNED);
             heapProfObject(census, &arr, bd->blocks * BLOCK_SIZE_W, rtsTrue);
             continue;
         }
@@ -988,7 +991,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:
@@ -1070,8 +1074,7 @@ heapCensusChain( Census *census, bdescr *bd )
     }
 }
 
-void
-heapCensus( Ticks t )
+void heapCensus (Time t)
 {
   nat g, n;
   Census *census;