Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/python3.14/internal/pycore_instruments.h
1 #ifndef Py_INTERNAL_INSTRUMENT_H 2 #define Py_INTERNAL_INSTRUMENT_H 3 4 #ifndef Py_BUILD_CORE 5 # error "this header requires Py_BUILD_CORE define" 6 #endif 7 8 #include "pycore_structs.h" // _Py_CODEUNIT 9 #include "pycore_typedefs.h" // _PyInterpreterFrame 10 11 #ifdef __cplusplus 12 extern "C" { 13 #endif 14 15 typedef uint32_t _PyMonitoringEventSet; 16 17 /* Tool IDs */ 18 19 /* These are defined in PEP 669 for convenience to avoid clashes */ 20 #define PY_MONITORING_DEBUGGER_ID 0 21 #define PY_MONITORING_COVERAGE_ID 1 22 #define PY_MONITORING_PROFILER_ID 2 23 #define PY_MONITORING_OPTIMIZER_ID 5 24 25 /* Internal IDs used to support sys.setprofile() and sys.settrace() */ 26 #define PY_MONITORING_SYS_PROFILE_ID 6 27 #define PY_MONITORING_SYS_TRACE_ID 7 28 29 30 PyObject *_PyMonitoring_RegisterCallback(int tool_id, int event_id, PyObject *obj); 31 32 int _PyMonitoring_SetEvents(int tool_id, _PyMonitoringEventSet events); 33 int _PyMonitoring_SetLocalEvents(PyCodeObject *code, int tool_id, _PyMonitoringEventSet events); 34 int _PyMonitoring_GetLocalEvents(PyCodeObject *code, int tool_id, _PyMonitoringEventSet *events); 35 36 extern int 37 _Py_call_instrumentation(PyThreadState *tstate, int event, 38 _PyInterpreterFrame *frame, _Py_CODEUNIT *instr); 39 40 extern int 41 _Py_call_instrumentation_line(PyThreadState *tstate, _PyInterpreterFrame* frame, 42 _Py_CODEUNIT *instr, _Py_CODEUNIT *prev); 43 44 extern int 45 _Py_call_instrumentation_instruction( 46 PyThreadState *tstate, _PyInterpreterFrame* frame, _Py_CODEUNIT *instr); 47 48 _Py_CODEUNIT * 49 _Py_call_instrumentation_jump( 50 _Py_CODEUNIT *instr, PyThreadState *tstate, int event, 51 _PyInterpreterFrame *frame, _Py_CODEUNIT *src, _Py_CODEUNIT *dest); 52 53 extern int 54 _Py_call_instrumentation_arg(PyThreadState *tstate, int event, 55 _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg); 56 57 extern int 58 _Py_call_instrumentation_2args(PyThreadState *tstate, int event, 59 _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1); 60 61 extern void 62 _Py_call_instrumentation_exc2(PyThreadState *tstate, int event, 63 _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1); 64 65 extern int 66 _Py_Instrumentation_GetLine(PyCodeObject *code, int index); 67 68 extern PyObject _PyInstrumentation_MISSING; 69 extern PyObject _PyInstrumentation_DISABLE; 70 71 72 /* Total tool ids available */ 73 #define PY_MONITORING_TOOL_IDS 8 74 /* Count of all local monitoring events */ 75 #define _PY_MONITORING_LOCAL_EVENTS 11 76 /* Count of all "real" monitoring events (not derived from other events) */ 77 #define _PY_MONITORING_UNGROUPED_EVENTS 16 78 /* Count of all monitoring events */ 79 #define _PY_MONITORING_EVENTS 19 80 81 /* Tables of which tools are active for each monitored event. */ 82 typedef struct _Py_LocalMonitors { 83 uint8_t tools[_PY_MONITORING_LOCAL_EVENTS]; 84 } _Py_LocalMonitors; 85 86 typedef struct _Py_GlobalMonitors { 87 uint8_t tools[_PY_MONITORING_UNGROUPED_EVENTS]; 88 } _Py_GlobalMonitors; 89 90 /* Ancillary data structure used for instrumentation. 91 Line instrumentation creates this with sufficient 92 space for one entry per code unit. The total size 93 of the data will be `bytes_per_entry * Py_SIZE(code)` */ 94 typedef struct { 95 uint8_t bytes_per_entry; 96 uint8_t data[1]; 97 } _PyCoLineInstrumentationData; 98 99 100 /* Main data structure used for instrumentation. 101 * This is allocated when needed for instrumentation 102 */ 103 typedef struct _PyCoMonitoringData { 104 /* Monitoring specific to this code object */ 105 _Py_LocalMonitors local_monitors; 106 /* Monitoring that is active on this code object */ 107 _Py_LocalMonitors active_monitors; 108 /* The tools that are to be notified for events for the matching code unit */ 109 uint8_t *tools; 110 /* The version of tools when they instrument the code */ 111 uintptr_t tool_versions[PY_MONITORING_TOOL_IDS]; 112 /* Information to support line events */ 113 _PyCoLineInstrumentationData *lines; 114 /* The tools that are to be notified for line events for the matching code unit */ 115 uint8_t *line_tools; 116 /* Information to support instruction events */ 117 /* The underlying instructions, which can themselves be instrumented */ 118 uint8_t *per_instruction_opcodes; 119 /* The tools that are to be notified for instruction events for the matching code unit */ 120 uint8_t *per_instruction_tools; 121 } _PyCoMonitoringData; 122 123 124 #ifdef __cplusplus 125 } 126 #endif 127 #endif /* !Py_INTERNAL_INSTRUMENT_H */