Skip to content

Commit cb3d362

Browse files
committed
gh-116879: Add new optimizer pystats to tables
1 parent 950667e commit cb3d362

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Tools/scripts/summarize_stats.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ def get_optimization_stats(self) -> dict[str, tuple[int, int | None]]:
441441
return {}
442442

443443
attempts = self._data["Optimization attempts"]
444+
estimated_incorrectly = self._data["Optimization estimated incorrectly"]
445+
estimated_correctly = self._data["Optimization estimated correctly"]
444446
created = self._data["Optimization traces created"]
445447
executed = self._data["Optimization traces executed"]
446448
uops = self._data["Optimization uops executed"]
@@ -466,6 +468,8 @@ def get_optimization_stats(self) -> dict[str, tuple[int, int | None]]:
466468
Doc(
467469
"Traces created", "The number of traces that were successfully created."
468470
): (created, attempts),
471+
Doc("Estimated incorrectly", ""): (estimated_incorrectly, attempts),
472+
Doc("Estimated correctly", ""): (estimated_correctly, attempts),
469473
Doc(
470474
"Trace stack overflow",
471475
"A trace is truncated because it would require more than 5 stack frames.",
@@ -512,6 +516,27 @@ def get_optimization_stats(self) -> dict[str, tuple[int, int | None]]:
512516
),
513517
}
514518

519+
def get_optimizer_stats(self) -> dict[str, tuple[int, int | None]]:
520+
attempts = self._data["Optimization optimizer attempts"]
521+
successes = self._data["Optimization optimizer successes"]
522+
no_memory = self._data["Optimization optimizer failure no memory"]
523+
524+
return {
525+
Doc(
526+
"Optimizer attempts",
527+
"The number of times the trace optimizer (_Py_uop_analyze_and_optimize) was run."
528+
): (
529+
attempts,
530+
None,
531+
),
532+
Doc(
533+
"Optimizer successes", "The number of traces that were successfully optimized."
534+
): (successes, attempts),
535+
Doc(
536+
"Optimizer no memory", "The number of optimizations that failed due to no memory."
537+
): (no_memory, attempts),
538+
}
539+
515540
def get_histogram(self, prefix: str) -> list[tuple[int, int]]:
516541
rows = []
517542
for k, v in self._data.items():
@@ -1118,6 +1143,18 @@ def calc_optimization_table(stats: Stats) -> Rows:
11181143
for label, (value, den) in optimization_stats.items()
11191144
]
11201145

1146+
def calc_optimizer_table(stats: Stats) -> Rows:
1147+
optimizer_stats = stats.get_optimizer_stats()
1148+
1149+
return [
1150+
(
1151+
label,
1152+
Count(value),
1153+
Ratio(value, den, percentage=label != "Uops executed"),
1154+
)
1155+
for label, (value, den) in optimizer_stats.items()
1156+
]
1157+
11211158
def calc_histogram_table(key: str, den: str) -> RowCalculator:
11221159
def calc(stats: Stats) -> Rows:
11231160
histogram = stats.get_histogram(key)
@@ -1159,6 +1196,7 @@ def iter_optimization_tables(base_stats: Stats, head_stats: Stats | None = None)
11591196
return
11601197

11611198
yield Table(("", "Count:", "Ratio:"), calc_optimization_table, JoinMode.CHANGE)
1199+
yield Table(("", "Count:", "Ratio:"), calc_optimizer_table, JoinMode.CHANGE)
11621200
for name, den in [
11631201
("Trace length", "Optimization traces created"),
11641202
("Optimized trace length", "Optimization traces created"),

0 commit comments

Comments
 (0)