@@ -1447,6 +1447,8 @@ add_stats(GCState *gcstate, int gen, struct gc_generation_stats *stats)
14471447
14481448 cur_stats -> objects_transitively_reachable += stats -> objects_transitively_reachable ;
14491449 cur_stats -> objects_not_transitively_reachable += stats -> objects_not_transitively_reachable ;
1450+
1451+ cur_stats -> duration += stats -> duration ;
14501452}
14511453
14521454static void
@@ -1929,13 +1931,12 @@ do_gc_callback(GCState *gcstate, const char *phase,
19291931 assert (PyList_CheckExact (gcstate -> callbacks ));
19301932 PyObject * info = NULL ;
19311933 if (PyList_GET_SIZE (gcstate -> callbacks ) != 0 ) {
1932- double duration = PyTime_AsSecondsDouble (stats -> ts_stop - stats -> ts_start );
19331934 info = Py_BuildValue ("{sisnsnsnsd}" ,
19341935 "generation" , generation ,
19351936 "collected" , stats -> collected ,
19361937 "uncollectable" , stats -> uncollectable ,
19371938 "candidates" , stats -> candidates ,
1938- "duration" , duration );
1939+ "duration" , stats -> duration );
19391940 if (info == NULL ) {
19401941 PyErr_FormatUnraisable ("Exception ignored while invoking gc callbacks" );
19411942 return ;
@@ -2191,6 +2192,7 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
21912192 Py_UNREACHABLE ();
21922193 }
21932194 (void )PyTime_PerfCounterRaw (& stats .ts_stop );
2195+ stats .duration = PyTime_AsSecondsDouble (stats .ts_stop - stats .ts_start );
21942196 add_stats (gcstate , generation , & stats );
21952197 if (PyDTrace_GC_DONE_ENABLED ()) {
21962198 PyDTrace_GC_DONE (stats .uncollectable + stats .collected );
@@ -2213,10 +2215,9 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
22132215 _Py_atomic_store_int (& gcstate -> collecting , 0 );
22142216
22152217 if (gcstate -> debug & _PyGC_DEBUG_STATS ) {
2216- double duration = PyTime_AsSecondsDouble (stats .ts_stop - stats .ts_start );
22172218 PySys_WriteStderr (
22182219 "gc: done, %zd unreachable, %zd uncollectable, %.4fs elapsed\n" ,
2219- stats .collected + stats .uncollectable , stats .uncollectable , duration
2220+ stats .collected + stats .uncollectable , stats .uncollectable , stats . duration
22202221 );
22212222 }
22222223
0 commit comments