@@ -1363,6 +1363,7 @@ gc_list_set_space(PyGC_Head *list, int space)
13631363static void
13641364add_stats (GCState * gcstate , int gen , struct gc_collection_stats * stats )
13651365{
1366+ gcstate -> generation_stats [gen ].duration += stats -> duration ;
13661367 gcstate -> generation_stats [gen ].collected += stats -> collected ;
13671368 gcstate -> generation_stats [gen ].uncollectable += stats -> uncollectable ;
13681369 gcstate -> generation_stats [gen ].collections += 1 ;
@@ -1383,6 +1384,7 @@ gc_collect_young(PyThreadState *tstate,
13831384 gc_list_init (& survivors );
13841385 gc_list_set_space (young , gcstate -> visited_space );
13851386 gc_collect_region (tstate , young , & survivors , stats );
1387+ stats -> visited += gcstate -> young .count ;
13861388 gc_list_merge (& survivors , visited );
13871389 validate_spaces (gcstate );
13881390 gcstate -> young .count = 0 ;
@@ -1697,6 +1699,7 @@ gc_collect_increment(PyThreadState *tstate, struct gc_collection_stats *stats)
16971699 PyGC_Head survivors ;
16981700 gc_list_init (& survivors );
16991701 gc_collect_region (tstate , & increment , & survivors , stats );
1702+ stats -> visited += increment_size ;
17001703 gc_list_merge (& survivors , visited );
17011704 assert (gc_list_is_empty (& increment ));
17021705 gcstate -> work_to_do -= increment_size ;
@@ -1729,6 +1732,7 @@ gc_collect_full(PyThreadState *tstate,
17291732
17301733 gc_collect_region (tstate , visited , visited ,
17311734 stats );
1735+ stats -> visited += gcstate -> young .count + gcstate -> old [0 ].count + gcstate -> old [1 ].count ;
17321736 validate_spaces (gcstate );
17331737 gcstate -> young .count = 0 ;
17341738 gcstate -> old [0 ].count = 0 ;
@@ -1846,10 +1850,11 @@ do_gc_callback(GCState *gcstate, const char *phase,
18461850 assert (PyList_CheckExact (gcstate -> callbacks ));
18471851 PyObject * info = NULL ;
18481852 if (PyList_GET_SIZE (gcstate -> callbacks ) != 0 ) {
1849- info = Py_BuildValue ("{sisnsn }" ,
1853+ info = Py_BuildValue ("{sisnsnsd }" ,
18501854 "generation" , generation ,
18511855 "collected" , stats -> collected ,
1852- "uncollectable" , stats -> uncollectable );
1856+ "uncollectable" , stats -> uncollectable ,
1857+ "duration" , stats -> duration );
18531858 if (info == NULL ) {
18541859 PyErr_FormatUnraisable ("Exception ignored while invoking gc callbacks" );
18551860 return ;
@@ -2080,15 +2085,15 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
20802085 if (reason != _Py_GC_REASON_SHUTDOWN ) {
20812086 invoke_gc_callback (gcstate , "start" , generation , & stats );
20822087 }
2083- PyTime_t t1 ;
20842088 if (gcstate -> debug & _PyGC_DEBUG_STATS ) {
20852089 PySys_WriteStderr ("gc: collecting generation %d...\n" , generation );
2086- (void )PyTime_PerfCounterRaw (& t1 );
20872090 show_stats_each_generations (gcstate );
20882091 }
20892092 if (PyDTrace_GC_START_ENABLED ()) {
20902093 PyDTrace_GC_START (generation );
20912094 }
2095+ PyTime_t start , stop ;
2096+ (void )PyTime_PerfCounterRaw (& start );
20922097 PyObject * exc = _PyErr_GetRaisedException (tstate );
20932098 switch (generation ) {
20942099 case 0 :
@@ -2103,6 +2108,8 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
21032108 default :
21042109 Py_UNREACHABLE ();
21052110 }
2111+ (void )PyTime_PerfCounterRaw (& stop );
2112+ stats .duration = PyTime_AsSecondsDouble (stop - start );
21062113 if (PyDTrace_GC_DONE_ENABLED ()) {
21072114 PyDTrace_GC_DONE (stats .uncollectable + stats .collected );
21082115 }
@@ -2124,12 +2131,9 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
21242131 _Py_atomic_store_int (& gcstate -> collecting , 0 );
21252132
21262133 if (gcstate -> debug & _PyGC_DEBUG_STATS ) {
2127- PyTime_t t2 ;
2128- (void )PyTime_PerfCounterRaw (& t2 );
2129- double d = PyTime_AsSecondsDouble (t2 - t1 );
21302134 PySys_WriteStderr (
21312135 "gc: done, %zd unreachable, %zd uncollectable, %.4fs elapsed\n" ,
2132- stats .collected + stats .uncollectable , stats .uncollectable , d
2136+ stats .collected + stats .uncollectable , stats .uncollectable , stats . duration
21332137 );
21342138 }
21352139
0 commit comments