diff --git a/Include/cpython/pystats.h b/Include/cpython/pystats.h index 887fbbedf88502..c575b9106b7dbe 100644 --- a/Include/cpython/pystats.h +++ b/Include/cpython/pystats.h @@ -94,6 +94,7 @@ typedef struct _gc_stats { uint64_t collections; uint64_t object_visits; uint64_t objects_collected; + uint64_t objects_queued; } GCStats; typedef struct _uop_stats { diff --git a/Python/gc.c b/Python/gc.c index d0f4ce38bbe567..82adc6f904fa71 100644 --- a/Python/gc.c +++ b/Python/gc.c @@ -1384,8 +1384,11 @@ expand_region_transitively_reachable(PyGC_Head *container, PyGC_Head *gc, GCStat static void completed_cycle(GCState *gcstate) { + #ifdef Py_DEBUG PyGC_Head *not_visited = &gcstate->old[gcstate->visited_space^1].head; assert(gc_list_is_empty(not_visited)); + #endif + gcstate->visited_space = flip_old_space(gcstate->visited_space); if (gcstate->work_to_do > 0) { gcstate->work_to_do = 0; @@ -1421,7 +1424,7 @@ gc_collect_increment(PyThreadState *tstate, struct gc_collection_stats *stats) gc_set_old_space(gc, gcstate->visited_space); increment_size += expand_region_transitively_reachable(&increment, gc, gcstate); } - GC_STAT_ADD(1, objects_queued, region_size); + GC_STAT_ADD(1, objects_queued, increment_size); PyGC_Head survivors; gc_list_init(&survivors); gc_collect_region(tstate, &increment, &survivors, UNTRACK_TUPLES, stats); @@ -1807,10 +1810,10 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason) _PyErr_SetRaisedException(tstate, exc); GC_STAT_ADD(generation, objects_collected, stats.collected); #ifdef Py_STATS - if (_py_stats) { + if (_Py_stats) { GC_STAT_ADD(generation, object_visits, - _py_stats->object_stats.object_visits); - _py_stats->object_stats.object_visits = 0; + _Py_stats->object_stats.object_visits); + _Py_stats->object_stats.object_visits = 0; } #endif validate_old(gcstate); diff --git a/Python/specialize.c b/Python/specialize.c index b1f9eb756c3665..09bfbede04eb68 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -212,6 +212,7 @@ print_gc_stats(FILE *out, GCStats *stats) fprintf(out, "GC[%d] collections: %" PRIu64 "\n", i, stats[i].collections); fprintf(out, "GC[%d] object visits: %" PRIu64 "\n", i, stats[i].object_visits); fprintf(out, "GC[%d] objects collected: %" PRIu64 "\n", i, stats[i].objects_collected); + fprintf(out, "GC[%d] objects queued: %" PRIu64 "\n", i, stats[i].objects_queued); } } diff --git a/Tools/scripts/summarize_stats.py b/Tools/scripts/summarize_stats.py index 6af14e1b769b80..ba1fc3e9ddcc3e 100644 --- a/Tools/scripts/summarize_stats.py +++ b/Tools/scripts/summarize_stats.py @@ -1103,6 +1103,7 @@ def calc_gc_stats(stats: Stats) -> Rows: Count(gen["collections"]), Count(gen["objects collected"]), Count(gen["object visits"]), + Count(gen["objects queued"]), ) for (i, gen) in enumerate(gc_stats) ] @@ -1112,7 +1113,13 @@ def calc_gc_stats(stats: Stats) -> Rows: "GC collections and effectiveness", [ Table( - ("Generation:", "Collections:", "Objects collected:", "Object visits:"), + ( + "Generation:", + "Collections:", + "Objects collected:", + "Object visits:", + "Objects queued:", + ), calc_gc_stats, ) ],
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: