gh-135953: Profile a module or script with sampling profiler by lkollar · Pull Request #136777 · python/cpython
Bot
mentioned this pull request
lkollar
marked this pull request as ready for review
AA-Turner
changed the title
[gh-135953] Profile a module or script with sampling profiler
gh-135953: Profile a module or script with sampling profiler
Add `-m` and `filename` arguments to the sampling profiler to launch the specified Python program in a subprocess and start profiling it. Previously only a PID was accepted, this can now be done by passing `-p PID`.
These args are already mutually exclusive, but we need to check if at least on module argument has been passed.
In this case the subprocess will go into zombie state until we can poll it. We can simply assume this is the case if it's still detected as running when we get a ValueError.
Improve the return value check to be able to raise a ProcessLookupError when the remote process is not available. Mach uses composite error values where higher error values indicate specific subsystems. We can use the err_get_code function to mask the higher bits to make our error checking more robust in case the subsystem bits are set. For example, in some situations if the process is in zombie state, we can get KERN_NO_SPACE (0x3) but the actual return value is 0x10000003 which indicates a specific subsystem, thus we need to use err_get_code to extract the error value. This also improves how KERN_INVALID_ARGUMENT is handled to check whether we got a generic invalid argument error, or if the process is no longer accessible.
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters