8000 GH-108362: Incremental GC implementation by markshannon · Pull Request #116199 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-108362: Incremental GC implementation #116199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Restore printing of stats when _PyGC_DEBUG_STATS is set.
  • Loading branch information
markshannon committed Jan 8, 2024
commit aa27357982d316c11fd6047c0be0ce3888fca30f
32 changes: 32 additions & 0 deletions Python/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,25 @@ PyGC_IsEnabled(void)
return gcstate->enabled;
}

// Show stats for objects in each generations
static void
show_stats_each_generations(GCState *gcstate)
{
char buf[100];
size_t pos = 0;

for (int i = 0; i < NUM_GENERATIONS && pos < sizeof(buf); i++) {
pos += PyOS_snprintf(buf+pos, sizeof(buf)-pos,
" %zd",
gc_list_size(GEN_HEAD(gcstate, i)));
}

PySys_FormatStderr(
"gc: objects in each generation:%s\n"
"gc: objects in permanent generation: %zd\n",
buf, gc_list_size(&gcstate->permanent_generation.head));
}

Py_ssize_t
_PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
{
Expand All @@ -1762,6 +1781,12 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
if (reason != _Py_GC_REASON_SHUTDOWN) {
invoke_gc_callback(gcstate, "start", generation, &stats);
}
_PyTime_t t1 = 0; /* initialize to prevent a compiler warning */
if (gcstate->debug & _PyGC_DEBUG_STATS) {
PySys_WriteStderr("gc: collecting generation %d...\n", generation);
show_stats_each_generations(gcstate);
t1 = _PyTime_GetPerfCounter();
}
if (PyDTrace_GC_START_ENABLED()) {
PyDTrace_GC_START(generation);
}
Expand Down Expand Up @@ -1797,6 +1822,13 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
}
#endif
validate_old(gcstate);
if (gcstate->debug & _PyGC_DEBUG_STATS) {
double d = _PyTime_AsSecondsDouble(_PyTime_GetPerfCounter() - t1);
PySys_WriteStderr(
"gc: done, %zd collected, %zd uncollectable, %.4fs elapsed\n",
stats.collected, stats.uncollectable, d);
}

_Py_atomic_store_int(&gcstate->collecting, 0);
return stats.uncollectable + stats.collected;
}
Expand Down
0