mirror of
https://github.com/python/cpython.git
synced 2025-09-19 15:10:58 +00:00
Add pair counts to stats output and summary. (GH-31324)
This commit is contained in:
parent
15ee55528e
commit
0ade875ebe
2 changed files with 46 additions and 10 deletions
|
@ -174,13 +174,13 @@ print_spec_stats(FILE *out, OpcodeStats *stats)
|
||||||
{
|
{
|
||||||
/* Mark some opcodes as specializable for stats,
|
/* Mark some opcodes as specializable for stats,
|
||||||
* even though we don't specialize them yet. */
|
* even though we don't specialize them yet. */
|
||||||
fprintf(out, " opcode[%d].specializable : 1\n", FOR_ITER);
|
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_FUNCTION);
|
||||||
fprintf(out, " opcode[%d].specializable : 1\n", PRECALL_METHOD);
|
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", UNPACK_SEQUENCE);
|
||||||
for (int i = 0; i < 256; i++) {
|
for (int i = 0; i < 256; i++) {
|
||||||
if (adaptive_opcodes[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.success);
|
||||||
PRINT_STAT(i, specialization.failure);
|
PRINT_STAT(i, specialization.failure);
|
||||||
|
@ -196,6 +196,12 @@ print_spec_stats(FILE *out, OpcodeStats *stats)
|
||||||
PRIu64 "\n", i, j, val);
|
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
|
#undef PRINT_STAT
|
||||||
|
|
|
@ -6,6 +6,8 @@ import collections
|
||||||
import os.path
|
import os.path
|
||||||
import opcode
|
import opcode
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
import itertools
|
||||||
|
import argparse
|
||||||
|
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
DEFAULT_DIR = "c:\\temp\\py_stats\\"
|
DEFAULT_DIR = "c:\\temp\\py_stats\\"
|
||||||
|
@ -80,7 +82,7 @@ def gather_stats():
|
||||||
for line in fd:
|
for line in fd:
|
||||||
key, value = line.split(":")
|
key, value = line.split(":")
|
||||||
key = key.strip()
|
key = key.strip()
|
||||||
value = int(value.strip())
|
value = int(value)
|
||||||
stats[key] += value
|
stats[key] += value
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
|
@ -268,14 +270,42 @@ def emit_object_stats(stats):
|
||||||
rows.append((label, value, materialize))
|
rows.append((label, value, materialize))
|
||||||
emit_table(("", "Count:", "Ratio:"), rows)
|
emit_table(("", "Count:", "Ratio:"), rows)
|
||||||
|
|
||||||
|
def get_total(opcode_stats):
|
||||||
|
total = 0
|
||||||
|
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():
|
def main():
|
||||||
stats = gather_stats()
|
stats = gather_stats()
|
||||||
opcode_stats = extract_opcode_stats(stats)
|
opcode_stats = extract_opcode_stats(stats)
|
||||||
total = 0
|
total = get_total(opcode_stats)
|
||||||
for i, opcode_stat in enumerate(opcode_stats):
|
|
||||||
if "execution_count" in opcode_stat:
|
|
||||||
total += opcode_stat['execution_count']
|
|
||||||
emit_execution_counts(opcode_stats, total)
|
emit_execution_counts(opcode_stats, total)
|
||||||
|
emit_pair_counts(opcode_stats, total)
|
||||||
emit_specialization_stats(opcode_stats)
|
emit_specialization_stats(opcode_stats)
|
||||||
emit_specialization_overview(opcode_stats, total)
|
emit_specialization_overview(opcode_stats, total)
|
||||||
emit_call_stats(stats)
|
emit_call_stats(stats)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue