gh-114312: Collect stats for unlikely events (GH-114493)

This commit is contained in:
Michael Droettboom 2024-01-25 06:10:51 -05:00 committed by GitHub
parent c63c6142f9
commit ea3cd0498c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 199 additions and 1 deletions

View file

@ -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)