Support for Perf Maps ¶
On supported platforms (as of this writing, only Linux), the runtime can take advantage of
perf map files
to make Python functions visible to an external profiling tool (such as
perf
). A running process may create a file in the
/tmp
directory, which contains entries that can map a section of executable code to a name. This interface is described in the
documentation of the Linux Perf tool
.
In Python, these helper APIs can be used by libraries and features that rely on generating machine code on the fly.
Note that holding the Global Interpreter Lock (GIL) is not required for these APIs.
-
int
PyUnstable_PerfMapState_Init
(
void
)
¶
-
这为 Unstable API . It may change without warning in minor releases.
打开
/tmp/perf-$pid.mapfile, unless it’s already opened, and create a lock to ensure thread-safe writes to the file (provided the writes are done throughPyUnstable_WritePerfMapEntry()). Normally, there’s no need to call this explicitly; just usePyUnstable_WritePerfMapEntry()and it will initialize the state on first call.返回
0当成功时,-1on failure to create/open the perf map file, or-2on failure to create a lock. Checkerrnofor more information about the cause of a failure.
-
int
PyUnstable_WritePerfMapEntry
(
const
void
*
code_addr
,
unsigned
int
code_size
,
const
char
*
entry_name
)
¶
-
这为 Unstable API . It may change without warning in minor releases.
Write one single entry to the
/tmp/perf-$pid.mapfile. This function is thread safe. Here is what an example entry looks like:# address size name 7f3529fcf759 b py::bar:/run/t.py