Skip to content

Provide a mechanism to "unload" the monitoring tool #116750

Closed
@gaogaotiantian

Description

@gaogaotiantian

Feature or enhancement

Proposal:

As mentioned in #111963, we don't have a way to fully unload the monitoring tool and this is a bad experience for users. Debuggers have to track code objects of their breakpoints if they want to do it with local events. I think we should have a sys.monitoring.clear_tool_id(tool_id: int) to clear up all the residues for the tool without giving up the tool_id. Also sys.monitoring.free_tool_id() should run clear_tool_id first - it's just safer and makes more sense.

Global events should be trivial, by set_events(tool_id, 0) all the global events should be disabled and if the next tool claims the id, it needs to explicitly set them again anyway. Callbacks are easy as they are just in an array.

The hard part is local events, as they are instrumented lazily. Currently we don't have a way to inform the code object that a tool is unloaded(cleared) and we don't track all the instrumented code objects.

I think the way to go is to version the tool and the local monitors. Each time a tool is registered (cleared), a new version number is assigned to the tool (same source of the code object, global_version basically). The increment of the version number will force all the code object to check their instrumentation, and in update_instrumentation_data, we can check whether the local monitors are in sync with the tools. Remove the tool if they are not.

Impacts:

  • For each _Py_LocalMonitors, another uint32_t versions[PY_MONITORING_TOOL_IDS] to keep the version of the tools
  • Extra check in update_instrumentation_data
  • No run-time impact on programs without instrumentation

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions