benfred / py-spy

Sampling profiler for Python programs
MIT License
12.16k stars 401 forks source link

How can reducing the sampling rate. #547

Closed LukeLIN-web closed 1 year ago

LukeLIN-web commented 1 year ago

When I run py-spy record -o profile.svg -- python myprogram.py It continuously shows py-spy> 347.19s behind in sampling results may be inaccurate. Try reducing the sampling rate How can I do it? And running this command takes much longer than python myprogram.py May you know why? Thank you for your time!

Jongy commented 1 year ago

You can use -r to control the sampling rate, e.g py-spy record -r 5 for 5 HZ.

py-spy operates in blocking mode by default - where the application is paused during each sample taken. Therefore by design the app will take longer to run when profiled. Normally it shouldn't be "much longer" but only a bit - but this depends on the number of threads in your application. You can use --nonblocking flag to have py-spy to run in non-blocking which should not affect the application at all (but might reduce the accuracy of the profile).

LukeLIN-web commented 1 year ago

You can use -r to control the sampling rate, e.g py-spy record -r 5 for 5 HZ.

py-spy operates in blocking mode by default - where the application is paused during each sample taken. Therefore by design the app will take longer to run when profiled. Normally it shouldn't be "much longer" but only a bit - but this depends on the number of threads in your application. You can use --nonblocking flag to have py-spy to run in non-blocking which should not affect the application at all (but might reduce the accuracy of the profile).

Thank you!