From 9a85c5607f47a0085b6c344e962a6cb90fb3f61b Mon Sep 17 00:00:00 2001 From: Yash Date: Wed, 7 Jan 2026 00:17:10 +0530 Subject: [PATCH 1/3] first commit perfmaps --- Doc/c-api/perfmaps.rst | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Doc/c-api/perfmaps.rst b/Doc/c-api/perfmaps.rst index 76a1e9f528dc70..098b8c18ff2498 100644 --- a/Doc/c-api/perfmaps.rst +++ b/Doc/c-api/perfmaps.rst @@ -49,3 +49,34 @@ Note that holding an :term:`attached thread state` is not required for these API This is called by the runtime itself during interpreter shut-down. In general, there shouldn't be a reason to explicitly call this, except to handle specific scenarios such as forking. + + +.. c:function:: int PyUnstable_CopyPerfMapFile(const char *parent_filename) + + Open the ``/tmp/perf-$pid.map`` file and append the content of *parent_filename* + to it. + + :param parent_filename: The name of the file to copy. + :return: 0 on success, -1 on failure. + + .. versionadded:: 3.13 + + +.. c:function:: int PyUnstable_PerfTrampoline_CompileCode(PyCodeObject *code) + + Compile the given code object using the current perf trampoline. + + :param code: The code object to compile. + :return: 0 on success, -1 on failure. + + .. versionadded:: 3.13 + + +.. c:function:: int PyUnstable_PerfTrampoline_SetPersistAfterFork(int enable) + + Set whether the perf trampoline should persist after a fork. + + :param enable: 1 to enable, 0 to disable. + :return: 0 on success, -1 on failure. + + .. versionadded:: 3.13 From 5e050f1939d8551a381f84ba24f6f249805f1e23 Mon Sep 17 00:00:00 2001 From: Yash Date: Wed, 7 Jan 2026 00:44:01 +0530 Subject: [PATCH 2/3] fix 1 perfmaps --- Doc/c-api/perfmaps.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/perfmaps.rst b/Doc/c-api/perfmaps.rst index 098b8c18ff2498..dbce1c1e389658 100644 --- a/Doc/c-api/perfmaps.rst +++ b/Doc/c-api/perfmaps.rst @@ -56,8 +56,8 @@ Note that holding an :term:`attached thread state` is not required for these API Open the ``/tmp/perf-$pid.map`` file and append the content of *parent_filename* to it. - :param parent_filename: The name of the file to copy. - :return: 0 on success, -1 on failure. + This function is only available on platforms that support perf maps (currently + Linux). Return ``0`` on success, ``-1`` on failure. .. versionadded:: 3.13 From bd7eb99ee99bd129bb646384f1809c4426313175 Mon Sep 17 00:00:00 2001 From: Yash Date: Thu, 8 Jan 2026 22:24:34 +0530 Subject: [PATCH 3/3] fix 2 perfmaps --- Doc/c-api/perfmaps.rst | 17 +++++++++++++++++ Tools/check-c-api-docs/ignored_c_api.txt | 4 ---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Doc/c-api/perfmaps.rst b/Doc/c-api/perfmaps.rst index dbce1c1e389658..d908ebebdfc74e 100644 --- a/Doc/c-api/perfmaps.rst +++ b/Doc/c-api/perfmaps.rst @@ -50,6 +50,11 @@ Note that holding an :term:`attached thread state` is not required for these API general, there shouldn't be a reason to explicitly call this, except to handle specific scenarios such as forking. +These unstable functions let you access and set perf map information +about the current frame from C code. + +Note: Appends the content of the parent frame to the current one in perf maps. +Just like in frameobject.h. .. c:function:: int PyUnstable_CopyPerfMapFile(const char *parent_filename) @@ -66,6 +71,11 @@ Note that holding an :term:`attached thread state` is not required for these API Compile the given code object using the current perf trampoline. + The "current" trampoline is the one set by the runtime or the most recent + :c:func:`PyUnstable_PerfTrampoline_SetPersistAfterFork` call. + + If no trampoline is set, falls back to normal compilation (no perf map entry). + :param code: The code object to compile. :return: 0 on success, -1 on failure. @@ -76,6 +86,13 @@ Note that holding an :term:`attached thread state` is not required for these API Set whether the perf trampoline should persist after a fork. + * If ``enable`` is true (non-zero): perf map file remains open/valid post-fork. + Child process inherits all existing perf map entries. + * If ``enable`` is false (zero): perf map closes post-fork. + Child process gets empty perf map. + + Default: false (clears on fork). + :param enable: 1 to enable, 0 to disable. :return: 0 on success, -1 on failure. diff --git a/Tools/check-c-api-docs/ignored_c_api.txt b/Tools/check-c-api-docs/ignored_c_api.txt index e81ffd51e193b2..6f79dd2e92e727 100644 --- a/Tools/check-c-api-docs/ignored_c_api.txt +++ b/Tools/check-c-api-docs/ignored_c_api.txt @@ -68,10 +68,6 @@ PyStdPrinter_Type Py_UniversalNewlineFgets # cpython/setobject.h PySet_MINSIZE -# cpython/ceval.h -PyUnstable_CopyPerfMapFile -PyUnstable_PerfTrampoline_CompileCode -PyUnstable_PerfTrampoline_SetPersistAfterFork # cpython/genobject.h PyAsyncGenASend_CheckExact # cpython/longintrepr.h