Add heap_size to stats

This commit is contained in:
Sergey Miryanov 2026-05-01 00:28:05 +05:00
parent b6ec9924fb
commit 2281499513
2 changed files with 5 additions and 1 deletions

View file

@ -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 */

View file

@ -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) {