Skip to content

Commit b0cf32a

Browse files
committed
Record opcode misses
1 parent a4fce82 commit b0cf32a

File tree

5 files changed

+8
-3
lines changed

5 files changed

+8
-3
lines changed

Include/cpython/pystats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ typedef struct _gc_stats {
9898

9999
typedef struct _uop_stats {
100100
uint64_t execution_count;
101+
uint64_t miss;
101102
} UOpStats;
102103

103104
#define _Py_UOP_HIST_SIZE 32

Include/internal/pycore_code.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ extern int _PyStaticCode_Init(PyCodeObject *co);
283283
do { if (_Py_stats && PyFunction_Check(callable)) _Py_stats->call_stats.eval_calls[name]++; } while (0)
284284
#define GC_STAT_ADD(gen, name, n) do { if (_Py_stats) _Py_stats->gc_stats[(gen)].name += (n); } while (0)
285285
#define OPT_STAT_INC(name) do { if (_Py_stats) _Py_stats->optimization_stats.name++; } while (0)
286-
#define UOP_EXE_INC(opname) do { if (_Py_stats) _Py_stats->optimization_stats.opcode[opname].execution_count++; } while (0)
286+
#define UOP_STAT_INC(opname, name) do { if (_Py_stats) { assert(opname < 512); _Py_stats->optimization_stats.opcode[opname].name++; } } while (0)
287287
#define OPT_UNSUPPORTED_OPCODE(opname) do { if (_Py_stats) _Py_stats->optimization_stats.unsupported_opcode[opname]++; } while (0)
288288
#define OPT_HIST(length, name) \
289289
do { \

Python/executor.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#undef DEOPT_IF
2929
#define DEOPT_IF(COND, INSTNAME) \
3030
if ((COND)) { \
31+
UOP_STAT_INC(INSTNAME, miss); \
3132
goto deoptimize; \
3233
}
3334

@@ -96,7 +97,7 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject
9697
(int)(stack_pointer - _PyFrame_Stackbase(frame)));
9798
pc++;
9899
OPT_STAT_INC(uops_executed);
99-
UOP_EXE_INC(opcode);
100+
UOP_STAT_INC(opcode, execution_count);
100101
#ifdef Py_STATS
101102
trace_uop_execution_counter++;
102103
#endif

Python/specialize.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ print_optimization_stats(FILE *out, OptimizationStats *stats)
247247
if (stats->opcode[i].execution_count) {
248248
fprintf(out, "uops[%s].execution_count : %" PRIu64 "\n", names[i], stats->opcode[i].execution_count);
249249
}
250+
if (stats->opcode[i].miss) {
251+
fprintf(out, "uops[%s].specialization.miss : %" PRIu64 "\n", names[i], stats->opcode[i].miss);
252+
}
250253
}
251254

252255
for (int i = 0; i < 256; i++) {

Tools/scripts/summarize_stats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ def iter_optimization_tables(base_stats: Stats, head_stats: Stats | None = None)
10161016
],
10171017
)
10181018
yield Section(
1019-
"Uop stats",
1019+
"Uop execution stats",
10201020
"",
10211021
[
10221022
Table(

0 commit comments

Comments
 (0)