Add some GC stats to Py_STATS (GH-107581)

This commit is contained in:
Mark Shannon 2023-08-04 10:34:23 +01:00 committed by GitHub
parent fa45958450
commit 2ba7c7f7b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 80 additions and 1 deletions

View file

@ -18,7 +18,8 @@
*/
#ifdef Py_STATS
PyStats _py_stats_struct = { 0 };
GCStats _py_gc_stats[NUM_GENERATIONS] = { 0 };
PyStats _py_stats_struct = { .gc_stats = &_py_gc_stats[0] };
PyStats *_py_stats = NULL;
#define ADD_STAT_TO_DICT(res, field) \
@ -202,17 +203,32 @@ print_object_stats(FILE *out, ObjectStats *stats)
fprintf(out, "Optimization uops executed: %" PRIu64 "\n", stats->optimization_uops_executed);
}
static void
print_gc_stats(FILE *out, GCStats *stats)
{
for (int i = 0; i < NUM_GENERATIONS; i++) {
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);
}
}
static void
print_stats(FILE *out, PyStats *stats) {
print_spec_stats(out, stats->opcode_stats);
print_call_stats(out, &stats->call_stats);
print_object_stats(out, &stats->object_stats);
print_gc_stats(out, stats->gc_stats);
}
void
_Py_StatsClear(void)
{
for (int i = 0; i < NUM_GENERATIONS; i++) {
_py_gc_stats[i] = (GCStats) { 0 };
}
_py_stats_struct = (PyStats) { 0 };
_py_stats_struct.gc_stats = _py_gc_stats;
}
void