diff options
author | Mark Shannon <mark@hotpy.org> | 2023-08-04 09:34:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-04 09:34:23 (GMT) |
commit | 2ba7c7f7b151ff56cf12bf3cab286981bb646c90 (patch) | |
tree | e89d562e9043fb9703a9b822de58a9bd4bedb1ac /Modules/gcmodule.c | |
parent | fa45958450aa3489607daf9855ca0474a2a20878 (diff) | |
download | cpython-2ba7c7f7b151ff56cf12bf3cab286981bb646c90.zip cpython-2ba7c7f7b151ff56cf12bf3cab286981bb646c90.tar.gz cpython-2ba7c7f7b151ff56cf12bf3cab286981bb646c90.tar.bz2 |
Add some GC stats to Py_STATS (GH-107581)
Diffstat (limited to 'Modules/gcmodule.c')
-rw-r--r-- | Modules/gcmodule.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index 246c0a9..35a3509 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -460,6 +460,7 @@ update_refs(PyGC_Head *containers) static int visit_decref(PyObject *op, void *parent) { + OBJECT_STAT_INC(object_visits); _PyObject_ASSERT(_PyObject_CAST(parent), !_PyObject_IsFreed(op)); if (_PyObject_IS_GC(op)) { @@ -498,6 +499,7 @@ subtract_refs(PyGC_Head *containers) static int visit_reachable(PyObject *op, PyGC_Head *reachable) { + OBJECT_STAT_INC(object_visits); if (!_PyObject_IS_GC(op)) { return 0; } @@ -725,6 +727,7 @@ clear_unreachable_mask(PyGC_Head *unreachable) static int visit_move(PyObject *op, PyGC_Head *tolist) { + OBJECT_STAT_INC(object_visits); if (_PyObject_IS_GC(op)) { PyGC_Head *gc = AS_GC(op); if (gc_is_collecting(gc)) { @@ -1195,6 +1198,12 @@ gc_collect_main(PyThreadState *tstate, int generation, Py_ssize_t *n_collected, Py_ssize_t *n_uncollectable, int nofail) { + GC_STAT_ADD(generation, collections, 1); +#ifdef Py_STATS + if (_py_stats) { + _py_stats->object_stats.object_visits = 0; + } +#endif int i; Py_ssize_t m = 0; /* # objects collected */ Py_ssize_t n = 0; /* # unreachable objects that couldn't be collected */ @@ -1351,6 +1360,15 @@ gc_collect_main(PyThreadState *tstate, int generation, stats->collected += m; stats->uncollectable += n; + GC_STAT_ADD(generation, objects_collected, m); +#ifdef Py_STATS + if (_py_stats) { + GC_STAT_ADD(generation, object_visits, + _py_stats->object_stats.object_visits); + _py_stats->object_stats.object_visits = 0; + } +#endif + if (PyDTrace_GC_DONE_ENABLED()) { PyDTrace_GC_DONE(n + m); } |