mirror of
https://github.com/python/cpython.git
synced 2025-11-24 12:20:42 +00:00
[3.14] gh-140358: Bring back elapsed time and unreachable count to gc debug output (GH-140359) (#140405)
Some checks are pending
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Check if the ABI has changed (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Android (aarch64) (push) Blocked by required conditions
Tests / Android (x86_64) (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Sanitizers (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
Some checks are pending
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Check if the ABI has changed (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Android (aarch64) (push) Blocked by required conditions
Tests / Android (x86_64) (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Sanitizers (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
Co-authored-by: Pål Grønås Drange <paal.drange+pgdr@gmail.com>
This commit is contained in:
parent
ce1deb947e
commit
c1bfd4cb9c
3 changed files with 43 additions and 0 deletions
|
|
@ -776,6 +776,32 @@ class GCTests(unittest.TestCase):
|
||||||
rc, out, err = assert_python_ok('-c', code)
|
rc, out, err = assert_python_ok('-c', code)
|
||||||
self.assertEqual(out.strip(), b'__del__ called')
|
self.assertEqual(out.strip(), b'__del__ called')
|
||||||
|
|
||||||
|
@unittest.skipIf(Py_GIL_DISABLED, "requires GC generations or increments")
|
||||||
|
def test_gc_debug_stats(self):
|
||||||
|
# Checks that debug information is printed to stderr
|
||||||
|
# when DEBUG_STATS is set.
|
||||||
|
code = """if 1:
|
||||||
|
import gc
|
||||||
|
gc.set_debug(%s)
|
||||||
|
gc.collect()
|
||||||
|
"""
|
||||||
|
_, _, err = assert_python_ok("-c", code % "gc.DEBUG_STATS")
|
||||||
|
self.assertRegex(err, b"gc: collecting generation [0-9]+")
|
||||||
|
self.assertRegex(
|
||||||
|
err,
|
||||||
|
b"gc: objects in each generation: [0-9]+ [0-9]+ [0-9]+",
|
||||||
|
)
|
||||||
|
self.assertRegex(
|
||||||
|
err, b"gc: objects in permanent generation: [0-9]+"
|
||||||
|
)
|
||||||
|
self.assertRegex(
|
||||||
|
err,
|
||||||
|
b"gc: done, .* unreachable, .* uncollectable, .* elapsed",
|
||||||
|
)
|
||||||
|
|
||||||
|
_, _, err = assert_python_ok("-c", code % "0")
|
||||||
|
self.assertNotIn(b"elapsed", err)
|
||||||
|
|
||||||
def test_global_del_SystemExit(self):
|
def test_global_del_SystemExit(self):
|
||||||
code = """if 1:
|
code = """if 1:
|
||||||
class ClassWithDel:
|
class ClassWithDel:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
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.
|
||||||
|
Contributed by Pål Grønås Drange.
|
||||||
13
Python/gc.c
13
Python/gc.c
|
|
@ -2024,8 +2024,10 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
|
||||||
if (reason != _Py_GC_REASON_SHUTDOWN) {
|
if (reason != _Py_GC_REASON_SHUTDOWN) {
|
||||||
invoke_gc_callback(gcstate, "start", generation, &stats);
|
invoke_gc_callback(gcstate, "start", generation, &stats);
|
||||||
}
|
}
|
||||||
|
PyTime_t t1;
|
||||||
if (gcstate->debug & _PyGC_DEBUG_STATS) {
|
if (gcstate->debug & _PyGC_DEBUG_STATS) {
|
||||||
PySys_WriteStderr("gc: collecting generation %d...\n", generation);
|
PySys_WriteStderr("gc: collecting generation %d...\n", generation);
|
||||||
|
(void)PyTime_PerfCounterRaw(&t1);
|
||||||
show_stats_each_generations(gcstate);
|
show_stats_each_generations(gcstate);
|
||||||
}
|
}
|
||||||
if (PyDTrace_GC_START_ENABLED()) {
|
if (PyDTrace_GC_START_ENABLED()) {
|
||||||
|
|
@ -2062,6 +2064,17 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
|
||||||
#endif
|
#endif
|
||||||
validate_spaces(gcstate);
|
validate_spaces(gcstate);
|
||||||
_Py_atomic_store_int(&gcstate->collecting, 0);
|
_Py_atomic_store_int(&gcstate->collecting, 0);
|
||||||
|
|
||||||
|
if (gcstate->debug & _PyGC_DEBUG_STATS) {
|
||||||
|
PyTime_t t2;
|
||||||
|
(void)PyTime_PerfCounterRaw(&t2);
|
||||||
|
double d = PyTime_AsSecondsDouble(t2 - t1);
|
||||||
|
PySys_WriteStderr(
|
||||||
|
"gc: done, %zd unreachable, %zd uncollectable, %.4fs elapsed\n",
|
||||||
|
stats.collected + stats.uncollectable, stats.uncollectable, d
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return stats.uncollectable + stats.collected;
|
return stats.uncollectable + stats.collected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue