Skip to content

Commit 7f46627

Browse files
committed
visited -> candidates
1 parent 9be8100 commit 7f46627

File tree

7 files changed

+32
-31
lines changed

7 files changed

+32
-31
lines changed

Doc/library/gc.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ The :mod:`gc` module provides the following functions:
110110
to be uncollectable (and were therefore moved to the :data:`garbage`
111111
list) inside this generation;
112112

113-
* ``visited`` is the total number of unique objects visited during each
114-
collection of this generation;
113+
* ``candidates`` is the total number of objects in this generation which were
114+
traversed and considered for collection;
115115

116116
* ``duration`` is the total time in seconds spent in collections for this
117117
generation.
118118

119119
.. versionadded:: 3.4
120120

121121
.. versionchanged:: next
122-
Add ``duration`` and ``visited``.
122+
Add ``duration`` and ``candidates``.
123123

124124

125125
.. function:: set_threshold(threshold0, [threshold1, [threshold2]])
@@ -322,8 +322,8 @@ values but should not rebind them):
322322
"uncollectable": When *phase* is "stop", the number of objects
323323
that could not be collected and were put in :data:`garbage`.
324324

325-
"visited": When *phase* is "stop", the number of unique objects visited
326-
during the collection.
325+
"candidates": When *phase* is "stop", the total number of objects in this
326+
generation which were traversed and considered for collection.
327327

328328
"duration": When *phase* is "stop", the time in seconds spent in the
329329
collection.
@@ -341,7 +341,7 @@ values but should not rebind them):
341341
.. versionadded:: 3.3
342342

343343
.. versionchanged:: next
344-
Add "duration" and "visited".
344+
Add "duration" and "candidates".
345345

346346

347347
The following constants are provided for use with :func:`set_debug`:

Include/internal/pycore_interp_structs.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ struct gc_collection_stats {
179179
Py_ssize_t collected;
180180
/* total number of uncollectable objects (put into gc.garbage) */
181181
Py_ssize_t uncollectable;
182-
// Total number of objects visited:
183-
Py_ssize_t visited;
182+
// Total number of objects traversed and considered for collection:
183+
Py_ssize_t candidates;
184184
// Duration of the collection in seconds:
185185
double duration;
186186
};
@@ -193,8 +193,8 @@ struct gc_generation_stats {
193193
Py_ssize_t collected;
194194
/* total number of uncollectable objects (put into gc.garbage) */
195195
Py_ssize_t uncollectable;
196-
// Total number of objects visited:
197-
Py_ssize_t visited;
196+
// Total number of objects traversed and considered for collection:
197+
Py_ssize_t candidates;
198198
// Duration of the collection in seconds:
199199
double duration;
200200
};

Lib/test/test_gc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -848,12 +848,12 @@ def test_get_stats(self):
848848
self.assertIsInstance(st, dict)
849849
self.assertEqual(
850850
set(st),
851-
{"collected", "collections", "uncollectable", "visited", "duration"}
851+
{"collected", "collections", "uncollectable", "candidates", "duration"}
852852
)
853853
self.assertGreaterEqual(st["collected"], 0)
854854
self.assertGreaterEqual(st["collections"], 0)
855855
self.assertGreaterEqual(st["uncollectable"], 0)
856-
self.assertGreaterEqual(st["visited"], 0)
856+
self.assertGreaterEqual(st["candidates"], 0)
857857
self.assertGreaterEqual(st["duration"], 0)
858858
# Check that collection counts are incremented correctly
859859
if gc.isenabled():
@@ -868,7 +868,7 @@ def test_get_stats(self):
868868
self.assertGreater(new[0]["duration"], old[0]["duration"])
869869
self.assertEqual(new[1]["duration"], old[1]["duration"])
870870
self.assertEqual(new[2]["duration"], old[2]["duration"])
871-
for stat in ["collected", "uncollectable", "visited"]:
871+
for stat in ["collected", "uncollectable", "candidates"]:
872872
self.assertGreaterEqual(new[0][stat], old[0][stat])
873873
self.assertEqual(new[1][stat], old[1][stat])
874874
self.assertEqual(new[2][stat], old[2][stat])
@@ -880,7 +880,7 @@ def test_get_stats(self):
880880
self.assertEqual(new[0]["duration"], old[0]["duration"])
881881
self.assertEqual(new[1]["duration"], old[1]["duration"])
882882
self.assertGreater(new[2]["duration"], old[2]["duration"])
883-
for stat in ["collected", "uncollectable", "visited"]:
883+
for stat in ["collected", "uncollectable", "candidates"]:
884884
self.assertEqual(new[0][stat], old[0][stat])
885885
self.assertEqual(new[1][stat], old[1][stat])
886886
self.assertGreaterEqual(new[2][stat], old[2][stat])
@@ -1319,7 +1319,7 @@ def test_collect(self):
13191319
self.assertIn("generation", info)
13201320
self.assertIn("collected", info)
13211321
self.assertIn("uncollectable", info)
1322-
self.assertIn("visited", info)
1322+
self.assertIn("candidates", info)
13231323
self.assertIn("duration", info)
13241324

13251325
def test_collect_generation(self):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Expose a ``"visited"`` stat in :func:`gc.get_stats` and
1+
Expose a ``"candidates"`` stat in :func:`gc.get_stats` and
22
:data:`gc.callbacks`.

Modules/gcmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ gc_get_stats_impl(PyObject *module)
362362
"collections", st->collections,
363363
"collected", st->collected,
364364
"uncollectable", st->uncollectable,
365-
"visited", st->visited,
365+
"candidates", st->candidates,
366366
"duration", st->duration
367367
);
368368
if (dict == NULL)

Python/gc.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ update_refs(PyGC_Head *containers)
488488
{
489489
PyGC_Head *next;
490490
PyGC_Head *gc = GC_NEXT(containers);
491-
Py_ssize_t visited = 0;
491+
Py_ssize_t candidates = 0;
492492

493493
while (gc != containers) {
494494
next = GC_NEXT(gc);
@@ -520,9 +520,9 @@ update_refs(PyGC_Head *containers)
520520
*/
521521
_PyObject_ASSERT(op, gc_get_refs(gc) != 0);
522522
gc = next;
523-
visited++;
523+
candidates++;
524524
}
525-
return visited;
525+
return candidates;
526526
}
527527

528528
/* A traversal callback for subtract_refs. */
@@ -1251,7 +1251,7 @@ deduce_unreachable(PyGC_Head *base, PyGC_Head *unreachable) {
12511251
* refcount greater than 0 when all the references within the
12521252
* set are taken into account).
12531253
*/
1254-
Py_ssize_t visited = update_refs(base); // gc_prev is used for gc_refs
1254+
Py_ssize_t candidates = update_refs(base); // gc_prev is used for gc_refs
12551255
subtract_refs(base);
12561256

12571257
/* Leave everything reachable from outside base in base, and move
@@ -1292,7 +1292,7 @@ deduce_unreachable(PyGC_Head *base, PyGC_Head *unreachable) {
12921292
move_unreachable(base, unreachable); // gc_prev is pointer again
12931293
validate_list(base, collecting_clear_unreachable_clear);
12941294
validate_list(unreachable, collecting_set_unreachable_set);
1295-
return visited;
1295+
return candidates;
12961296
}
12971297

12981298
/* Handle objects that may have resurrected after a call to 'finalize_garbage', moving
@@ -1368,9 +1368,9 @@ static void
13681368
add_stats(GCState *gcstate, int gen, struct gc_collection_stats *stats)
13691369
{
13701370
gcstate->generation_stats[gen].duration += stats->duration;
1371-
gcstate->generation_stats[gen].visited += stats->visited;
13721371
gcstate->generation_stats[gen].collected += stats->collected;
13731372
gcstate->generation_stats[gen].uncollectable += stats->uncollectable;
1373+
gcstate->generation_stats[gen].candidates += stats->candidates;
13741374
gcstate->generation_stats[gen].collections += 1;
13751375
}
13761376

@@ -1759,7 +1759,7 @@ gc_collect_region(PyThreadState *tstate,
17591759
assert(!_PyErr_Occurred(tstate));
17601760

17611761
gc_list_init(&unreachable);
1762-
stats->visited = deduce_unreachable(from, &unreachable);
1762+
stats->candidates = deduce_unreachable(from, &unreachable);
17631763
validate_consistent_old_space(from);
17641764
untrack_tuples(from);
17651765

@@ -1853,7 +1853,7 @@ do_gc_callback(GCState *gcstate, const char *phase,
18531853
"generation", generation,
18541854
"collected", stats->collected,
18551855
"uncollectable", stats->uncollectable,
1856-
"visited", stats->visited,
1856+
"candidates", stats->candidates,
18571857
"duration", stats->duration);
18581858
if (info == NULL) {
18591859
PyErr_FormatUnraisable("Exception ignored while invoking gc callbacks");

Python/gc_free_threading.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ struct collection_state {
9898
// we can't collect objects with deferred references because we may not
9999
// see all references.
100100
int skip_deferred_objects;
101-
Py_ssize_t visited;
102101
Py_ssize_t collected;
103102
Py_ssize_t uncollectable;
103+
Py_ssize_t candidates;
104104
Py_ssize_t long_lived_total;
105105
struct worklist unreachable;
106106
struct worklist legacy_finalizers;
@@ -993,7 +993,7 @@ update_refs(const mi_heap_t *heap, const mi_heap_area_t *area,
993993
gc_clear_unreachable(op);
994994
return true;
995995
}
996-
state->visited++;
996+
state->candidates++;
997997

998998
Py_ssize_t refcount = Py_REFCNT(op);
999999
if (_PyObject_HasDeferredRefcount(op)) {
@@ -1914,7 +1914,8 @@ handle_resurrected_objects(struct collection_state *state)
19141914
static void
19151915
invoke_gc_callback(PyThreadState *tstate, const char *phase,
19161916
int generation, Py_ssize_t collected,
1917-
Py_ssize_t uncollectable, Py_ssize_t visited, double duration)
1917+
Py_ssize_t uncollectable, Py_ssize_t candidates,
1918+
double duration)
19181919
{
19191920
assert(!_PyErr_Occurred(tstate));
19201921

@@ -1932,7 +1933,7 @@ invoke_gc_callback(PyThreadState *tstate, const char *phase,
19321933
"generation", generation,
19331934
"collected", collected,
19341935
"uncollectable", uncollectable,
1935-
"visited", visited,
1936+
"candidates", candidates,
19361937
"duration", duration);
19371938
if (info == NULL) {
19381939
PyErr_FormatUnraisable("Exception ignored while "
@@ -2431,7 +2432,7 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason)
24312432
stats->collected += m;
24322433
stats->uncollectable += n;
24332434
stats->duration += duration;
2434-
stats->visited += state.visited;
2435+
stats->candidates += state.candidates;
24352436

24362437
GC_STAT_ADD(generation, objects_collected, m);
24372438
#ifdef Py_STATS
@@ -2450,7 +2451,7 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason)
24502451
}
24512452

24522453
if (reason != _Py_GC_REASON_SHUTDOWN) {
2453-
invoke_gc_callback(tstate, "stop", generation, m, n, state.visited, duration);
2454+
invoke_gc_callback(tstate, "stop", generation, m, n, state.candidates, duration);
24542455
}
24552456

24562457
assert(!_PyErr_Occurred(tstate));

0 commit comments

Comments
 (0)