|
6 | 6 | import os.path
|
7 | 7 | import opcode
|
8 | 8 | from datetime import date
|
| 9 | +import itertools |
| 10 | +import argparse |
9 | 11 |
|
10 | 12 | if os.name == "nt":
|
11 | 13 | DEFAULT_DIR = "c:\\temp\\py_stats\\"
|
@@ -80,7 +82,7 @@ def gather_stats():
|
80 | 82 | for line in fd:
|
81 | 83 | key, value = line.split(":")
|
82 | 84 | key = key.strip()
|
83 |
| - value = int(value.strip()) |
| 85 | + value = int(value) |
84 | 86 | stats[key] += value
|
85 | 87 | return stats
|
86 | 88 |
|
@@ -268,14 +270,42 @@ def emit_object_stats(stats):
|
268 | 270 | rows.append((label, value, materialize))
|
269 | 271 | emit_table(("", "Count:", "Ratio:"), rows)
|
270 | 272 |
|
271 |
| -def main(): |
272 |
| - stats = gather_stats() |
273 |
| - opcode_stats = extract_opcode_stats(stats) |
| 273 | +def get_total(opcode_stats): |
274 | 274 | total = 0
|
275 |
| - for i, opcode_stat in enumerate(opcode_stats): |
| 275 | + for opcode_stat in opcode_stats: |
276 | 276 | if "execution_count" in opcode_stat:
|
277 | 277 | total += opcode_stat['execution_count']
|
| 278 | + return total |
| 279 | + |
| 280 | +def emit_pair_counts(opcode_stats, total): |
| 281 | + with Section("Pair counts", summary="Pair counts for top 100 pairs"): |
| 282 | + pair_counts = [] |
| 283 | + for i, opcode_stat in enumerate(opcode_stats): |
| 284 | + if i == 0: |
| 285 | + continue |
| 286 | + for key, value in opcode_stat.items(): |
| 287 | + if key.startswith("pair_count"): |
| 288 | + x, _, _ = key[11:].partition("]") |
| 289 | + if value: |
| 290 | + pair_counts.append((value, (i, int(x)))) |
| 291 | + pair_counts.sort(reverse=True) |
| 292 | + cumulative = 0 |
| 293 | + rows = [] |
| 294 | + for (count, pair) in itertools.islice(pair_counts, 100): |
| 295 | + i, j = pair |
| 296 | + cumulative += count |
| 297 | + rows.append((opname[i] + " " + opname[j], count, f"{100*count/total:0.1f}%", |
| 298 | + f"{100*cumulative/total:0.1f}%")) |
| 299 | + emit_table(("Pair", "Count:", "Self:", "Cumulative:"), |
| 300 | + rows |
| 301 | + ) |
| 302 | + |
| 303 | +def main(): |
| 304 | + stats = gather_stats() |
| 305 | + opcode_stats = extract_opcode_stats(stats) |
| 306 | + total = get_total(opcode_stats) |
278 | 307 | emit_execution_counts(opcode_stats, total)
|
| 308 | + emit_pair_counts(opcode_stats, total) |
279 | 309 | emit_specialization_stats(opcode_stats)
|
280 | 310 | emit_specialization_overview(opcode_stats, total)
|
281 | 311 | emit_call_stats(stats)
|
|
0 commit comments