Skip to content

Commit 41814f3

Browse files
committed
Update docs and tests
1 parent 3ee8db9 commit 41814f3

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

Doc/library/gc.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +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;
115+
113116
* ``duration`` is the total time in seconds spent in collections for this
114117
generation.
115118

116119
.. versionadded:: 3.4
117120

118121
.. versionchanged:: next
119-
Add ``duration``.
122+
Add ``duration`` and ``visited``.
120123

121124

122125
.. function:: set_threshold(threshold0, [threshold1, [threshold2]])
@@ -319,6 +322,9 @@ values but should not rebind them):
319322
"uncollectable": When *phase* is "stop", the number of objects
320323
that could not be collected and were put in :data:`garbage`.
321324

325+
"visited": When *phase* is "stop", the number of unique objects visited
326+
during the collection.
327+
322328
"duration": When *phase* is "stop", the time in seconds spent in the
323329
collection.
324330

@@ -335,7 +341,7 @@ values but should not rebind them):
335341
.. versionadded:: 3.3
336342

337343
.. versionchanged:: next
338-
Add "duration".
344+
Add "duration" and "visited".
339345

340346

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

Lib/test/test_gc.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -846,11 +846,14 @@ def test_get_stats(self):
846846
self.assertEqual(len(stats), 3)
847847
for st in stats:
848848
self.assertIsInstance(st, dict)
849-
self.assertEqual(set(st),
850-
{"collected", "collections", "uncollectable", "duration"})
849+
self.assertEqual(
850+
set(st),
851+
{"collected", "collections", "uncollectable", "visited", "duration"}
852+
)
851853
self.assertGreaterEqual(st["collected"], 0)
852854
self.assertGreaterEqual(st["collections"], 0)
853855
self.assertGreaterEqual(st["uncollectable"], 0)
856+
self.assertGreaterEqual(st["visited"], 0)
854857
self.assertGreaterEqual(st["duration"], 0)
855858
# Check that collection counts are incremented correctly
856859
if gc.isenabled():
@@ -865,7 +868,7 @@ def test_get_stats(self):
865868
self.assertGreater(new[0]["duration"], old[0]["duration"])
866869
self.assertEqual(new[1]["duration"], old[1]["duration"])
867870
self.assertEqual(new[2]["duration"], old[2]["duration"])
868-
for stat in ["collected", "uncollectable"]:
871+
for stat in ["collected", "uncollectable", "visited"]:
869872
self.assertGreaterEqual(new[0][stat], old[0][stat])
870873
self.assertEqual(new[1][stat], old[1][stat])
871874
self.assertEqual(new[2][stat], old[2][stat])
@@ -877,7 +880,7 @@ def test_get_stats(self):
877880
self.assertEqual(new[0]["duration"], old[0]["duration"])
878881
self.assertEqual(new[1]["duration"], old[1]["duration"])
879882
self.assertGreater(new[2]["duration"], old[2]["duration"])
880-
for stat in ["collected", "uncollectable"]:
883+
for stat in ["collected", "uncollectable", "visited"]:
881884
self.assertEqual(new[0][stat], old[0][stat])
882885
self.assertEqual(new[1][stat], old[1][stat])
883886
self.assertGreaterEqual(new[2][stat], old[2][stat])
@@ -1316,6 +1319,7 @@ def test_collect(self):
13161319
self.assertIn("generation", info)
13171320
self.assertIn("collected", info)
13181321
self.assertIn("uncollectable", info)
1322+
self.assertIn("visited", info)
13191323
self.assertIn("duration", info)
13201324

13211325
def test_collect_generation(self):

Python/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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->visited = deduce_unreachable(from, &unreachable);
17631763
validate_consistent_old_space(from);
17641764
untrack_tuples(from);
17651765

0 commit comments

Comments
 (0)