benfred / py-spy

Sampling profiler for Python programs
MIT License
12.2k stars 401 forks source link

Failed to find python version from target process on macOS #512

Closed dzvon closed 1 year ago

dzvon commented 1 year ago

I have already disabled SIP on my macOS.

sudo py-spy record -- python3
Python 3.10.5 (v3.10.5:f377153967, Jun  6 2022, 12:36:10) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> Error: Failed to find python version from target process

There are last few lines of the debugging output, which the command runs with RUST_LOG=debug:

[2022-08-01T10:14:33.466797000Z INFO  py_spy::python_spy] got symbol Py_GetVersion.version (0x0000000101fe6b80) from libpython binary
[2022-08-01T10:14:33.466802000Z INFO  py_spy::python_spy] Getting version from symbol address
[2022-08-01T10:14:33.466812000Z INFO  py_spy::python_spy] Getting version from python binary BSS
[2022-08-01T10:14:33.466817000Z INFO  py_spy::python_spy] Failed to get version from BSS section: failed to find version string
[2022-08-01T10:14:33.466820000Z INFO  py_spy::python_spy] Getting version from libpython BSS
[2022-08-01T10:14:33.466840000Z INFO  py_spy::python_spy] Failed to get version from libpython BSS section: failed to find version string
[2022-08-01T10:14:33.466845000Z INFO  py_spy::python_spy] Trying to get version from path: /Library/Frameworks/Python.framework/Versions/3.10/Resources/Python.app/Contents/MacOS/Python
Error: Failed to find python version from target process

After looking into the source code, it seems like function get_python_version hasn't cover the path like this in macOS.

https://github.com/benfred/py-spy/blob/cd41ee6539026913e006464a4d4e666afd16654b/src/python_spy.rs#L563-L574

dzvon commented 1 year ago

Fixed under conda python environment.