From 62f1b67db4fd833b726e5ee43502f3c3c64bc0e9 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Wed, 24 Aug 2022 11:10:28 +0100 Subject: [PATCH] PEP 669: Require names for tools. (GH-2770) * Add Petr's suggestion for naming tools. * Clarify that instrumentation works similarly to PEP 659, but that PEP 659 is not a requirement. --- pep-0669.rst | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pep-0669.rst b/pep-0669.rst index 27646778a..bf6416774 100644 --- a/pep-0669.rst +++ b/pep-0669.rst @@ -105,10 +105,13 @@ Identifiers are integers in the range 0 to 5. :: - sys.monitoring.use_tool_id(id)->None - sys.monitoring.free_tool_id(id)->None + sys.monitoring.use_tool_id(id, name:str) -> None + sys.monitoring.free_tool_id(id) -> None + sys.monitoring.get_tool(id) -> str | None ``sys.monitoring.use_tool_id`` raises a ``ValueError`` if ``id`` is in use. +``sys.monitoring.get_tool`` returns the name of the tool if ``id`` is in use, +otherwise it returns ``None``. All IDs are treated the same by the VM with regard to events, but the following IDs are pre-defined to make co-operation of tools easier:: @@ -342,6 +345,7 @@ In general these operations can be considered to be fast: * ``def get_events(tool_id: int)->Event`` * ``def get_local_events(tool_id: int, code: CodeType)->Event`` * ``def register_callback(tool_id: int, event: Event, func: Callable)->Optional[Callable]`` +* ``def get_tool(tool_id) -> str | None`` These operations are slower, but not especially so: @@ -351,7 +355,7 @@ These operations are slower, but not especially so: And these operations should be regarded as slow: -* ``def use_tool_id(id)->None`` +* ``def use_tool_id(id, name:str)->None`` * ``def free_tool_id(id)->None`` * ``def set_events(tool_id: int, event_set: Event)->None`` * ``def restart_events()->None`` @@ -396,9 +400,9 @@ implementation for later versions of CPython and other Python implementations may differ considerably. The proposed implementation of this PEP will be built on top of the quickening -step of :pep:`PEP 659 <659#quickening>`. -Activating some events will cause all code objects to -be quickened before they are executed. +step of CPython 3.11, as described in :pep:`PEP 659 <659#quickening>`. +Instrumentation works in much the same way as quickening, bytecodes are +replaced with instrumented ones as needed. For example, if the ``C_CALL`` event is turned on, then all call instructions will be