Skip to content

Commit f286c3d

Browse files
committed
Add stats on how objects are passed to GC.
1 parent 58901ff commit f286c3d

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

Include/pystats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ typedef struct _object_stats {
8181
typedef struct _gc_stats {
8282
uint64_t collections;
8383
uint64_t object_visits;
84+
uint64_t objects_queued;
8485
uint64_t objects_collected;
8586
} GCStats;
8687

Modules/gcmodule.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,14 +1295,16 @@ gc_collect_young(PyThreadState *tstate,
12951295
PyGC_Head *young = &gcstate->young.head;
12961296
PyGC_Head *aging = &gcstate->old[gcstate->aging_space].head;
12971297
validate_old(gcstate);
1298-
if (gcstate->aging_space) {
1299-
/* objects in aging space have bit set, so we need to
1300-
* do that here */
1298+
#ifdef Py_STATS
1299+
{
1300+
Py_ssize_t count = 0;
13011301
PyGC_Head *gc;
13021302
for (gc = GC_NEXT(young); gc != young; gc = GC_NEXT(gc)) {
1303-
gc_set_old_space(gc, 1);
1303+
count++;
13041304
}
1305+
GC_STAT_ADD(0, objects_queued, count);
13051306
}
1307+
#endif
13061308
validate_old(gcstate);
13071309
PyGC_Head survivors;
13081310
gc_list_init(&survivors);
@@ -1465,6 +1467,16 @@ gc_collect_increment(PyThreadState *tstate, struct gc_collection_stats *stats)
14651467
}
14661468
validate_old(gcstate);
14671469
validate_list_is_aging(&increment);
1470+
#ifdef Py_STATS
1471+
{
1472+
Py_ssize_t count = 0;
1473+
PyGC_Head *gc;
1474+
for (gc = GC_NEXT(&increment); gc != &increment; gc = GC_NEXT(gc)) {
1475+
count++;
1476+
}
1477+
GC_STAT_ADD(NUM_GENERATIONS, objects_queued, count);
1478+
}
1479+
#endif
14681480
gc_collect_region(tstate, &increment, aging, 0, stats);
14691481
validate_old(gcstate);
14701482
assert(gc_list_is_empty(&increment));

0 commit comments

Comments
 (0)