From b53624274dc07ac307c48c92283128755620774b Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Thu, 26 Oct 2023 11:33:12 +0100 Subject: [PATCH] GH-111213: Fix a few broken stats (GH-111216) --- Python/specialize.c | 2 +- Tools/scripts/summarize_stats.py | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Python/specialize.c b/Python/specialize.c index 49633b103b3815b..8e2476066570501 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -134,7 +134,7 @@ print_spec_stats(FILE *out, OpcodeStats *stats) fprintf(out, "opcode[BINARY_SLICE].specializable : 1\n"); fprintf(out, "opcode[STORE_SLICE].specializable : 1\n"); for (int i = 0; i < 256; i++) { - if (_PyOpcode_Caches[i]) { + if (_PyOpcode_Caches[i] && i != JUMP_BACKWARD) { fprintf(out, "opcode[%s].specializable : 1\n", _PyOpcode_OpName[i]); } PRINT_STAT(i, specialization.success); diff --git a/Tools/scripts/summarize_stats.py b/Tools/scripts/summarize_stats.py index 071b24a59ef44eb..165b9b40566a2d5 100644 --- a/Tools/scripts/summarize_stats.py +++ b/Tools/scripts/summarize_stats.py @@ -251,7 +251,8 @@ def is_specializable(self, opcode: str) -> bool: def get_specialized_total_counts(self) -> tuple[int, int, int]: basic = 0 - specialized = 0 + specialized_hits = 0 + specialized_misses = 0 not_specialized = 0 for opcode, opcode_stat in self._data.items(): if "execution_count" not in opcode_stat: @@ -261,16 +262,17 @@ def get_specialized_total_counts(self) -> tuple[int, int, int]: not_specialized += count elif opcode in self._specialized_instructions: miss = opcode_stat.get("specialization.miss", 0) - not_specialized += miss - specialized += count - miss + specialized_hits += count - miss + specialized_misses += miss else: basic += count - return basic, specialized, not_specialized + return basic, specialized_hits, specialized_misses, not_specialized def get_deferred_counts(self) -> dict[str, int]: return { opcode: opcode_stat.get("specialization.deferred", 0) for opcode, opcode_stat in self._data.items() + if opcode != "RESUME" } def get_misses_counts(self) -> dict[str, int]: @@ -799,7 +801,8 @@ def calc_specialization_effectiveness_table(stats: Stats) -> Rows: ( basic, - specialized, + specialized_hits, + specialized_misses, not_specialized, ) = opcode_stats.get_specialized_total_counts() @@ -810,7 +813,16 @@ def calc_specialization_effectiveness_table(stats: Stats) -> Rows: Count(not_specialized), Ratio(not_specialized, total), ), - ("Specialized", Count(specialized), Ratio(specialized, total)), + ( + "Specialized hits", + Count(specialized_hits), + Ratio(specialized_hits, total), + ), + ( + "Specialized misses", + Count(specialized_misses), + Ratio(specialized_misses, total), + ), ] def calc_deferred_by_table(stats: Stats) -> Rows: