Add some GC stats to Py_STATS (GH-107581)

This commit is contained in:
Mark Shannon 2023-08-04 10:34:23 +01:00 • committed by GitHub
parent fa45958450
commit 2ba7c7f7b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 80 additions and 1 deletions

View file

@ -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);
}