summaryrefslogtreecommitdiffstats
path: root/Tools/scripts
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-08-04 09:34:23 (GMT)
committerGitHub <noreply@github.com>2023-08-04 09:34:23 (GMT)
commit2ba7c7f7b151ff56cf12bf3cab286981bb646c90 (patch)
treee89d562e9043fb9703a9b822de58a9bd4bedb1ac /Tools/scripts
parentfa45958450aa3489607daf9855ca0474a2a20878 (diff)
downloadcpython-2ba7c7f7b151ff56cf12bf3cab286981bb646c90.zip
cpython-2ba7c7f7b151ff56cf12bf3cab286981bb646c90.tar.gz
cpython-2ba7c7f7b151ff56cf12bf3cab286981bb646c90.tar.bz2
Add some GC stats to Py_STATS (GH-107581)
Diffstat (limited to 'Tools/scripts')
-rw-r--r--Tools/scripts/summarize_stats.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/Tools/scripts/summarize_stats.py b/Tools/scripts/summarize_stats.py
index 9c88189..f798b2f 100644
--- a/Tools/scripts/summarize_stats.py
+++ b/Tools/scripts/summarize_stats.py
@@ -494,6 +494,22 @@ def calculate_object_stats(stats):
rows.append((label, value, ratio))
return rows
+def calculate_gc_stats(stats):
+ gc_stats = []
+ for key, value in stats.items():
+ if not key.startswith("GC"):
+ continue
+ n, _, rest = key[3:].partition("]")
+ name = rest.strip()
+ gen_n = int(n)
+ while len(gc_stats) <= gen_n:
+ gc_stats.append({})
+ gc_stats[gen_n][name] = value
+ return [
+ (i, gen["collections"], gen["objects collected"], gen["object visits"])
+ for (i, gen) in enumerate(gc_stats)
+ ]
+
def emit_object_stats(stats):
with Section("Object stats", summary="allocations, frees and dict materializatons"):
rows = calculate_object_stats(stats)
@@ -505,6 +521,22 @@ def emit_comparative_object_stats(base_stats, head_stats):
head_rows = calculate_object_stats(head_stats)
emit_table(("", "Base Count:", "Base Ratio:", "Head Count:", "Head Ratio:"), join_rows(base_rows, head_rows))
+def emit_gc_stats(stats):
+ with Section("GC stats", summary="GC collections and effectiveness"):
+ rows = calculate_gc_stats(stats)
+ emit_table(("Generation:", "Collections:", "Objects collected:", "Object visits:"), rows)
+
+def emit_comparative_gc_stats(base_stats, head_stats):
+ with Section("GC stats", summary="GC collections and effectiveness"):
+ base_rows = calculate_gc_stats(base_stats)
+ head_rows = calculate_gc_stats(head_stats)
+ emit_table(
+ ("Generation:",
+ "Base collections:", "Head collections:",
+ "Base objects collected:", "Head objects collected:",
+ "Base object visits:", "Head object visits:"),
+ join_rows(base_rows, head_rows))
+
def get_total(opcode_stats):
total = 0
for opcode_stat in opcode_stats:
@@ -574,6 +606,7 @@ def output_single_stats(stats):
emit_specialization_overview(opcode_stats, total)
emit_call_stats(stats)
emit_object_stats(stats)
+ emit_gc_stats(stats)
with Section("Meta stats", summary="Meta statistics"):
emit_table(("", "Count:"), [('Number of data files', stats['__nfiles__'])])
@@ -596,6 +629,7 @@ def output_comparative_stats(base_stats, head_stats):
)
emit_comparative_call_stats(base_stats, head_stats)
emit_comparative_object_stats(base_stats, head_stats)
+ emit_comparative_gc_stats(base_stats, head_stats)
def output_stats(inputs, json_output=None):
if len(inputs) == 1: