Tracing and visualizing the Python GIL with perf and VizTracer
9 comments · 97% upvoted · source · other discussions
9 comments · 97% upvoted · source · other discussions
Helpful article
Good stuff, thanks
This looks awesome! How does it handle cythonized libraries and/or C bindings such as tensorflow?
Thanks! You will see the call to the C library (this is what CPython and VizTracer do), and you should see if the GIL is being released, like with NumPy, one of the examples in the article.
That's fantastic. Actually, my application for this is to find naughty C bindings that don't release the GIL. I have a big application that's heavily multithreaded with many C bindings (think gstreamer + tensorflow + OpenVINO), and something is causing a lockup somewhere. It's quite frustrating!
I'll give this tutorial go.
Indeed, that's one of the things I'd like to automate (and I'm very close now), feel free to contact me, we could maybe collaborate on this https://github.com/maartenbreddels/per4m
Nice! A convenient alternative (but maybe not as powerful?):
I recently discovered py-spy for profiling python.
And then visualize it via speedscope.app
maartenbreddels [OP] 3 points · Jan 2021
I think profiling and tracing (what I do here) are complementary. I use py-spy a lot, but it only gives you a 'statistical' view of where time is spent or how much the GIL is held. To gain a deep understanding of the flow of your program and the GIL in a multithreaded environment I needed a tool as I presented, and unfortunately had to make it myself :)
flying-sheep 3 points · Jan 2021
Thank you! I know the feeling: “This should exist, why doesn’t it yet? Sigh.” *rolls up sleeves*