PDA

View Full Version : Techniques to determine what is blocking the gui thread



Berryblue031
10th April 2012, 11:33
Does anybody have some advice on the easiest way to determine what function call is blocking the gui thread?

We have recently added a new loading spinner (QMovie) in our app - the animation is choppy for the first few seconds (if I run the spinner when the app is idle it works perfect) so it's obvious that something is blocking/taking to much time in the gui thread when the spinner is running.... my question is how to find it?

Is there a general debugging technique I can use? Right now I am just commenting out functionality hoping to hit the right chunk - but it's a big app and there must be a better way!

wysota
10th April 2012, 14:09
Does anybody have some advice on the easiest way to determine what function call is blocking the gui thread?
Run your program under the debugger, when the GUI is blocked, interrupt the application (e.g. Ctrl+C when using gdb) and see what the top frame of the main thread is. That's your blocking call. You can trace it down to your code by checking lower frames (printing a backtrace is the simplest way to do this).

Michael Druckenmiller Sr
10th April 2012, 19:58
If you are using any loops try adding YourAppName.processEvents() inside the loop

This is similar to DoEvents in VB.

It allows the System/GUI to process any "Events" aka "Signals" that may be blocked during the loop.

Hope this helps.

Spitfire
11th April 2012, 15:52
Or use some profiler that will show you where your app spends the time.