Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ print_spec_stats(FILE *out, OpcodeStats *stats)
{
/* Mark some opcodes as specializable for stats,
* even though we don't specialize them yet. */
fprintf(out, " opcode[%d].specializable : 1\n", FOR_ITER);
fprintf(out, " opcode[%d].specializable : 1\n", PRECALL_FUNCTION);
fprintf(out, " opcode[%d].specializable : 1\n", PRECALL_METHOD);
fprintf(out, " opcode[%d].specializable : 1\n", UNPACK_SEQUENCE);
fprintf(out, "opcode[%d].specializable : 1\n", FOR_ITER);
fprintf(out, "opcode[%d].specializable : 1\n", PRECALL_FUNCTION);
fprintf(out, "opcode[%d].specializable : 1\n", PRECALL_METHOD);
fprintf(out, "opcode[%d].specializable : 1\n", UNPACK_SEQUENCE);
for (int i = 0; i < 256; i++) {
if (adaptive_opcodes[i]) {
fprintf(out, " opcode[%d].specializable : 1\n", i);
fprintf(out, "opcode[%d].specializable : 1\n", i);
}
PRINT_STAT(i, specialization.success);
PRINT_STAT(i, specialization.failure);
Expand All @@ -196,6 +196,12 @@ print_spec_stats(FILE *out, OpcodeStats *stats)
PRIu64 "\n", i, j, val);
}
}
for(int j = 0; j < 256; j++) {
if (stats[i].pair_count[j]) {
fprintf(out, "opcode[%d].pair_count[%d] : %" PRIu64 "\n",
i, j, stats[i].pair_count[j]);
}
}
}
}
#undef PRINT_STAT
Expand Down
40 changes: 35 additions & 5 deletions Tools/scripts/summarize_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import os.path
import opcode
from datetime import date
import itertools
import argparse

if os.name == "nt":
DEFAULT_DIR = "c:\\temp\\py_stats\\"
Expand Down Expand Up @@ -80,7 +82,7 @@ def gather_stats():
for line in fd:
key, value = line.split(":")
key = key.strip()
value = int(value.strip())
value = int(value)
stats[key] += value
return stats

Expand Down Expand Up @@ -268,14 +270,42 @@ def emit_object_stats(stats):
rows.append((label, value, materialize))
emit_table(("", "Count:", "Ratio:"), rows)

def main():
stats = gather_stats()
opcode_stats = extract_opcode_stats(stats)
def get_total(opcode_stats):
total = 0
for i, opcode_stat in enumerate(opcode_stats):
for opcode_stat in opcode_stats:
if "execution_count" in opcode_stat:
total += opcode_stat['execution_count']
return total

def emit_pair_counts(opcode_stats, total):
with Section("Pair counts", summary="Pair counts for top 100 pairs"):
pair_counts = []
for i, opcode_stat in enumerate(opcode_stats):
if i == 0:
continue
for key, value in opcode_stat.items():
if key.startswith("pair_count"):
x, _, _ = key[11:].partition("]")
if value:
pair_counts.append((value, (i, int(x))))
pair_counts.sort(reverse=True)
cumulative = 0
rows = []
for (count, pair) in itertools.islice(pair_counts, 100):
i, j = pair
cumulative += count
rows.append((opname[i] + " " + opname[j], count, f"{100*count/total:0.1f}%",
f"{100*cumulative/total:0.1f}%"))
emit_table(("Pair", "Count:", "Self:", "Cumulative:"),
rows
)

def main():
stats = gather_stats()
opcode_stats = extract_opcode_stats(stats)
total = get_total(opcode_stats)
emit_execution_counts(opcode_stats, total)
emit_pair_counts(opcode_stats, total)
emit_specialization_stats(opcode_stats)
emit_specialization_overview(opcode_stats, total)
emit_call_stats(stats)
Expand Down