Skip to content

Commit 6d1dfa9

Browse files
Move tool version to code monitoring and force an instrument
1 parent 81e1de0 commit 6d1dfa9

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Include/cpython/code.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ extern "C" {
2020
/* Tables of which tools are active for each monitored event. */
2121
typedef struct _Py_LocalMonitors {
2222
uint8_t tools[_PY_MONITORING_LOCAL_EVENTS];
23-
uintptr_t tool_versions[_PY_MONITORING_TOOL_IDS];
2423
} _Py_LocalMonitors;
2524

2625
typedef struct _Py_GlobalMonitors {
@@ -60,6 +59,8 @@ typedef struct {
6059
_Py_LocalMonitors active_monitors;
6160
/* The tools that are to be notified for events for the matching code unit */
6261
uint8_t *tools;
62+
/* The version of tools when they instrument the code */
63+
uintptr_t tool_versions[_PY_MONITORING_TOOL_IDS];
6364
/* Information to support line events */
6465
_PyCoLineInstrumentationData *lines;
6566
/* The tools that are to be notified for line events for the matching code unit */

Python/instrumentation.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,12 +1663,13 @@ update_instrumentation_data(PyCodeObject *code, PyInterpreterState *interp)
16631663
// If the local monitors are out of date, clear them up
16641664
_Py_LocalMonitors *local_monitors = &code->_co_monitoring->local_monitors;
16651665
for (int i = 0; i < PY_MONITORING_TOOL_IDS; i++) {
1666-
if (local_monitors->tool_versions[i] != interp->monitoring_tool_versions[i]) {
1666+
if (code->_co_monitoring->tool_versions[i] != interp->monitoring_tool_versions[i]) {
16671667
for (int j = 0; j < _PY_MONITORING_LOCAL_EVENTS; j++) {
16681668
local_monitors->tools[j] &= ~(1 << i);
16691669
}
16701670
}
16711671
}
1672+
16721673
_Py_LocalMonitors all_events = local_union(
16731674
interp->monitors,
16741675
code->_co_monitoring->local_monitors);
@@ -2013,14 +2014,15 @@ _PyMonitoring_SetLocalEvents(PyCodeObject *code, int tool_id, _PyMonitoringEvent
20132014
goto done;
20142015
}
20152016

2017+
code->_co_monitoring->tool_versions[tool_id] = interp->monitoring_tool_versions[tool_id];
2018+
20162019
_Py_LocalMonitors *local = &code->_co_monitoring->local_monitors;
20172020
uint32_t existing_events = get_local_events(local, tool_id);
20182021
if (existing_events == events) {
20192022
res = 0;
20202023
goto done;
20212024
}
20222025
set_local_events(local, tool_id, events);
2023-
local->tool_versions[tool_id] = interp->monitoring_tool_versions[tool_id];
20242026

20252027
res = force_instrument_lock_held(code, interp);
20262028

@@ -2071,8 +2073,9 @@ int _PyMonitoring_ClearToolId(int tool_id)
20712073
}
20722074
interp->monitoring_tool_versions[tool_id] = version;
20732075
set_global_version(_PyThreadState_GET(), version);
2076+
int res = instrument_all_executing_code_objects(interp);
20742077
_PyEval_StartTheWorld(interp);
2075-
return 0;
2078+
return res;
20762079
}
20772080

20782081
/*[clinic input]

0 commit comments

Comments
 (0)