@@ -1289,6 +1289,7 @@ gc_collect_young(PyThreadState *tstate,
1289
1289
GCState * gcstate = & tstate -> interp -> gc ;
1290
1290
PyGC_Head * young = & gcstate -> young .head ;
1291
1291
PyGC_Head * visited = & gcstate -> old [gcstate -> visited_space ].head ;
1292
+ GC_STAT_ADD (0 , collections , 1 );
1292
1293
#ifdef Py_STATS
1293
1294
{
1294
1295
Py_ssize_t count = 0 ;
@@ -1417,6 +1418,7 @@ completed_cycle(GCState *gcstate)
1417
1418
static void
1418
1419
gc_collect_increment (PyThreadState * tstate , struct gc_collection_stats * stats )
1419
1420
{
1421
+ GC_STAT_ADD (1 , collections , 1 );
1420
1422
GCState * gcstate = & tstate -> interp -> gc ;
1421
1423
PyGC_Head * not_visited = & gcstate -> old [gcstate -> visited_space ^1 ].head ;
1422
1424
PyGC_Head * visited = & gcstate -> old [gcstate -> visited_space ].head ;
@@ -1462,6 +1464,7 @@ static void
1462
1464
gc_collect_full (PyThreadState * tstate ,
1463
1465
struct gc_collection_stats * stats )
1464
1466
{
1467
+ GC_STAT_ADD (2 , collections , 1 );
1465
1468
GCState * gcstate = & tstate -> interp -> gc ;
1466
1469
validate_old (gcstate );
1467
1470
PyGC_Head * young = & gcstate -> young .head ;
@@ -1784,6 +1787,24 @@ PyGC_IsEnabled(void)
1784
1787
return gcstate -> enabled ;
1785
1788
}
1786
1789
1790
+ // Show stats for objects in each generations
1791
+ static void
1792
+ show_stats_each_generations (GCState * gcstate )
1793
+ {
1794
+ char buf [100 ];
1795
+ size_t pos = 0 ;
1796
+
1797
+ for (int i = 0 ; i < NUM_GENERATIONS && pos < sizeof (buf ); i ++ ) {
1798
+ pos += PyOS_snprintf (buf + pos , sizeof (buf )- pos ,
1799
+ " %zd" ,
1800
+ gc_list_size (GEN_HEAD (gcstate , i )));
1801
+ }
1802
+ PySys_FormatStderr (
1803
+ "gc: objects in each generation:%s\n"
1804
+ "gc: objects in permanent generation: %zd\n" ,
1805
+ buf , gc_list_size (& gcstate -> permanent_generation .head ));
1806
+ }
1807
+
1787
1808
Py_ssize_t
1788
1809
_PyGC_Collect (PyThreadState * tstate , int generation , _PyGC_Reason reason )
1789
1810
{
@@ -1799,6 +1820,10 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
1799
1820
if (reason != _Py_GC_REASON_SHUTDOWN ) {
1800
1821
invoke_gc_callback (gcstate , "start" , generation , & stats );
1801
1822
}
1823
+ if (gcstate -> debug & _PyGC_DEBUG_STATS ) {
1824
+ PySys_WriteStderr ("gc: collecting generation %d...\n" , generation );
1825
+ show_stats_each_generations (gcstate );
1826
+ }
1802
1827
if (PyDTrace_GC_START_ENABLED ()) {
1803
1828
PyDTrace_GC_START (generation );
1804
1829
}
0 commit comments