@@ -49,3 +49,43 @@ Note that holding an :term:`attached thread state` is not required for these API
4949 This is called by the runtime itself during interpreter shut-down. In
5050 general, there shouldn't be a reason to explicitly call this, except to
5151 handle specific scenarios such as forking.
52+
53+ .. c:function:: int PyUnstable_CopyPerfMapFile(const char *parent_filename)
54+
55+ Open the ``/tmp/perf-$pid.map `` file and append the content of *parent_filename *
56+ to it.
57+
58+ This function is available on all platforms but only generates output on platforms
59+ that support perf maps (currently only Linux). On other platforms, it does nothing.
60+
61+ .. versionadded:: 3.13
62+
63+ .. c:function:: int PyUnstable_PerfTrampoline_CompileCode(PyCodeObject *code)
64+
65+ Compile the given code object using the current perf trampoline.
66+
67+ The "current" trampoline is the one set by the runtime or the most recent
68+ :c:func: `PyUnstable_PerfTrampoline_SetPersistAfterFork ` call.
69+
70+ If no trampoline is set, falls back to normal compilation (no perf map entry).
71+
72+ :param code: The code object to compile.
73+ :return: 0 on success, -1 on failure.
74+
75+ .. versionadded:: 3.13
76+
77+ .. c:function:: int PyUnstable_PerfTrampoline_SetPersistAfterFork(int enable)
78+
79+ Set whether the perf trampoline should persist after a fork.
80+
81+ * If ``enable`` is true (non-zero): perf map file remains open/valid post-fork.
82+ Child process inherits all existing perf map entries.
83+ * If ``enable`` is false (zero): perf map closes post-fork.
84+ Child process gets empty perf map.
85+
86+ Default: false (clears on fork).
87+
88+ :param enable: 1 to enable, 0 to disable.
89+ :return: 0 on success, -1 on failure.
90+
91+ .. versionadded:: 3.13
0 commit comments