P403n1x87 / austin

Python frame stack sampler for CPython
https://pypi.org/project/austin-dist/
GNU General Public License v3.0
1.71k stars 51 forks source link

Can't run Austin against pyenv python distribution #204

Closed sihil closed 1 year ago

sihil commented 1 year ago

Description

Struggling to get Austin running against pytest on MacOS due to what I am currently assuming is missing debug symbols in my python. I've reduced this to a minimal test case below.

Steps to Reproduce

  1. Install python via pyenv
  2. Run austin python -c "from time import sleep;sleep(4)"

Expected behavior: Austin starts process and outputs profiling data.

Actual behavior: Austin tells me It looks like you are trying to profile a process that is not a Python process.

Reproduces how often: 100%

Versions

austin 3.5.0 (via homebrew) macOS 13.4.1 on a 2019 MacBookPro (Intel) Python (various, all from pyenv)

Additional Information

When installing a version of python the build process seems to pull in libraries from various places so I wonder if this is the variable that is causing this to fail. This is the output from building 3.8.16:

❯ pyenv install 3.8.16
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.8.16.tar.xz...
-> https://www.python.org/ftp/python/3.8.16/Python-3.8.16.tar.xz
Installing Python-3.8.16...
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.8.16 to /Users/sihil/.pyenv/versions/3.8.16

This is an example run:

❯ austin --version
austin 3.5.0

❯ pyenv versions
  system
  3.8.6
  3.8.10
  3.8.10/envs/document-enhancement
* 3.8.16 (set by /Users/sihil/.python-version)
  3.9.11
  3.10.12
  document-enhancement --> /Users/sihil/.pyenv/versions/3.8.10/envs/document-enhancement

❯ python --version
Python 3.8.16

❯ austin python -c "from time import sleep;sleep(4)"
              _   _
 __ _ _  _ __| |_(_)_ _
/ _` | || (_-<  _| | ' \
\__,_|\_,_/__/\__|_|_||_| 3.5.0 [GCC 4.2.1]

👾 It looks like you are trying to profile a process that is not a Python
process. Make sure that you are targeting the right application. If the Python
process is actually a child of the target process then use the -C option to
discover it automatically.

❯ nm -gD /Users/sihil/.pyenv/versions/3.8.16/lib/libpython3.8.dylib
/Library/Developer/CommandLineTools/usr/bin/nm: error: /Users/sihil/.pyenv/versions/3.8.16/lib/libpython3.8.dylib: File format has no dynamic symbol table
P403n1x87 commented 1 year ago

@sihil thanks for reporting this. What happens if you run this instead?

sudo austin -t 1s python -c "from time import sleep;sleep(4)"

Does it still fail to emit samples?

sihil commented 1 year ago

Oh no 🤦 that's working now and I can now see where the readme says Austin requires the use of sudo to work on MacOS.

Perhaps that error message could be enhanced on macOS to aide future impatient users 😳

P403n1x87 commented 1 year ago

@sihil thank you very much for confirming and the feedback! If you have the time, perhaps you can test Austin from the devel branch. It should already have the more informative error message pointing to the use of sudo in this case (https://github.com/P403n1x87/austin/pull/173). It will be part of the 3.6 release, which should land in October, after Python 3.12 is released 🙏