diff options
author | Mark Shannon <mark@hotpy.org> | 2023-08-04 09:34:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-04 09:34:23 (GMT) |
commit | 2ba7c7f7b151ff56cf12bf3cab286981bb646c90 (patch) | |
tree | e89d562e9043fb9703a9b822de58a9bd4bedb1ac /Python/specialize.c | |
parent | fa45958450aa3489607daf9855ca0474a2a20878 (diff) | |
download | cpython-2ba7c7f7b151ff56cf12bf3cab286981bb646c90.zip cpython-2ba7c7f7b151ff56cf12bf3cab286981bb646c90.tar.gz cpython-2ba7c7f7b151ff56cf12bf3cab286981bb646c90.tar.bz2 |
Add some GC stats to Py_STATS (GH-107581)
Diffstat (limited to 'Python/specialize.c')
-rw-r--r-- | Python/specialize.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/Python/specialize.c b/Python/specialize.c index 1669ce1..de329ef 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -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) \ @@ -203,16 +204,31 @@ print_object_stats(FILE *out, ObjectStats *stats) } 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 |