benfred / py-spy

Sampling profiler for Python programs
MIT License
12.14k stars 400 forks source link

Add 'whitelist' argument to limit the subprocesses being monitored #597

Open WillRosen opened 1 year ago

WillRosen commented 1 year ago

Hello!

The main reasoning behind this change is the following issue: https://github.com/benfred/py-spy/issues/561

This changes the thread that checks for new subprocesses, and calls a new ‘should_spy_process’ function to determine if the subprocess should be spied on. It currently checks if the process name if within the whitelist, if no whitelist is provided then it reverts to the old behaviour.

It is important this check happens before checking the symbols, so it will reduce the CPU usage as mentioned in the issue above. Example usage: py-spy.exe record -o speedscope.json -f speedscope --pid x --subprocesses --whitelist=python,pythonw,ect

Let me know what your thoughts are, many thanks! William Rosen