summaryrefslogtreecommitdiffstats
path: root/Tools/scripts/summarize_stats.py
diff options
context:
space:
mode:
authorMichael Droettboom <mdboom@gmail.com>2024-01-25 11:10:51 (GMT)
committerGitHub <noreply@github.com>2024-01-25 11:10:51 (GMT)
commitea3cd0498c443e93be441736c804258e93d21edd (patch)
treeab975dc0fe8c933fd2c197275a7d9fc6598aa04b /Tools/scripts/summarize_stats.py
parentc63c6142f9146e1e977f4c824c56e8979e6aca87 (diff)
downloadcpython-ea3cd0498c443e93be441736c804258e93d21edd.zip
cpython-ea3cd0498c443e93be441736c804258e93d21edd.tar.gz
cpython-ea3cd0498c443e93be441736c804258e93d21edd.tar.bz2
gh-114312: Collect stats for unlikely events (GH-114493)
Diffstat (limited to 'Tools/scripts/summarize_stats.py')
-rw-r--r--Tools/scripts/summarize_stats.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/Tools/scripts/summarize_stats.py b/Tools/scripts/summarize_stats.py
index 1e9dc07..9b7e7b9 100644
--- a/Tools/scripts/summarize_stats.py
+++ b/Tools/scripts/summarize_stats.py
@@ -412,6 +412,14 @@ class Stats:
rows.sort()
return rows
+ def get_rare_events(self) -> list[tuple[str, int]]:
+ prefix = "Rare event "
+ return [
+ (key[len(prefix) + 1:-1], val)
+ for key, val in self._data.items()
+ if key.startswith(prefix)
+ ]
+
class Count(int):
def markdown(self) -> str:
@@ -1064,6 +1072,17 @@ def optimization_section() -> Section:
)
+def rare_event_section() -> Section:
+ def calc_rare_event_table(stats: Stats) -> Table:
+ return [(x, Count(y)) for x, y in stats.get_rare_events()]
+
+ return Section(
+ "Rare events",
+ "Counts of rare/unlikely events",
+ [Table(("Event", "Count:"), calc_rare_event_table, JoinMode.CHANGE)],
+ )
+
+
def meta_stats_section() -> Section:
def calc_rows(stats: Stats) -> Rows:
return [("Number of data files", Count(stats.get("__nfiles__")))]
@@ -1085,6 +1104,7 @@ LAYOUT = [
object_stats_section(),
gc_stats_section(),
optimization_section(),
+ rare_event_section(),
meta_stats_section(),
]
@@ -1162,7 +1182,7 @@ def output_stats(inputs: list[Path], json_output=str | None):
case 1:
data = load_raw_data(Path(inputs[0]))
if json_output is not None:
- with open(json_output, 'w', encoding='utf-8') as f:
+ with open(json_output, "w", encoding="utf-8") as f:
save_raw_data(data, f) # type: ignore
stats = Stats(data)
output_markdown(sys.stdout, LAYOUT, stats)