diff --git a/Include/internal/pycore_interp_structs.h b/Include/internal/pycore_interp_structs.h index 4448744f168..485e82b3312 100644 --- a/Include/internal/pycore_interp_structs.h +++ b/Include/internal/pycore_interp_structs.h @@ -181,6 +181,8 @@ struct gc_generation { struct gc_generation_stats { PyTime_t ts_start; PyTime_t ts_stop; + /* heap_size on the start of the collection */ + Py_ssize_t heap_size; /* total number of collections */ Py_ssize_t collections; /* total number of collected objects */ diff --git a/Python/gc.c b/Python/gc.c index f3ed20dda82..636a8f3859b 100644 --- a/Python/gc.c +++ b/Python/gc.c @@ -1405,7 +1405,7 @@ add_stats(GCState *gcstate, int gen, struct gc_generation_stats *stats) memcpy(cur_stats, prev_stats, sizeof(struct gc_generation_stats)); cur_stats->ts_start = stats->ts_start; - cur_stats->ts_stop = stats->ts_stop; + cur_stats->heap_size = stats->heap_size; cur_stats->collections += 1; cur_stats->collected += stats->collected; @@ -1413,6 +1413,7 @@ add_stats(GCState *gcstate, int gen, struct gc_generation_stats *stats) cur_stats->candidates += stats->candidates; cur_stats->duration += stats->duration; + cur_stats->ts_stop = stats->ts_stop; } /* This is the main function. Read this to understand how the @@ -1465,6 +1466,7 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason) invoke_gc_callback(tstate, "start", generation, &stats); } + stats.heap_size = gcstate->heap_size; // ignore error: don't interrupt the GC if reading the clock fails (void)PyTime_PerfCounterRaw(&stats.ts_start); if (gcstate->debug & _PyGC_DEBUG_STATS) {