Skip to content

Commit

Permalink
pythonGH-111213: Fix a few broken stats (pythonGH-111216)
Browse files Browse the repository at this point in the history
  • Loading branch information
markshannon authored and Glyphack committed Jan 27, 2024
1 parent 48a19b7 commit 2817103
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 18 additions & 6 deletions Tools/scripts/summarize_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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]:
Expand Down Expand Up @@ -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()

Expand All @@ -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:
Expand Down

0 comments on commit 2817103

Please sign in to comment.