From 13761bd8269f2230742d6befddf3a3154b1ee610 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Wed, 28 Jul 2010 00:12:10 -0300 Subject: [PATCH] stats: Log the pointer to the allocated memory --- rt/gc/cdgc/gc.d | 2 +- rt/gc/cdgc/stats.d | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/rt/gc/cdgc/gc.d b/rt/gc/cdgc/gc.d index b5635f9..f5e088c 100644 --- a/rt/gc/cdgc/gc.d +++ b/rt/gc/cdgc/gc.d @@ -334,7 +334,7 @@ class GC stats.malloc_started(size, attrs, pm_bitmask); scope (exit) - stats.malloc_finished(); + stats.malloc_finished(p); void *p = null; Bins bin; diff --git a/rt/gc/cdgc/stats.d b/rt/gc/cdgc/stats.d index 314b509..aefce42 100644 --- a/rt/gc/cdgc/stats.d +++ b/rt/gc/cdgc/stats.d @@ -123,6 +123,8 @@ struct MallocInfo 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. @@ -236,16 +238,17 @@ private: if (this.mallocs_file is null) return; cstdio.fprintf(this.mallocs_file, - "%f,%f,%zu,%zu,%zu,%zu,%zu,%p\n", - //0 1 2 3 4 5 6 7 + "%f,%f,%p,%zu,%zu,%zu,%zu,%zu,%p\n", + //0 1 2 3 4 5 6 7 8 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.ptrmap); // 7 + 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 + this.malloc_info.ptrmap); // 8 // TODO: make it an option cstdio.fflush(this.mallocs_file); } @@ -291,7 +294,7 @@ public: this_.active = true; this_.mallocs_file = this_.start_file( options.malloc_stats_file.ptr, - "Timestamp,Time,Size,Collection triggered," + "Timestamp,Time,Pointer,Size,Collection triggered," "Finalize,No scan,No move,Pointer map\n"); } // collection @@ -338,7 +341,7 @@ public: } /// Inform the end of an allocation. - void malloc_finished() + void malloc_finished(void* ptr) { if (!this.active) return; @@ -348,6 +351,7 @@ public: 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; -- 2.43.0