@@ -177,31 +177,54 @@ struct gc_generation {
177177 generations */
178178};
179179
180- struct gc_collection_stats {
181- /* number of collected objects */
182- Py_ssize_t collected ;
183- /* total number of uncollectable objects (put into gc.garbage) */
184- Py_ssize_t uncollectable ;
185- // Total number of objects considered for collection and traversed:
186- Py_ssize_t candidates ;
187- // Duration of the collection in seconds:
188- double duration ;
189- };
190-
191180/* Running stats per generation */
192181struct gc_generation_stats {
182+ PyTime_t ts_start ;
183+ PyTime_t ts_stop ;
184+
185+ /* heap_size on the start of the collection */
186+ Py_ssize_t heap_size ;
187+
188+ /* work_to_do on the start of the collection */
189+ Py_ssize_t work_to_do ;
190+
193191 /* total number of collections */
194192 Py_ssize_t collections ;
193+
194+ /* total number of visited objects */
195+ Py_ssize_t object_visits ;
196+
195197 /* total number of collected objects */
196198 Py_ssize_t collected ;
197199 /* total number of uncollectable objects (put into gc.garbage) */
198200 Py_ssize_t uncollectable ;
199201 // Total number of objects considered for collection and traversed:
200202 Py_ssize_t candidates ;
201- // Duration of the collection in seconds:
203+
204+ Py_ssize_t objects_transitively_reachable ;
205+ Py_ssize_t objects_not_transitively_reachable ;
206+
207+ // Total duration of the collection in seconds:
202208 double duration ;
203209};
204210
211+ #ifdef Py_GIL_DISABLED
212+ #define GC_YOUNG_STATS_SIZE 1
213+ #define GC_OLD_STATS_SIZE 1
214+ #else
215+ #define GC_YOUNG_STATS_SIZE 11
216+ #define GC_OLD_STATS_SIZE 3
217+ #endif
218+ struct gc_young_stats_buffer {
219+ struct gc_generation_stats items [GC_YOUNG_STATS_SIZE ];
220+ int8_t index ;
221+ };
222+
223+ struct gc_old_stats_buffer {
224+ struct gc_generation_stats items [GC_OLD_STATS_SIZE ];
225+ int8_t index ;
226+ };
227+
205228enum _GCPhase {
206229 GC_PHASE_MARK = 0 ,
207230 GC_PHASE_COLLECT = 1
@@ -211,6 +234,11 @@ enum _GCPhase {
211234 signature of gc.collect and change the size of PyStats.gc_stats */
212235#define NUM_GENERATIONS 3
213236
237+ struct gc_stats {
238+ struct gc_young_stats_buffer young ;
239+ struct gc_old_stats_buffer old [2 ];
240+ };
241+
214242struct _gc_runtime_state {
215243 /* Is automatic collection enabled? */
216244 int enabled ;
@@ -220,7 +248,7 @@ struct _gc_runtime_state {
220248 struct gc_generation old [2 ];
221249 /* a permanent generation which won't be collected */
222250 struct gc_generation permanent_generation ;
223- struct gc_generation_stats generation_stats [ NUM_GENERATIONS ] ;
251+ struct gc_stats generation_stats ;
224252 /* true if we are currently running the collector */
225253 int collecting ;
226254 // The frame that started the current collection. It might be NULL even when
0 commit comments