Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Restore elapsed time and unreachable object count in GC debug output. These
were inadvertently removed during a refactor of ``gc.c``. The debug log now
again reports elapsed collection time and the number of unreachable objects.
17 changes: 17 additions & 0 deletions Python/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "pycore_interpframe.h" // _PyFrame_GetLocalsArray()
#include "pycore_object_alloc.h" // _PyObject_MallocWithType()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_time.h" // _PyTime_MonotonicRaw()
#include "pycore_tuple.h" // _PyTuple_MaybeUntrack()
#include "pycore_weakref.h" // _PyWeakref_ClearRef()

Expand Down Expand Up @@ -2067,6 +2068,11 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
GCState *gcstate = &tstate->interp->gc;
assert(tstate->current_frame == NULL || tstate->current_frame->stackpointer != NULL);

PyTime_t now;
if (gcstate->debug & _PyGC_DEBUG_STATS) {
(void)PyTime_MonotonicRaw(&now);
}

int expected = 0;
if (!_Py_atomic_compare_exchange_int(&gcstate->collecting, &expected, 1)) {
// Don't start a garbage collection if one is already in progress.
Expand Down Expand Up @@ -2115,6 +2121,17 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
#endif
validate_spaces(gcstate);
_Py_atomic_store_int(&gcstate->collecting, 0);

if (gcstate->debug & _PyGC_DEBUG_STATS) {
PyTime_t endtime;
(void)PyTime_MonotonicRaw(&endtime);
double d = PyTime_AsSecondsDouble(endtime - now);
PySys_WriteStderr(
"gc: done, %zd unreachable, %zd uncollectable, %.4fs elapsed\n",
stats.collected + stats.collected, stats.uncollectable, d
);
}

return stats.uncollectable + stats.collected;
}

Expand Down
Loading