Skip to content

Commit

Permalink
pythongh-117122: Fix pystats after incremental GC changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed Mar 21, 2024
1 parent 1f8b24e commit 4169667
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions Include/cpython/pystats.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 4 additions & 5 deletions Python/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,6 @@ expand_region_transitively_reachable(PyGC_Head *container, PyGC_Head *gc, GCStat
static void
completed_cycle(GCState *gcstate)
{
PyGC_Head *not_visited = &gcstate->old[gcstate->visited_space^1].head;
assert(gc_list_is_empty(not_visited));
gcstate->visited_space = flip_old_space(gcstate->visited_space);
if (gcstate->work_to_do > 0) {
Expand Down Expand Up @@ -1421,7 +1420,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);
Expand Down Expand Up @@ -1807,10 +1806,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);
Expand Down
1 change: 1 addition & 0 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
9 changes: 8 additions & 1 deletion Tools/scripts/summarize_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]
Expand All @@ -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,
)
],
Expand Down

0 comments on commit 4169667

Please sign in to comment.