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

more GIL stuff!

Open nlevitt opened this issue 6 years ago • 3 comments

There's so much more I want to know about the GIL. :) Like which threads and functions are holding the GIL and for how long, and which ones are waiting for the GIL and for how long, etc. It's probably a lot to ask for.

nlevitt avatar May 17 '19 19:05 nlevitt

There is some minor work to better able to visualize GIL status in the web branch (pip install py-spy==0.2.0.dev1). If you run with the '--serve' option, this will host an embedded web server that will let you live profile application.

This adds a graph of %GIL activity over time, and also adds the ability to only show frames that hold the GIL.

I agree about adding support for better visualizing this - and would like to add code here to see what threads/functions are holding the GIL. Figuring out if a thread is waiting for the GIL is tricky though, and I doubt I'll have anything for that anytime soon.

benfred avatar May 19 '19 03:05 benfred

One way to see if a thread is waiting for the GIL is to look at the 'PyGILState_Ensure' function in the stack (assuming you have 0.2.0.dev2 installed and are using the --native option).

Still not an awesome solution, but I found it useful just now - with 30% of the time in one of my programs being blocked on the GIL just to update the progress bar.

benfred avatar Jul 07 '19 01:07 benfred

@benfred So, today if I want to see which thread holds the GIL now in cmd line, how can I do? py-spy record -g -f raw -t -p xxx seems work but hard to see in cmd line.

zzt93 avatar Feb 18 '24 08:02 zzt93