]> git.llucax.com Git - software/dgc/cdgc.git/blobdiff - rt/gc/cdgc/stats.d
Unify GC class and Gcx struct
[software/dgc/cdgc.git] / rt / gc / cdgc / stats.d
index 073a594d13b6bcef941063d4f3b4d662a3ccd3bf..1a2e8ef18fd2e43db5c4ff938cc1d45c7618f78a 100644 (file)
@@ -123,12 +123,16 @@ struct MallocInfo
     double timestamp = -1.0;
     /// Time spent in the malloc() call (in seconds).
     double time = -1.0;
     double timestamp = -1.0;
     /// Time spent in the malloc() call (in seconds).
     double time = -1.0;
+    /// Address of the pointer returned by malloc.
+    void* ptr = null;
     /// Memory requested by the malloc() call (in bytes).
     size_t size = 0;
     /// Memory attributes as BlkAttr flags.
     uint attr = 0;
     /// True if this malloc() triggered a collection.
     bool collected = false;
     /// Memory requested by the malloc() call (in bytes).
     size_t size = 0;
     /// Memory attributes as BlkAttr flags.
     uint attr = 0;
     /// True if this malloc() triggered a collection.
     bool collected = false;
+    /// Address of the pointer map bitmask.
+    size_t* ptrmap = null;
 }
 
 
 }
 
 
@@ -153,7 +157,7 @@ struct Stats
 private:
 
     /// The GC instance we are collecting stats from.
 private:
 
     /// The GC instance we are collecting stats from.
-    .gc.GC gc = null;
+    .gc.GC* gc = null;
 
     /// True if statistics should be collected.
     bool active = false;
 
     /// True if statistics should be collected.
     bool active = false;
@@ -184,13 +188,13 @@ private:
     /// Fill a MemoryInfo struct with the current state of the GC heap.
     void fill_memory_info(MemoryInfo* mem_info)
     {
     /// Fill a MemoryInfo struct with the current state of the GC heap.
     void fill_memory_info(MemoryInfo* mem_info)
     {
-        mem_info.overhead += .gc.GC.classinfo.init.length + .gc.Gcx.sizeof
-                + .gc.pools.size_of + .gc.roots.size_of + .gc.ranges.size_of;
+        mem_info.overhead += .gc.GC.sizeof + gc.pools.elements_sizeof +
+                gc.roots.elements_sizeof + gc.ranges.elements_sizeof;
 
         // pools
 
         // pools
-        for (size_t i = 0; i < .gc.pools.length; i++)
+        for (size_t i = 0; i < gc.pools.length; i++)
         {
         {
-            auto pool = .gc.pools[i];
+            auto pool = gc.pools[i];
             mem_info.overhead += pool.npages * ubyte.sizeof;
             // the 5 bitmaps (mark, scan, free, final, noscan)
             mem_info.overhead += 5 * (GCBits.sizeof
             mem_info.overhead += pool.npages * ubyte.sizeof;
             // the 5 bitmaps (mark, scan, free, final, noscan)
             mem_info.overhead += 5 * (GCBits.sizeof
@@ -233,16 +237,27 @@ private:
     {
         if (this.mallocs_file is null)
             return;
     {
         if (this.mallocs_file is null)
             return;
+        auto ptrmap = this.malloc_info.ptrmap;
+        auto ptrmask_offset = (ptrmap[0] - 1) / (size_t.sizeof * 8) + 1;
         cstdio.fprintf(this.mallocs_file,
         cstdio.fprintf(this.mallocs_file,
-                "%f,%f,%zu,%zu,%zu,%zu,%zu\n",
-                //0  1   2   3   4   5   6
+                "%f,%f,%p,%zu,%zu,%zu,%zu,%zu,%p,%zu,%0*zX,%0*zX\n",
+                //0  1   2   3   4   5   6  7  8   9    10    11
                 this.malloc_info.timestamp,                   // 0
                 this.malloc_info.time,                        // 1
                 this.malloc_info.timestamp,                   // 0
                 this.malloc_info.time,                        // 1
-                this.malloc_info.size,                        // 2
-                this.malloc_info.collected ? 1u : 0u,         // 3
-                this.malloc_info.attr & .gc.BlkAttr.FINALIZE, // 4
-                this.malloc_info.attr & .gc.BlkAttr.NO_SCAN,  // 5
-                this.malloc_info.attr & .gc.BlkAttr.NO_MOVE); // 6
+                this.malloc_info.ptr,                         // 2
+                this.malloc_info.size,                        // 3
+                this.malloc_info.collected ? 1u : 0u,         // 4
+                this.malloc_info.attr & .gc.BlkAttr.FINALIZE, // 5
+                this.malloc_info.attr & .gc.BlkAttr.NO_SCAN,  // 6
+                this.malloc_info.attr & .gc.BlkAttr.NO_MOVE,  // 7
+                ptrmap,                                       // 8
+                ptrmap[0] * size_t.sizeof,                    // 9
+                size_t.sizeof,                                // fill length
+                ptrmap[1],                                    // 10
+                size_t.sizeof,                                // fill length
+                ptrmap[1 + ptrmask_offset]);                  // 11
+        // TODO: make it an option
+        cstdio.fflush(this.mallocs_file);
     }
 
     void print_collection()
     }
 
     void print_collection()
@@ -264,6 +279,8 @@ private:
                 this.collection_info.after.free,          // 9
                 this.collection_info.after.wasted,        // 10
                 this.collection_info.after.overhead);     // 11
                 this.collection_info.after.free,          // 9
                 this.collection_info.after.wasted,        // 10
                 this.collection_info.after.overhead);     // 11
+        // TODO: make it an option
+        cstdio.fflush(this.collections_file);
     }
 
 
     }
 
 
@@ -276,7 +293,7 @@ public:
      * the program start time (in seconds since the epoch) needs to be taken to
      * properly add timestamps to allocations and collections.
      */
      * the program start time (in seconds since the epoch) needs to be taken to
      * properly add timestamps to allocations and collections.
      */
-    static Stats opCall(.gc.GC gc)
+    static Stats opCall(.gc.GC* gc)
     {
         Stats this_;
         this_.gc = gc;
     {
         Stats this_;
         this_.gc = gc;
@@ -284,8 +301,10 @@ public:
             this_.active = true;
             this_.mallocs_file = this_.start_file(
                     options.malloc_stats_file.ptr,
             this_.active = true;
             this_.mallocs_file = this_.start_file(
                     options.malloc_stats_file.ptr,
-                    "Timestamp,Time,Size,Collection triggered,"
-                    "Finalize,No scan,No move\n");
+                    "Timestamp,Time,Pointer,Size,Collection triggered,"
+                    "Finalize,No scan,No move,Pointer map,Type size,"
+                    "Pointer map scan bitmask (first word, hexa),"
+                    "Pointer map pointer bitmask (first word, hexa)\n");
         }
         // collection
         if (options.collect_stats_file[0] != '\0') {
         }
         // collection
         if (options.collect_stats_file[0] != '\0') {
@@ -309,7 +328,8 @@ public:
     }
 
     /// Inform the start of an allocation.
     }
 
     /// Inform the start of an allocation.
-    void malloc_started(size_t size, uint attr)
+    // TODO: store/use type information
+    void malloc_started(size_t size, uint attr, size_t* ptrmap_bitmask)
     {
         if (!this.active)
             return;
     {
         if (!this.active)
             return;
@@ -321,6 +341,7 @@ public:
         this.malloc_info.time = now;
         this.malloc_info.size = size;
         this.malloc_info.attr = attr;
         this.malloc_info.time = now;
         this.malloc_info.size = size;
         this.malloc_info.attr = attr;
+        this.malloc_info.ptrmap = ptrmap_bitmask;
         // this.malloc_info.collected is filled in malloc_finished()
         // collection
         this.collection_info = this.collection_info.init;
         // this.malloc_info.collected is filled in malloc_finished()
         // collection
         this.collection_info = this.collection_info.init;
@@ -329,7 +350,7 @@ public:
     }
 
     /// Inform the end of an allocation.
     }
 
     /// Inform the end of an allocation.
-    void malloc_finished()
+    void malloc_finished(void* ptr)
     {
         if (!this.active)
             return;
     {
         if (!this.active)
             return;
@@ -339,6 +360,7 @@ public:
         this.malloc_info.time = now - this.malloc_info.time;
         if (collected)
             this.malloc_info.collected = true;
         this.malloc_info.time = now - this.malloc_info.time;
         if (collected)
             this.malloc_info.collected = true;
+        this.malloc_info.ptr = ptr;
         this.print_malloc();
         if (!collected)
             return;
         this.print_malloc();
         if (!collected)
             return;