(root)/
Python-3.12.0/
Include/
internal/
pycore_instruments.h
       1  
       2  #ifndef Py_INTERNAL_INSTRUMENT_H
       3  #define Py_INTERNAL_INSTRUMENT_H
       4  
       5  
       6  #include "pycore_bitutils.h"      // _Py_popcount32
       7  #include "pycore_frame.h"
       8  
       9  #include "cpython/code.h"
      10  
      11  #ifdef __cplusplus
      12  extern "C" {
      13  #endif
      14  
      15  #define PY_MONITORING_TOOL_IDS 8
      16  
      17  /* Local events.
      18   * These require bytecode instrumentation */
      19  
      20  #define PY_MONITORING_EVENT_PY_START 0
      21  #define PY_MONITORING_EVENT_PY_RESUME 1
      22  #define PY_MONITORING_EVENT_PY_RETURN 2
      23  #define PY_MONITORING_EVENT_PY_YIELD 3
      24  #define PY_MONITORING_EVENT_CALL 4
      25  #define PY_MONITORING_EVENT_LINE 5
      26  #define PY_MONITORING_EVENT_INSTRUCTION 6
      27  #define PY_MONITORING_EVENT_JUMP 7
      28  #define PY_MONITORING_EVENT_BRANCH 8
      29  #define PY_MONITORING_EVENT_STOP_ITERATION 9
      30  
      31  #define PY_MONITORING_IS_INSTRUMENTED_EVENT(ev) \
      32      ((ev) < _PY_MONITORING_LOCAL_EVENTS)
      33  
      34  /* Other events, mainly exceptions */
      35  
      36  #define PY_MONITORING_EVENT_RAISE 10
      37  #define PY_MONITORING_EVENT_EXCEPTION_HANDLED 11
      38  #define PY_MONITORING_EVENT_PY_UNWIND 12
      39  #define PY_MONITORING_EVENT_PY_THROW 13
      40  #define PY_MONITORING_EVENT_RERAISE 14
      41  
      42  
      43  /* Ancilliary events */
      44  
      45  #define PY_MONITORING_EVENT_C_RETURN 15
      46  #define PY_MONITORING_EVENT_C_RAISE 16
      47  
      48  
      49  typedef uint32_t _PyMonitoringEventSet;
      50  
      51  /* Tool IDs */
      52  
      53  /* These are defined in PEP 669 for convenience to avoid clashes */
      54  #define PY_MONITORING_DEBUGGER_ID 0
      55  #define PY_MONITORING_COVERAGE_ID 1
      56  #define PY_MONITORING_PROFILER_ID 2
      57  #define PY_MONITORING_OPTIMIZER_ID 5
      58  
      59  /* Internal IDs used to suuport sys.setprofile() and sys.settrace() */
      60  #define PY_MONITORING_SYS_PROFILE_ID 6
      61  #define PY_MONITORING_SYS_TRACE_ID 7
      62  
      63  
      64  PyObject *_PyMonitoring_RegisterCallback(int tool_id, int event_id, PyObject *obj);
      65  
      66  int _PyMonitoring_SetEvents(int tool_id, _PyMonitoringEventSet events);
      67  
      68  extern int
      69  _Py_call_instrumentation(PyThreadState *tstate, int event,
      70      _PyInterpreterFrame *frame, _Py_CODEUNIT *instr);
      71  
      72  extern int
      73  _Py_call_instrumentation_line(PyThreadState *tstate, _PyInterpreterFrame* frame,
      74                                _Py_CODEUNIT *instr, _Py_CODEUNIT *prev);
      75  
      76  extern int
      77  _Py_call_instrumentation_instruction(
      78      PyThreadState *tstate, _PyInterpreterFrame* frame, _Py_CODEUNIT *instr);
      79  
      80  _Py_CODEUNIT *
      81  _Py_call_instrumentation_jump(
      82      PyThreadState *tstate, int event,
      83      _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, _Py_CODEUNIT *target);
      84  
      85  extern int
      86  _Py_call_instrumentation_arg(PyThreadState *tstate, int event,
      87      _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg);
      88  
      89  extern int
      90  _Py_call_instrumentation_2args(PyThreadState *tstate, int event,
      91      _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1);
      92  
      93  extern void
      94  _Py_call_instrumentation_exc2(PyThreadState *tstate, int event,
      95      _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1);
      96  
      97  extern int
      98  _Py_Instrumentation_GetLine(PyCodeObject *code, int index);
      99  
     100  extern PyObject _PyInstrumentation_MISSING;
     101  extern PyObject _PyInstrumentation_DISABLE;
     102  
     103  #ifdef __cplusplus
     104  }
     105  #endif
     106  #endif /* !Py_INTERNAL_INSTRUMENT_H */