Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b1372e2

Browse filesBrowse files
[3.13] GH-122298: Restore printing of GC stats (GH-123261) (#123268)
GH-122298: Restore printing of GC stats (GH-123261) (cherry picked from commit 7cd3aa4) Co-authored-by: Mark Shannon <mark@hotpy.org>
1 parent d9e4c4b commit b1372e2
Copy full SHA for b1372e2

File tree

Expand file treeCollapse file tree

2 files changed

+28
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+28
-0
lines changed
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Restore printout of GC stats when ``gc.set_debug(gc.DEBUG_STATS)`` is
2+
called. This featue was accidentally removed when implementing incremental
3+
GC.

‎Python/gc.c

Copy file name to clipboardExpand all lines: Python/gc.c
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,7 @@ gc_collect_young(PyThreadState *tstate,
12891289
GCState *gcstate = &tstate->interp->gc;
12901290
PyGC_Head *young = &gcstate->young.head;
12911291
PyGC_Head *visited = &gcstate->old[gcstate->visited_space].head;
1292+
GC_STAT_ADD(0, collections, 1);
12921293
#ifdef Py_STATS
12931294
{
12941295
Py_ssize_t count = 0;
@@ -1417,6 +1418,7 @@ completed_cycle(GCState *gcstate)
14171418
static void
14181419
gc_collect_increment(PyThreadState *tstate, struct gc_collection_stats *stats)
14191420
{
1421+
GC_STAT_ADD(1, collections, 1);
14201422
GCState *gcstate = &tstate->interp->gc;
14211423
PyGC_Head *not_visited = &gcstate->old[gcstate->visited_space^1].head;
14221424
PyGC_Head *visited = &gcstate->old[gcstate->visited_space].head;
@@ -1462,6 +1464,7 @@ static void
14621464
gc_collect_full(PyThreadState *tstate,
14631465
struct gc_collection_stats *stats)
14641466
{
1467+
GC_STAT_ADD(2, collections, 1);
14651468
GCState *gcstate = &tstate->interp->gc;
14661469
validate_old(gcstate);
14671470
PyGC_Head *young = &gcstate->young.head;
@@ -1784,6 +1787,24 @@ PyGC_IsEnabled(void)
17841787
return gcstate->enabled;
17851788
}
17861789

1790+
// Show stats for objects in each generations
1791+
static void
1792+
show_stats_each_generations(GCState *gcstate)
1793+
{
1794+
char buf[100];
1795+
size_t pos = 0;
1796+
1797+
for (int i = 0; i < NUM_GENERATIONS && pos < sizeof(buf); i++) {
1798+
pos += PyOS_snprintf(buf+pos, sizeof(buf)-pos,
1799+
" %zd",
1800+
gc_list_size(GEN_HEAD(gcstate, i)));
1801+
}
1802+
PySys_FormatStderr(
1803+
"gc: objects in each generation:%s\n"
1804+
"gc: objects in permanent generation: %zd\n",
1805+
buf, gc_list_size(&gcstate->permanent_generation.head));
1806+
}
1807+
17871808
Py_ssize_t
17881809
_PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
17891810
{
@@ -1799,6 +1820,10 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
17991820
if (reason != _Py_GC_REASON_SHUTDOWN) {
18001821
invoke_gc_callback(gcstate, "start", generation, &stats);
18011822
}
1823+
if (gcstate->debug & _PyGC_DEBUG_STATS) {
1824+
PySys_WriteStderr("gc: collecting generation %d...\n", generation);
1825+
show_stats_each_generations(gcstate);
1826+
}
18021827
if (PyDTrace_GC_START_ENABLED()) {
18031828
PyDTrace_GC_START(generation);
18041829
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.