Skip to content

Commit d5618d7

Browse files
committed
Add histogram of the trace sizes
1 parent 3122c1d commit d5618d7

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

Include/cpython/pystats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ typedef struct _optimization_stats {
148148
uint64_t jit_data_size;
149149
uint64_t jit_padding_size;
150150
uint64_t jit_freed_memory_size;
151+
uint64_t trace_total_memory_hist[_Py_UOP_HIST_SIZE];
151152
} OptimizationStats;
152153

153154
typedef struct _rare_event_stats {

Python/jit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz
517517
OPT_STAT_ADD(jit_trampoline_size, state.trampolines.size);
518518
OPT_STAT_ADD(jit_data_size, data_size);
519519
OPT_STAT_ADD(jit_padding_size, padding);
520+
OPT_HIST(total_size, trace_total_memory_hist);
520521
// Update the offsets of each instruction:
521522
for (size_t i = 0; i < length; i++) {
522523
state.instruction_starts[i] += (uintptr_t)memory;

Python/specialize.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ print_optimization_stats(FILE *out, OptimizationStats *stats)
315315
fprintf(out, "JIT data size: %" PRIu64 "\n", stats->jit_data_size);
316316
fprintf(out, "JIT padding size: %" PRIu64 "\n", stats->jit_padding_size);
317317
fprintf(out, "JIT freed memory size: %" PRIu64 "\n", stats->jit_freed_memory_size);
318+
319+
print_histogram(out, "Trace total memory size", stats->trace_total_memory_hist);
318320
}
319321
#endif
320322

Tools/scripts/summarize_stats.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,10 +1208,16 @@ def calc_jit_memory_table(stats: Stats) -> Rows:
12081208
for label, (value, den) in jit_memory_stats.items()
12091209
]
12101210

1211-
def calc_histogram_table(key: str, den: str) -> RowCalculator:
1211+
def calc_histogram_table(key: str, den: str | None = None) -> RowCalculator:
12121212
def calc(stats: Stats) -> Rows:
12131213
histogram = stats.get_histogram(key)
1214-
denominator = stats.get(den)
1214+
1215+
if den:
1216+
denominator = stats.get(den)
1217+
else:
1218+
denominator = 0
1219+
for _, v in histogram:
1220+
denominator += v
12151221

12161222
rows: Rows = []
12171223
last_non_zero = 0
@@ -1272,6 +1278,17 @@ def iter_optimization_tables(base_stats: Stats, head_stats: Stats | None = None)
12721278
)
12731279
],
12741280
)
1281+
yield Section(
1282+
"JIT trace total memory histogram",
1283+
"",
1284+
[
1285+
Table(
1286+
("Size (bytes)", "Count", "Ratio:"),
1287+
calc_histogram_table("Trace total memory size"),
1288+
JoinMode.CHANGE_NO_SORT,
1289+
)
1290+
],
1291+
)
12751292
for name, den in [
12761293
("Trace length", "Optimization traces created"),
12771294
("Optimized trace length", "Optimization traces created"),

0 commit comments

Comments
 (0)