[Python-checkins] Right justify numeric columns in stats summary script. (GH-31234)

markshannon webhook-mailer at python.org
Thu Feb 10 06:01:26 EST 2022


https://github.com/python/cpython/commit/cfc1cecd7b6f0f27163b5bf519530284140cf5b2
commit: cfc1cecd7b6f0f27163b5bf519530284140cf5b2
branch: main
author: Mark Shannon <mark at hotpy.org>
committer: markshannon <mark at hotpy.org>
date: 2022-02-10T11:01:18Z
summary:

Right justify numeric columns in stats summary script. (GH-31234)

files:
M Tools/scripts/summarize_stats.py

diff --git a/Tools/scripts/summarize_stats.py b/Tools/scripts/summarize_stats.py
index da0bab2390f3d..6e0286f52a0ea 100644
--- a/Tools/scripts/summarize_stats.py
+++ b/Tools/scripts/summarize_stats.py
@@ -55,7 +55,7 @@ def print_specialization_stats(name, family_stats, defines):
             label = label[0].upper() + label[1:]
             val = family_stats.get(key, 0)
             rows.append((label, val, f"{100*val/total_attempts:0.1f}%"))
-        emit_table(("", "Count", "Ratio"), rows)
+        emit_table(("", "Count:", "Ratio:"), rows)
         total_failures = family_stats.get("specialization.failure", 0)
         failure_kinds = [ 0 ] * 30
         for key in family_stats:
@@ -71,7 +71,7 @@ def print_specialization_stats(name, family_stats, defines):
             if not value:
                 continue
             rows.append((kind_to_text(index, defines, name), value, f"{100*value/total_failures:0.1f}%"))
-        emit_table(("Failure kind", "Count", "Ratio"), rows)
+        emit_table(("Failure kind", "Count:", "Ratio:"), rows)
 
 def gather_stats():
     stats = collections.Counter()
@@ -174,8 +174,17 @@ def __exit__(*args):
 
 def emit_table(header, rows):
     width = len(header)
-    print("|", " | ".join(header), "|")
-    print("|", " | ".join(["---"]*width), "|")
+    header_line = "|"
+    under_line = "|"
+    for item in header:
+        under = "---"
+        if item.endswith(":"):
+            item = item[:-1]
+            under += ":"
+        header_line += item + " | "
+        under_line += under + "|"
+    print(header_line)
+    print(under_line)
     for row in rows:
         if width is not None and len(row) != width:
             raise ValueError("Wrong number of elements in row '" + str(rows) + "'")
@@ -204,7 +213,7 @@ def emit_execution_counts(opcode_stats, total):
             rows.append((name, count, f"{100*count/total:0.1f}%",
                         f"{100*cumulative/total:0.1f}%", miss))
         emit_table(
-            ("Name", "Count", "Self", "Cumulative", "Miss ratio"),
+            ("Name", "Count:", "Self:", "Cumulative:", "Miss ratio:"),
             rows
         )
 
@@ -221,7 +230,7 @@ def emit_specialization_stats(opcode_stats):
 def emit_specialization_overview(opcode_stats, total):
     basic, not_specialized, specialized = categorized_counts(opcode_stats)
     with Section("Specialization effectiveness"):
-        emit_table(("Instructions", "Count", "Ratio"), (
+        emit_table(("Instructions", "Count:", "Ratio:"), (
             ("Basic", basic, f"{basic*100/total:0.1f}%"),
             ("Not specialized", not_specialized, f"{not_specialized*100/total:0.1f}%"),
             ("Specialized", specialized, f"{specialized*100/total:0.1f}%"),
@@ -240,7 +249,7 @@ def emit_call_stats(stats):
         for key, value in stats.items():
             if key.startswith("Frame"):
                 rows.append((key, value, f"{100*value/total:0.1f}%"))
-        emit_table(("", "Count", "Ratio"), rows)
+        emit_table(("", "Count:", "Ratio:"), rows)
 
 def emit_object_stats(stats):
     with Section("Object stats", summary="allocations, frees and dict materializatons"):
@@ -255,7 +264,7 @@ def emit_object_stats(stats):
                 label = key[6:].strip()
                 label = label[0].upper() + label[1:]
                 rows.append((label, value, materialize))
-        emit_table(("",  "Count", "Ratio"), rows)
+        emit_table(("",  "Count:", "Ratio:"), rows)
 
 def main():
     stats = gather_stats()



More information about the Python-checkins mailing list