mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-111997: C-API for signalling monitoring events (#116413)
This commit is contained in:
parent
da2cfc4cb6
commit
85af789961
20 changed files with 1442 additions and 37 deletions
|
@ -84,6 +84,7 @@
|
|||
#include "setobject.h"
|
||||
#include "methodobject.h"
|
||||
#include "moduleobject.h"
|
||||
#include "monitoring.h"
|
||||
#include "cpython/funcobject.h"
|
||||
#include "cpython/classobject.h"
|
||||
#include "fileobject.h"
|
||||
|
|
250
Include/cpython/monitoring.h
Normal file
250
Include/cpython/monitoring.h
Normal file
|
@ -0,0 +1,250 @@
|
|||
#ifndef Py_CPYTHON_MONITORING_H
|
||||
# error "this header file must not be included directly"
|
||||
#endif
|
||||
|
||||
/* Local events.
|
||||
* These require bytecode instrumentation */
|
||||
|
||||
#define PY_MONITORING_EVENT_PY_START 0
|
||||
#define PY_MONITORING_EVENT_PY_RESUME 1
|
||||
#define PY_MONITORING_EVENT_PY_RETURN 2
|
||||
#define PY_MONITORING_EVENT_PY_YIELD 3
|
||||
#define PY_MONITORING_EVENT_CALL 4
|
||||
#define PY_MONITORING_EVENT_LINE 5
|
||||
#define PY_MONITORING_EVENT_INSTRUCTION 6
|
||||
#define PY_MONITORING_EVENT_JUMP 7
|
||||
#define PY_MONITORING_EVENT_BRANCH 8
|
||||
#define PY_MONITORING_EVENT_STOP_ITERATION 9
|
||||
|
||||
#define PY_MONITORING_IS_INSTRUMENTED_EVENT(ev) \
|
||||
((ev) < _PY_MONITORING_LOCAL_EVENTS)
|
||||
|
||||
/* Other events, mainly exceptions */
|
||||
|
||||
#define PY_MONITORING_EVENT_RAISE 10
|
||||
#define PY_MONITORING_EVENT_EXCEPTION_HANDLED 11
|
||||
#define PY_MONITORING_EVENT_PY_UNWIND 12
|
||||
#define PY_MONITORING_EVENT_PY_THROW 13
|
||||
#define PY_MONITORING_EVENT_RERAISE 14
|
||||
|
||||
|
||||
/* Ancillary events */
|
||||
|
||||
#define PY_MONITORING_EVENT_C_RETURN 15
|
||||
#define PY_MONITORING_EVENT_C_RAISE 16
|
||||
|
||||
|
||||
typedef struct _PyMonitoringState {
|
||||
uint8_t active;
|
||||
uint8_t opaque;
|
||||
} PyMonitoringState;
|
||||
|
||||
|
||||
PyAPI_FUNC(int)
|
||||
PyMonitoring_EnterScope(PyMonitoringState *state_array, uint64_t *version,
|
||||
const uint8_t *event_types, Py_ssize_t length);
|
||||
|
||||
PyAPI_FUNC(int)
|
||||
PyMonitoring_ExitScope(void);
|
||||
|
||||
|
||||
PyAPI_FUNC(int)
|
||||
_PyMonitoring_FirePyStartEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset);
|
||||
|
||||
PyAPI_FUNC(int)
|
||||
_PyMonitoring_FirePyResumeEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset);
|
||||
|
||||
PyAPI_FUNC(int)
|
||||
_PyMonitoring_FirePyReturnEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
|
||||
PyObject *retval);
|
||||
|
||||
PyAPI_FUNC(int)
|
||||
_PyMonitoring_FirePyYieldEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
|
||||
PyObject *retval);
|
||||
|
||||
PyAPI_FUNC(int)
|
||||
_PyMonitoring_FireCallEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
|
||||
PyObject* callable, PyObject *arg0);
|
||||
|
||||
PyAPI_FUNC(int)
|
||||
_PyMonitoring_FireLineEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
|
||||
int lineno);
|
||||
|
||||
PyAPI_FUNC(int)
|
||||
_PyMonitoring_FireJumpEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
|
||||
PyObject *target_offset);
|
||||
|
||||
PyAPI_FUNC(int)
|
||||
_PyMonitoring_FireBranchEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
|
||||
PyObject *target_offset);
|
||||
|
||||
PyAPI_FUNC(int)
|
||||
_PyMonitoring_FireCReturnEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
|
||||
PyObject *retval);
|
||||
|
||||
PyAPI_FUNC(int)
|
||||
_PyMonitoring_FirePyThrowEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset);
|
||||
|
||||
PyAPI_FUNC(int)
|
||||
_PyMonitoring_FireRaiseEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset);
|
||||
|
||||
PyAPI_FUNC(int)
|
||||
_PyMonitoring_FireReraiseEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset);
|
||||
|
||||
PyAPI_FUNC(int)
|
||||
_PyMonitoring_FireExceptionHandledEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset);
|
||||
|
||||
PyAPI_FUNC(int)
|
||||
_PyMonitoring_FireCRaiseEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset);
|
||||
|
||||
PyAPI_FUNC(int)
|
||||
_PyMonitoring_FirePyUnwindEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset);
|
||||
|
||||
PyAPI_FUNC(int)
|
||||
_PyMonitoring_FireStopIterationEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset);
|
||||
|
||||
|
||||
#define _PYMONITORING_IF_ACTIVE(STATE, X) \
|
||||
if ((STATE)->active) { \
|
||||
return (X); \
|
||||
} \
|
||||
else { \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
static inline int
|
||||
PyMonitoring_FirePyStartEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset)
|
||||
{
|
||||
_PYMONITORING_IF_ACTIVE(
|
||||
state,
|
||||
_PyMonitoring_FirePyStartEvent(state, codelike, offset));
|
||||
}
|
||||
|
||||
static inline int
|
||||
PyMonitoring_FirePyResumeEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset)
|
||||
{
|
||||
_PYMONITORING_IF_ACTIVE(
|
||||
state,
|
||||
_PyMonitoring_FirePyResumeEvent(state, codelike, offset));
|
||||
}
|
||||
|
||||
static inline int
|
||||
PyMonitoring_FirePyReturnEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
|
||||
PyObject *retval)
|
||||
{
|
||||
_PYMONITORING_IF_ACTIVE(
|
||||
state,
|
||||
_PyMonitoring_FirePyReturnEvent(state, codelike, offset, retval));
|
||||
}
|
||||
|
||||
static inline int
|
||||
PyMonitoring_FirePyYieldEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
|
||||
PyObject *retval)
|
||||
{
|
||||
_PYMONITORING_IF_ACTIVE(
|
||||
state,
|
||||
_PyMonitoring_FirePyYieldEvent(state, codelike, offset, retval));
|
||||
}
|
||||
|
||||
static inline int
|
||||
PyMonitoring_FireCallEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
|
||||
PyObject* callable, PyObject *arg0)
|
||||
{
|
||||
_PYMONITORING_IF_ACTIVE(
|
||||
state,
|
||||
_PyMonitoring_FireCallEvent(state, codelike, offset, callable, arg0));
|
||||
}
|
||||
|
||||
static inline int
|
||||
PyMonitoring_FireLineEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
|
||||
int lineno)
|
||||
{
|
||||
_PYMONITORING_IF_ACTIVE(
|
||||
state,
|
||||
_PyMonitoring_FireLineEvent(state, codelike, offset, lineno));
|
||||
}
|
||||
|
||||
static inline int
|
||||
PyMonitoring_FireJumpEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
|
||||
PyObject *target_offset)
|
||||
{
|
||||
_PYMONITORING_IF_ACTIVE(
|
||||
state,
|
||||
_PyMonitoring_FireJumpEvent(state, codelike, offset, target_offset));
|
||||
}
|
||||
|
||||
static inline int
|
||||
PyMonitoring_FireBranchEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
|
||||
PyObject *target_offset)
|
||||
{
|
||||
_PYMONITORING_IF_ACTIVE(
|
||||
state,
|
||||
_PyMonitoring_FireBranchEvent(state, codelike, offset, target_offset));
|
||||
}
|
||||
|
||||
static inline int
|
||||
PyMonitoring_FireCReturnEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
|
||||
PyObject *retval)
|
||||
{
|
||||
_PYMONITORING_IF_ACTIVE(
|
||||
state,
|
||||
_PyMonitoring_FireCReturnEvent(state, codelike, offset, retval));
|
||||
}
|
||||
|
||||
static inline int
|
||||
PyMonitoring_FirePyThrowEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset)
|
||||
{
|
||||
_PYMONITORING_IF_ACTIVE(
|
||||
state,
|
||||
_PyMonitoring_FirePyThrowEvent(state, codelike, offset));
|
||||
}
|
||||
|
||||
static inline int
|
||||
PyMonitoring_FireRaiseEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset)
|
||||
{
|
||||
_PYMONITORING_IF_ACTIVE(
|
||||
state,
|
||||
_PyMonitoring_FireRaiseEvent(state, codelike, offset));
|
||||
}
|
||||
|
||||
static inline int
|
||||
PyMonitoring_FireReraiseEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset)
|
||||
{
|
||||
_PYMONITORING_IF_ACTIVE(
|
||||
state,
|
||||
_PyMonitoring_FireReraiseEvent(state, codelike, offset));
|
||||
}
|
||||
|
||||
static inline int
|
||||
PyMonitoring_FireExceptionHandledEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset)
|
||||
{
|
||||
_PYMONITORING_IF_ACTIVE(
|
||||
state,
|
||||
_PyMonitoring_FireExceptionHandledEvent(state, codelike, offset));
|
||||
}
|
||||
|
||||
static inline int
|
||||
PyMonitoring_FireCRaiseEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset)
|
||||
{
|
||||
_PYMONITORING_IF_ACTIVE(
|
||||
state,
|
||||
_PyMonitoring_FireCRaiseEvent(state, codelike, offset));
|
||||
}
|
||||
|
||||
static inline int
|
||||
PyMonitoring_FirePyUnwindEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset)
|
||||
{
|
||||
_PYMONITORING_IF_ACTIVE(
|
||||
state,
|
||||
_PyMonitoring_FirePyUnwindEvent(state, codelike, offset));
|
||||
}
|
||||
|
||||
static inline int
|
||||
PyMonitoring_FireStopIterationEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset)
|
||||
{
|
||||
_PYMONITORING_IF_ACTIVE(
|
||||
state,
|
||||
_PyMonitoring_FireStopIterationEvent(state, codelike, offset));
|
||||
}
|
||||
|
||||
#undef _PYMONITORING_IF_ACTIVE
|
|
@ -13,38 +13,6 @@ extern "C" {
|
|||
|
||||
#define PY_MONITORING_TOOL_IDS 8
|
||||
|
||||
/* Local events.
|
||||
* These require bytecode instrumentation */
|
||||
|
||||
#define PY_MONITORING_EVENT_PY_START 0
|
||||
#define PY_MONITORING_EVENT_PY_RESUME 1
|
||||
#define PY_MONITORING_EVENT_PY_RETURN 2
|
||||
#define PY_MONITORING_EVENT_PY_YIELD 3
|
||||
#define PY_MONITORING_EVENT_CALL 4
|
||||
#define PY_MONITORING_EVENT_LINE 5
|
||||
#define PY_MONITORING_EVENT_INSTRUCTION 6
|
||||
#define PY_MONITORING_EVENT_JUMP 7
|
||||
#define PY_MONITORING_EVENT_BRANCH 8
|
||||
#define PY_MONITORING_EVENT_STOP_ITERATION 9
|
||||
|
||||
#define PY_MONITORING_IS_INSTRUMENTED_EVENT(ev) \
|
||||
((ev) < _PY_MONITORING_LOCAL_EVENTS)
|
||||
|
||||
/* Other events, mainly exceptions */
|
||||
|
||||
#define PY_MONITORING_EVENT_RAISE 10
|
||||
#define PY_MONITORING_EVENT_EXCEPTION_HANDLED 11
|
||||
#define PY_MONITORING_EVENT_PY_UNWIND 12
|
||||
#define PY_MONITORING_EVENT_PY_THROW 13
|
||||
#define PY_MONITORING_EVENT_RERAISE 14
|
||||
|
||||
|
||||
/* Ancillary events */
|
||||
|
||||
#define PY_MONITORING_EVENT_C_RETURN 15
|
||||
#define PY_MONITORING_EVENT_C_RAISE 16
|
||||
|
||||
|
||||
typedef uint32_t _PyMonitoringEventSet;
|
||||
|
||||
/* Tool IDs */
|
||||
|
|
18
Include/monitoring.h
Normal file
18
Include/monitoring.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#ifndef Py_MONITORING_H
|
||||
#define Py_MONITORING_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// There is currently no limited API for monitoring
|
||||
|
||||
#ifndef Py_LIMITED_API
|
||||
# define Py_CPYTHON_MONITORING_H
|
||||
# include "cpython/monitoring.h"
|
||||
# undef Py_CPYTHON_MONITORING_H
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* !Py_MONITORING_H */
|
Loading…
Add table
Add a link
Reference in a new issue