py-spy icon indicating copy to clipboard operation
py-spy copied to clipboard

Support subprocesses with the `dump` command

Open benfred opened this issue 3 years ago • 2 comments

We can profile subprocesses with the record or top commands, but not yet with the dump command. We should add support for that as well (see https://twitter.com/StasBekman/status/1525636315936485376 )

benfred avatar May 15 '22 04:05 benfred

that would be very useful, thank you, @benfred!

and additionally controlling how many generations of ancestry to descend might be useful as well.

e.g. currently I have a need to py-spy the first generation of children and not the grandchildren (which are just helper processes). Here is a pstree output to show what I mean:

$ pstree -lT `whoami`
slurm_script─┬─srun───srun
             └─tee

python─┬─2*[python───60*[python]]
       └─6*[python]

sshd───bash───bash───pstree

So I want just the 2+6 python processes.

The 1 main python process is the pytorch launcher, the 60 grandchildren are helper dataloaders. the hanging usually happens in the 8 children.

Currently extracting this 2nd only generation with:

pgrep -P $(pgrep -o python) | xargs -I {} py-spy dump --pid {}

but, of course, I'm totally fine with the working pgrep solution.

stas00 avatar May 15 '22 16:05 stas00

I've got the first part of this done in #492 - this adds support for the subprocesses flag in dump (but not limiting the depth of the subprocesses). This will be in the next release, but in the meantime you can grab the prebuilt wheels from the CI artifacts https://github.com/benfred/py-spy/actions/runs/2333647967#artifacts

benfred avatar May 16 '22 18:05 benfred