@@ -2068,10 +2068,7 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
20682068 GCState * gcstate = & tstate -> interp -> gc ;
20692069 assert (tstate -> current_frame == NULL || tstate -> current_frame -> stackpointer != NULL );
20702070
2071- PyTime_t now ;
2072- if (gcstate -> debug & _PyGC_DEBUG_STATS ) {
2073- (void )PyTime_MonotonicRaw (& now );
2074- }
2071+ PyTime_t t1 ;
20752072
20762073 int expected = 0 ;
20772074 if (!_Py_atomic_compare_exchange_int (& gcstate -> collecting , & expected , 1 )) {
@@ -2084,6 +2081,7 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
20842081 invoke_gc_callback (gcstate , "start" , generation , & stats );
20852082 }
20862083 if (gcstate -> debug & _PyGC_DEBUG_STATS ) {
2084+ (void )PyTime_MonotonicRaw (& t1 );
20872085 PySys_WriteStderr ("gc: collecting generation %d...\n" , generation );
20882086 show_stats_each_generations (gcstate );
20892087 }
@@ -2123,9 +2121,9 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
21232121 _Py_atomic_store_int (& gcstate -> collecting , 0 );
21242122
21252123 if (gcstate -> debug & _PyGC_DEBUG_STATS ) {
2126- PyTime_t endtime ;
2127- (void )PyTime_MonotonicRaw (& endtime );
2128- double d = PyTime_AsSecondsDouble (endtime - now );
2124+ PyTime_t t2 ;
2125+ (void )PyTime_MonotonicRaw (& t2 );
2126+ double d = PyTime_AsSecondsDouble (t2 - t1 );
21292127 PySys_WriteStderr (
21302128 "gc: done, %zd unreachable, %zd uncollectable, %.4fs elapsed\n" ,
21312129 stats .collected + stats .collected , stats .uncollectable , d
0 commit comments