Skip to content

Commit 61a0404

Browse files
committed
Draw arrow from instruction to target. Add inctruction counts
1 parent f43d423 commit 61a0404

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

Include/internal/pycore_optimizer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ typedef struct {
6060
};
6161
uint64_t operand0; // A cache entry
6262
uint64_t operand1;
63+
#ifdef Py_STATS
64+
uint64_t execution_count;
65+
#endif
6366
} _PyUOpInstruction;
6467

6568
typedef struct {

Python/ceval.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10981098
UOP_PAIR_INC(uopcode, lastuop);
10991099
#ifdef Py_STATS
11001100
trace_uop_execution_counter++;
1101+
((_PyUOpInstruction *)next_uop)[-1].execution_count++;
11011102
#endif
11021103

11031104
switch (uopcode) {

Python/optimizer.c

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,9 @@ add_to_trace(
464464
trace[trace_length].target = target;
465465
trace[trace_length].oparg = oparg;
466466
trace[trace_length].operand0 = operand;
467+
#ifdef Py_STATS
468+
trace[trace_length].execution_count = 0;
469+
#endif
467470
return trace_length + 1;
468471
}
469472

@@ -973,6 +976,9 @@ static void make_exit(_PyUOpInstruction *inst, int opcode, int target)
973976
inst->operand0 = 0;
974977
inst->format = UOP_FORMAT_TARGET;
975978
inst->target = target;
979+
#ifdef Py_STATS
980+
inst->execution_count = 0;
981+
#endif
976982
}
977983

978984
/* Convert implicit exits, errors and deopts
@@ -1748,31 +1754,28 @@ dump_executor(_PyExecutorObject *executor, FILE *out)
17481754
int line = find_line_number(code, executor);
17491755
fprintf(out, " <tr><td border=\"1\" >line: %d</td></tr>\n", line);
17501756
}
1751-
for (int i = 0; i < executor->code_size; i++) {
1752-
_PyUOpInstruction *inst = &executor->trace[i];
1757+
for (uint32_t i = 0; i < executor->code_size; i++) {
1758+
_PyUOpInstruction const *inst = &executor->trace[i];
17531759
const char *opname = _PyOpcode_uop_name[inst->opcode];
1760+
#ifdef Py_STATS
1761+
fprintf(out, " <tr><td port=\"i%d\" border=\"1\" >%s -- %" PRIu64 "</td></tr>\n", i, opname, inst->execution_count);
1762+
#else
17541763
fprintf(out, " <tr><td port=\"i%d\" border=\"1\" >%s</td></tr>\n", i, opname);
1764+
#endif
17551765
}
1756-
for (int i = 0; i < executor->exit_count; i++) {
1757-
_PyExitData *exit = &executor->exits[i];
1758-
int temp = exit->temperature.value_and_backoff >> 4;
1759-
fprintf(out, " <tr><td port=\"e%d\" border=\"1\" >EXIT: temp %d</td></tr>\n", i, temp);
1760-
}
1761-
17621766
fprintf(out, " label = </table>>\n");
17631767
fprintf(out, "]\n\n");
1764-
for (int i = 0; i < executor->code_size; i++) {
1765-
_PyUOpInstruction *inst = &executor->trace[i];
1766-
if (inst->format == UOP_FORMAT_JUMP) {
1767-
int exit = inst->jump_target;
1768-
fprintf(out, "executor_%p:i%d -> executor_%p:i%d\n", executor, i, executor, exit);
1769-
}
1770-
}
1771-
1772-
for (int i = 0; i < executor->exit_count; i++) {
1773-
_PyExitData *exit = &executor->exits[i];
1774-
if (exit->executor != NULL) {
1775-
fprintf(out, "executor_%p:e%d -> executor_%p:start\n", executor, i, exit->executor);
1768+
for (uint32_t i = 0; i < executor->code_size; i++) {
1769+
_PyUOpInstruction const *inst = &executor->trace[i];
1770+
uint16_t flags = _PyUop_Flags[inst->opcode];
1771+
if (flags & HAS_EXIT_FLAG) {
1772+
assert(inst->format == UOP_FORMAT_JUMP);
1773+
_PyUOpInstruction const *exit_inst = &executor->trace[inst->jump_target];
1774+
assert(exit_inst->opcode == _EXIT_TRACE);
1775+
_PyExitData *exit = (_PyExitData *)exit_inst->operand0;
1776+
if (exit->executor != NULL) {
1777+
fprintf(out, "executor_%p:i%d -> executor_%p:start\n", executor, i, exit->executor);
1778+
}
17761779
}
17771780
}
17781781
}

0 commit comments

Comments
 (0)