|
10 | 10 | #include "pycore_interpframe.h" // _PyFrame_GetLocalsArray() |
11 | 11 | #include "pycore_object_alloc.h" // _PyObject_MallocWithType() |
12 | 12 | #include "pycore_pystate.h" // _PyThreadState_GET() |
| 13 | +#include "pycore_time.h" // _PyTime_MonotonicRaw() |
13 | 14 | #include "pycore_tuple.h" // _PyTuple_MaybeUntrack() |
14 | 15 | #include "pycore_weakref.h" // _PyWeakref_ClearRef() |
15 | 16 |
|
@@ -1816,6 +1817,7 @@ gc_collect_region(PyThreadState *tstate, |
1816 | 1817 | /* Collect statistics on uncollectable objects found and print |
1817 | 1818 | * debugging information. */ |
1818 | 1819 | Py_ssize_t n = 0; |
| 1820 | + |
1819 | 1821 | for (gc = GC_NEXT(&finalizers); gc != &finalizers; gc = GC_NEXT(gc)) { |
1820 | 1822 | n++; |
1821 | 1823 | if (gcstate->debug & _PyGC_DEBUG_UNCOLLECTABLE) |
@@ -2066,6 +2068,8 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason) |
2066 | 2068 | { |
2067 | 2069 | GCState *gcstate = &tstate->interp->gc; |
2068 | 2070 | assert(tstate->current_frame == NULL || tstate->current_frame->stackpointer != NULL); |
| 2071 | + PyTime_t now; |
| 2072 | + (void)PyTime_MonotonicRaw(&now); |
2069 | 2073 |
|
2070 | 2074 | int expected = 0; |
2071 | 2075 | if (!_Py_atomic_compare_exchange_int(&gcstate->collecting, &expected, 1)) { |
@@ -2115,6 +2119,17 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason) |
2115 | 2119 | #endif |
2116 | 2120 | validate_spaces(gcstate); |
2117 | 2121 | _Py_atomic_store_int(&gcstate->collecting, 0); |
| 2122 | + |
| 2123 | + if (gcstate->debug & _PyGC_DEBUG_STATS) { |
| 2124 | + PyTime_t endtime; |
| 2125 | + (void)PyTime_MonotonicRaw(&endtime); |
| 2126 | + double d = PyTime_AsSecondsDouble(endtime - now); |
| 2127 | + PySys_WriteStderr( |
| 2128 | + "gc: done, %zd unreachable, %zd uncollectable, %.4fs elapsed\n", |
| 2129 | + stats.collected, stats.uncollectable, d |
| 2130 | + ); |
| 2131 | + } |
| 2132 | + |
2118 | 2133 | return stats.uncollectable + stats.collected; |
2119 | 2134 | } |
2120 | 2135 |
|
|
0 commit comments