benfred / py-spy

Sampling profiler for Python programs
MIT License
12.89k stars 431 forks source link

Don't require symbols in python 3.10+ #716

Closed benfred closed 3 weeks ago

benfred commented 4 weeks ago

We used to have a feature that let us profile python processes, even if there were no symbols available from python.

This meant that we didn't rely on a _PyRuntime or an interp_head symbol, and could fall back to scanning the BSS section of the python binary to find the location of the interpreter.

This functionality broke after https://github.com/python/cpython/pull/4802 (found by bisecting the cpython source with a py-spy hacked up to ignore the symbols in https://github.com/benfred/py-spy/pull/715 ) - meaning that we haven't had this functionality since python 3.10. The change in cpython moved the PyRuntime state from the BSS section to a named section , meaning that we are scanning the wrong sections in memory right now. Ironically this change was to make finding this global variable easier for tools like py-spy (which to be clear, I very much appreciate! there have been a bunch of changes like this and the recent debug_offsets changes that will make maintaining py-spy much easier in the future).

This is also one of the reasons that we are currently broken on windows in python 3.10+ -