Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix profiling when python symbols aren't available. #718

Merged
merged 2 commits into from
Nov 1, 2024
Merged

Conversation

benfred
Copy link
Owner

@benfred benfred commented Oct 31, 2024

Since python 3.10 - we haven't been able to profile python interpreters that have been compiled without symbols. This is because cpython changed where the 'PyRuntime' global is stored in python 3.10, from being in the BSS section into being in its own named section in the binary (python/cpython#4802)

This especially affected profiling on windows, where you'd have to install python symbols to be able to use py-spy.

Fix by reading in the address/size of the the PyRuntime section from the elf/mach/pe binaries and using that to scan python interpreters when symbols aren't available.

Since python 3.10 - we haven't been able to profile python interpreters that
have been compiled without symbols. This is because cpython changed where
the 'PyRuntime' global is stored in python 3.10, from being in the BSS section
into being in its own named section in the binary.

This especially affected profiling on windows, where you'd have to install
python symbols to be able to use py-spy.

Fix by reading in the address/size of the the PyRuntime section from the
elf/mach/pe binaries and using that to scan python interpreters when symbols
aren't available.
@zanieb
Copy link
Contributor

zanieb commented Oct 31, 2024

I believe you can also test this with the "stripped" variants of python-build-standalone (which uv installs by default)

@benfred
Copy link
Owner Author

benfred commented Nov 1, 2024

it would be pretty cool if we could test this out using a stripped build in CI - does the uv build strip out the PyRuntime symbol too ? (like what does something like

nm -A `which python` | grep PyRuntime

show ?)

In the short term, I'm testing this by verifying this fixes the windows wheels #543 - since this mostly impacts windows right now

@benfred benfred marked this pull request as draft November 1, 2024 06:52
@benfred
Copy link
Owner Author

benfred commented Nov 1, 2024

I've created #719 to track testing this functionality in CI - but I'm going to merge this change in now since it does fix the issue , and I've tested this manually to verify it works (and I'd like to get a release out =)

@benfred benfred marked this pull request as ready for review November 1, 2024 18:31
@benfred benfred added the bug Something isn't working label Nov 1, 2024
@benfred benfred merged commit ef23761 into master Nov 1, 2024
50 checks passed
@benfred benfred deleted the fix_no_symbols branch November 1, 2024 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't require symbols in python 3.10+
2 participants