Skip to content

Commit

Permalink
Fix stats
Browse files Browse the repository at this point in the history
  • Loading branch information
markshannon committed Oct 23, 2023
1 parent c84b039 commit 098e687
Show file tree
Hide file tree
Showing 2 changed files with 12 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
17 changes: 11 additions & 6 deletions Tools/scripts/summarize_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ def kind_to_text(kind, defines, opname):

def categorized_counts(opcode_stats, specialized_instructions):
basic = 0
specialized = 0
specialized_hits = 0
specialized_misses = 0
not_specialized = 0
for name, opcode_stat in opcode_stats.items():
if "execution_count" not in opcode_stat:
Expand All @@ -312,11 +313,11 @@ def categorized_counts(opcode_stats, specialized_instructions):
not_specialized += count
elif name in specialized_instructions:
miss = opcode_stat.get("specialization.miss", 0)
not_specialized += miss
specialized += count - miss
specialized_misses += miss
specialized_hits += count - miss
else:
basic += count
return basic, not_specialized, specialized
return basic, not_specialized, specialized_hits, specialized_misses


def print_title(name, level=2):
Expand Down Expand Up @@ -484,13 +485,14 @@ def emit_comparative_specialization_stats(
def calculate_specialization_effectiveness(
opcode_stats, total, specialized_instructions
):
basic, not_specialized, specialized = categorized_counts(
basic, not_specialized, hits, misses = categorized_counts(
opcode_stats, specialized_instructions
)
return [
("Basic", basic, format_ratio(basic, total)),
("Not specialized", not_specialized, format_ratio(not_specialized, total)),
("Specialized", specialized, format_ratio(specialized, total)),
("Specialized hits", hits, format_ratio(specialized, total)),
("Specialized misses", misses, format_ratio(specialized, total)),
]


Expand All @@ -510,6 +512,9 @@ def emit_specialization_overview(opcode_stats, total, specialized_instructions):
# Avoid double counting misses
if title == "Misses" and "specializable" in opcode_stat:
continue
# Deferred stats for RESUME are meaningless
if title == "Deferred" and name == RESUME:
continue
value = opcode_stat.get(field, 0)
counts.append((value, name))
total += value
Expand Down

0 comments on commit 098e687

Please sign in to comment.