Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gaogaotiantian opened this issue Mar 13, 2024 · 1 comment
Open

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

gaogaotiantian opened this issue Mar 13, 2024 · 1 comment
Labels
type-feature A feature request or enhancement

Comments

@gaogaotiantian
Copy link
Member

gaogaotiantian commented Mar 13, 2024

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

@gaogaotiantian gaogaotiantian added the type-feature A feature request or enhancement label Mar 13, 2024
@gaogaotiantian
Copy link
Member Author

@markshannon @brandtbucher could you let me know what you think about this? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant