mirror of
https://github.com/python/cpython.git
synced 2025-10-17 04:08:28 +00:00
GH-122548: Implement branch taken and not taken events for sys.monitoring (GH-122564)
This commit is contained in:
parent
7b811d0562
commit
d2f1d917e8
29 changed files with 998 additions and 583 deletions
74
Python/generated_cases.c.h
generated
74
Python/generated_cases.c.h
generated
|
@ -4618,7 +4618,6 @@
|
|||
next_instr += 2;
|
||||
INSTRUCTION_STATS(INSTRUMENTED_FOR_ITER);
|
||||
/* Skip 1 cache entry */
|
||||
_Py_CODEUNIT *target;
|
||||
_PyStackRef iter_stackref = TOP();
|
||||
PyObject *iter = PyStackRef_AsPyObjectBorrow(iter_stackref);
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
|
@ -4626,7 +4625,6 @@
|
|||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
if (next != NULL) {
|
||||
PUSH(PyStackRef_FromPyObjectSteal(next));
|
||||
target = next_instr;
|
||||
}
|
||||
else {
|
||||
if (_PyErr_Occurred(tstate)) {
|
||||
|
@ -4647,9 +4645,9 @@
|
|||
STACK_SHRINK(1);
|
||||
PyStackRef_CLOSE(iter_stackref);
|
||||
/* Skip END_FOR and POP_TOP */
|
||||
target = next_instr + oparg + 2;
|
||||
_Py_CODEUNIT *target = next_instr + oparg + 2;
|
||||
INSTRUMENTED_JUMP(this_instr, target, PY_MONITORING_EVENT_BRANCH_RIGHT);
|
||||
}
|
||||
INSTRUMENTED_JUMP(this_instr, target, PY_MONITORING_EVENT_BRANCH);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -4754,6 +4752,15 @@
|
|||
GO_TO_INSTRUCTION(LOAD_SUPER_ATTR);
|
||||
}
|
||||
|
||||
TARGET(INSTRUMENTED_NOT_TAKEN) {
|
||||
_Py_CODEUNIT* const this_instr = frame->instr_ptr = next_instr;
|
||||
(void)this_instr;
|
||||
next_instr += 1;
|
||||
INSTRUCTION_STATS(INSTRUMENTED_NOT_TAKEN);
|
||||
INSTRUMENTED_JUMP(this_instr, next_instr, PY_MONITORING_EVENT_BRANCH_LEFT);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(INSTRUMENTED_POP_JUMP_IF_FALSE) {
|
||||
_Py_CODEUNIT* const this_instr = frame->instr_ptr = next_instr;
|
||||
(void)this_instr;
|
||||
|
@ -4762,10 +4769,11 @@
|
|||
/* Skip 1 cache entry */
|
||||
_PyStackRef cond = POP();
|
||||
assert(PyStackRef_BoolCheck(cond));
|
||||
int flag = PyStackRef_IsFalse(cond);
|
||||
int offset = flag * oparg;
|
||||
RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
|
||||
INSTRUMENTED_JUMP(this_instr, next_instr + offset, PY_MONITORING_EVENT_BRANCH);
|
||||
int jump = PyStackRef_IsFalse(cond);
|
||||
RECORD_BRANCH_TAKEN(this_instr[1].cache, jump);
|
||||
if (jump) {
|
||||
INSTRUMENTED_JUMP(this_instr, next_instr + oparg, PY_MONITORING_EVENT_BRANCH_RIGHT);
|
||||
}
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -4776,17 +4784,14 @@
|
|||
INSTRUCTION_STATS(INSTRUMENTED_POP_JUMP_IF_NONE);
|
||||
/* Skip 1 cache entry */
|
||||
_PyStackRef value_stackref = POP();
|
||||
int flag = PyStackRef_IsNone(value_stackref);
|
||||
int offset;
|
||||
if (flag) {
|
||||
offset = oparg;
|
||||
int jump = PyStackRef_IsNone(value_stackref);
|
||||
RECORD_BRANCH_TAKEN(this_instr[1].cache, jump);
|
||||
if (jump) {
|
||||
INSTRUMENTED_JUMP(this_instr, next_instr + oparg, PY_MONITORING_EVENT_BRANCH_RIGHT);
|
||||
}
|
||||
else {
|
||||
PyStackRef_CLOSE(value_stackref);
|
||||
offset = 0;
|
||||
}
|
||||
RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
|
||||
INSTRUMENTED_JUMP(this_instr, next_instr + offset, PY_MONITORING_EVENT_BRANCH);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -4797,19 +4802,12 @@
|
|||
INSTRUCTION_STATS(INSTRUMENTED_POP_JUMP_IF_NOT_NONE);
|
||||
/* Skip 1 cache entry */
|
||||
_PyStackRef value_stackref = POP();
|
||||
int offset;
|
||||
int nflag = PyStackRef_IsNone(value_stackref);
|
||||
if (nflag) {
|
||||
offset = 0;
|
||||
}
|
||||
else {
|
||||
int jump = !PyStackRef_IsNone(value_stackref);
|
||||
RECORD_BRANCH_TAKEN(this_instr[1].cache, jump);
|
||||
if (jump) {
|
||||
PyStackRef_CLOSE(value_stackref);
|
||||
offset = oparg;
|
||||
INSTRUMENTED_JUMP(this_instr, next_instr + oparg, PY_MONITORING_EVENT_BRANCH_RIGHT);
|
||||
}
|
||||
#if ENABLE_SPECIALIZATION
|
||||
this_instr[1].cache = (this_instr[1].cache << 1) | !nflag;
|
||||
#endif
|
||||
INSTRUMENTED_JUMP(this_instr, next_instr + offset, PY_MONITORING_EVENT_BRANCH);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -4821,10 +4819,11 @@
|
|||
/* Skip 1 cache entry */
|
||||
_PyStackRef cond = POP();
|
||||
assert(PyStackRef_BoolCheck(cond));
|
||||
int flag = PyStackRef_IsTrue(cond);
|
||||
int offset = flag * oparg;
|
||||
RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
|
||||
INSTRUMENTED_JUMP(this_instr, next_instr + offset, PY_MONITORING_EVENT_BRANCH);
|
||||
int jump = PyStackRef_IsTrue(cond);
|
||||
RECORD_BRANCH_TAKEN(this_instr[1].cache, jump);
|
||||
if (jump) {
|
||||
INSTRUMENTED_JUMP(this_instr, next_instr + oparg, PY_MONITORING_EVENT_BRANCH_RIGHT);
|
||||
}
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -6659,6 +6658,13 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(NOT_TAKEN) {
|
||||
frame->instr_ptr = next_instr;
|
||||
next_instr += 1;
|
||||
INSTRUCTION_STATS(NOT_TAKEN);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(POP_EXCEPT) {
|
||||
frame->instr_ptr = next_instr;
|
||||
next_instr += 1;
|
||||
|
@ -6687,7 +6693,7 @@
|
|||
assert(PyStackRef_BoolCheck(cond));
|
||||
int flag = PyStackRef_IsFalse(cond);
|
||||
RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
|
||||
JUMPBY(oparg * flag);
|
||||
JUMPBY(flag ? oparg : next_instr->op.code == NOT_TAKEN);
|
||||
stack_pointer += -1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
DISPATCH();
|
||||
|
@ -6719,7 +6725,7 @@
|
|||
assert(PyStackRef_BoolCheck(cond));
|
||||
int flag = PyStackRef_IsTrue(cond);
|
||||
RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
|
||||
JUMPBY(oparg * flag);
|
||||
JUMPBY(flag ? oparg : next_instr->op.code == NOT_TAKEN);
|
||||
}
|
||||
stack_pointer += -1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
|
@ -6752,7 +6758,7 @@
|
|||
assert(PyStackRef_BoolCheck(cond));
|
||||
int flag = PyStackRef_IsFalse(cond);
|
||||
RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
|
||||
JUMPBY(oparg * flag);
|
||||
JUMPBY(flag ? oparg : next_instr->op.code == NOT_TAKEN);
|
||||
}
|
||||
stack_pointer += -1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
|
@ -6770,7 +6776,7 @@
|
|||
assert(PyStackRef_BoolCheck(cond));
|
||||
int flag = PyStackRef_IsTrue(cond);
|
||||
RECORD_BRANCH_TAKEN(this_instr[1].cache, flag);
|
||||
JUMPBY(oparg * flag);
|
||||
JUMPBY(flag ? oparg : next_instr->op.code == NOT_TAKEN);
|
||||
stack_pointer += -1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
DISPATCH();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue