8000 Add BRANCH_LEFT and BRANCH_RIGHT events to sys.monitoring for coverag… · python/cpython@c5a4b17 · GitHub
[go: up one dir, main page]

Skip to content

Commit c5a4b17

Browse files
committed
Add BRANCH_LEFT and BRANCH_RIGHT events to sys.monitoring for coverage tools
1 parent 5a23994 commit c5a4b17

22 files changed

+946
-572
lines changed

Include/cpython/code.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ extern "C" {
1111
/* Total tool ids available */
1212
#define _PY_MONITORING_TOOL_IDS 8
1313
/* Count of all local monitoring events */
14-
#define _PY_MONITORING_LOCAL_EVENTS 10
14+
#define _PY_MONITORING_LOCAL_EVENTS 11
1515
/* Count of all "real" monitoring events (not derived from other events) */
16-
#define _PY_MONITORING_UNGROUPED_EVENTS 15
16+
#define _PY_MONITORING_UNGROUPED_EVENTS 16
1717
/* Count of all monitoring events */
18-
#define _PY_MONITORING_EVENTS 17
18+
#define _PY_MONITORING_EVENTS 19
1919

2020
/* Tables of which tools are active for each monitored event. */
2121
typedef struct _Py_LocalMonitors {

Include/cpython/monitoring.h

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,27 @@
1313
#define PY_MONITORING_EVENT_LINE 5
1414
#define PY_MONITORING_EVENT_INSTRUCTION 6
1515
#define PY_MONITORING_EVENT_JUMP 7
16-
#define PY_MONITORING_EVENT_BRANCH 8
17-
#define PY_MONITORING_EVENT_STOP_ITERATION 9
16+
#define PY_MONITORING_EVENT_BRANCH_LEFT 8
17+
#define PY_MONITORING_EVENT_BRANCH_RIGHT 9
18+
#define PY_MONITORING_EVENT_STOP_ITERATION 10
1819

1920
#define PY_MONITORING_IS_INSTRUMENTED_EVENT(ev) \
2021
((ev) < _PY_MONITORING_LOCAL_EVENTS)
2122

2223
/* Other events, mainly exceptions */
2324

24-
#define PY_MONITORING_EVENT_RAISE 10
25-
#define PY_MONITORING_EVENT_EXCEPTION_HANDLED 11
26-
#define PY_MONITORING_EVENT_PY_UNWIND 12
27-
#define PY_MONITORING_EVENT_PY_THROW 13
28-
#define PY_MONITORING_EVENT_RERAISE 14
25+
#define PY_MONITORING_EVENT_RAISE 11
26+
#define PY_MONITORING_EVENT_EXCEPTION_HANDLED 12
27+
#define PY_MONITORING_EVENT_PY_UNWIND 13
28+
#define PY_MONITORING_EVENT_PY_THROW 14
29+
#define PY_MONITORING_EVENT_RERAISE 15
2930

3031

3132
/* Ancillary events */
3233

33-
#define PY_MONITORING_EVENT_C_RETURN 15
34-
#define PY_MONITORING_EVENT_C_RAISE 16
34+
#define PY_MONITORING_EVENT_C_RETURN 16
35+
#define PY_MONITORING_EVENT_C_RAISE 17
36+
#define PY_MONITORING_EVENT_BRANCH 18
3537

3638

3739
typedef struct _PyMonitoringState {
@@ -74,10 +76,18 @@ PyAPI_FUNC(int)
7476
_PyMonitoring_FireJumpEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
7577
PyObject *target_offset);
7678

77-
PyAPI_FUNC(int)
79+
Py_DEPRECATED(3.14) PyAPI_FUNC(int)
7880
_PyMonitoring_FireBranchEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
7981
PyObject *target_offset);
8082

83+
PyAPI_FUNC(int)
84+
_PyMonitoring_FireBranchRightEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
85+
PyObject *target_offset);
86+
87+
PyAPI_FUNC(int)
88+
_PyMonitoring_FireBranchLeftEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
89+
PyObject *target_offset);
90+
8191
PyAPI_FUNC(int)
8292
_PyMonitoring_FireCReturnEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
8393
PyObject *retval);
@@ -174,12 +184,21 @@ PyMonitoring_FireJumpEvent(PyMonitoringState *state, PyObject *codelike, int32_t
174184
}
175185

176186
static inline int
177-
PyMonitoring_FireBranchEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
187+
PyMonitoring_FireBranchRightEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
188+
PyObject *target_offset)
189+
{
190+
_PYMONITORING_IF_ACTIVE(
191+
state,
192+
_PyMonitoring_FireBranchRightEvent(state, codelike, offset, target_offset));
193+
}
194+
195+
static inline int
196+
PyMonitoring_FireBranchLeftEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
178197
PyObject *target_offset)
179198
{
180199
_PYMONITORING_IF_ACTIVE(
181200
state,
182-
_PyMonitoring_FireBranchEvent(state, codelike, offset, target_offset));
201+
_PyMonitoring_FireBranchLeftEvent(state, codelike, offset, target_offset));
183202
}
184203

185204
static inline int

Include/internal/pycore_code.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,8 @@ extern _Py_CODEUNIT _Py_GetBaseCodeUnit(PyCodeObject *code, int offset);
603603

604604
extern int _PyInstruction_GetLength(PyCodeObject *code, int offset);
605605

606+
extern PyObject *_PyInstrumentation_BranchesIterator(PyCodeObject *code);
607+
606608
struct _PyCode8 _PyCode_DEF(8);
607609

608610
PyAPI_DATA(const struct _PyCode8) _Py_InitCleanup;

Include/internal/pycore_magic_number.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ Known values:
262262
Python 3.14a1 3607 (Add pseudo instructions JUMP_IF_TRUE/FALSE)
263263
Python 3.14a1 3608 (Add support for slices)
264264
Python 3.14a2 3609 (Add LOAD_SMALL_INT and LOAD_CONST_IMMORTAL instructions, remove RETURN_CONST)
265+
Python 3.14a3 3610 (Add NOT_TAKEN instruction)
265266
266267
Python 3.15 will start with 3650
267268
@@ -274,7 +275,7 @@ PC/launcher.c must also be updated.
274275
275276
*/
276277

277-
#define PYC_MAGIC_NUMBER 3609
278+
#define PYC_MAGIC_NUMBER 3610
278279
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
279280
(little-endian) and then appending b'\r\n'. */
280281
#define PYC_MAGIC_NUMBER_TOKEN \

Include/internal/pycore_opcode_metadata.h

Lines changed: 23 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_ids.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0