Skip to content
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

gh-117122: Fix pystats after incremental GC changes #117123

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
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
11 changes: 7 additions & 4 deletions Python/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@
Py_ssize_t size = 0;
PyGC_Head *gc;
for (gc = GC_NEXT(list); gc != list; gc = GC_NEXT(gc)) {
gc_set_old_space(gc, space);

Check warning on line 1240 in Python/gc.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'function': conversion from 'uintptr_t' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 1240 in Python/gc.c

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

'function': conversion from 'uintptr_t' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]
size++;
}
return size;
Expand Down Expand Up @@ -1384,8 +1384,11 @@
static void
completed_cycle(GCState *gcstate)
{
#ifdef Py_DEBUG
PyGC_Head *not_visited = &gcstate->old[gcstate->visited_space^1].head;
mdboom marked this conversation as resolved.
Show resolved Hide resolved
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;
Expand Down Expand Up @@ -1421,7 +1424,7 @@
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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is correct, but region_size doesn't exist.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this make sense anymore. Maybe just drop the "queued" stat?

PyGC_Head survivors;
gc_list_init(&survivors);
gc_collect_region(tstate, &increment, &survivors, UNTRACK_TUPLES, stats);
Expand Down Expand Up @@ -1697,7 +1700,7 @@
}
}
else {
if (append_objects(result, GEN_HEAD(gcstate, generation))) {

Check warning on line 1703 in Python/gc.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'function': conversion from 'Py_ssize_t' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 1703 in Python/gc.c

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

'function': conversion from 'Py_ssize_t' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]
goto error;
}
}
Expand Down Expand Up @@ -1807,10 +1810,10 @@
_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
Loading