-
Notifications
You must be signed in to change notification settings - Fork 0
Python
Includes the C calls. ref
- Make sure Python is installed with frame-pointers, the JIT way is too slow.
CFLAGS="-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer" pyenv install <version> - Run your program with perf.
perf record -g python -X perf <python command> - Show the profile data.
perf report
When compiling PyO3, it looks for which libpython to link to.
When building your package using maturin, linking is disabled, breaking binaries, tests, and examples.
ref
To inspect the location where PyO3 is looking, run: PYO3_PRINT_CONFIG=1 cargo b 2>&1 | grep lib_dir.
To inspect the lib_dir of a specific python executable:
python -c 'import sysconfig; print(sysconfig.get_config_var("LIBDIR"))'
If these don't match, something is wrong. This can happen for some reason (https://github.com/PyO3/pyo3/issues/1576) in PyEnv.
By using a venv during the build, the linking step is solved.
This however does not solve the run, which requires LD_LIBRARY_PATH to be set correctly.
When using the system python version, there is no issue.
When using an alternative location, which is not searched by ldd, you'll have to provide the LD_LIBRARY_PATH.
So to tie everything together, when using poetry:
LD_LIBRARY_PATH=$(poetry run python -c 'import sysconfig; print(sysconfig.get_config_var("LIBDIR"))') poetry run cargo t