6

I am seeing main thread freezing for a few seconds in my app only on iOS 8 (not on previous iOS versions).
I am using @synchronised (self) at a number of places and also using RemoteIO setup. My question is how do I debug where exactly is the main thread blocking and get additional information, such as what it is doing at that time ?

I am using Xcode 6 so please tell me the best way to debug.

EDIT: Here is the output from Pause.

enter image description here

enter image description here

Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131

1 Answers1

10

As a first step to understand what's happening I would suggest to simply press Pause in debugger while you're having a freeze. It will show you which thread is doing what at that point.

You will either see a task that is still executing, or msg_trap row indicating that there's a lock somewhere.

Post here what you found out.

hybridcattt
  • 3,001
  • 20
  • 37
  • 1
    Ok this has driven me crazy since morning. I pause whenever I find the main thread hanging on startup. It shows 13 pending blocks to be executed. It shows __semwait_signal at the top, so is the main thread waiting for some activity to finish ? I have edited the question & attached screenshots to the question. – Deepak Sharma Oct 06 '14 at 13:47
  • If I understand correctly what you're doing, you have some processing on video captured from a camera. So either it takes too long to process each frame, or callback is called too often so it cant do anything between calls. I assume it's your code so now Time Profiler could get helpful. – hybridcattt Oct 06 '14 at 13:55
  • Actually there is nothing expensive that I am doing and it only happens in iOS 8. I am sure I have discovered a bug in iOS 8 that sometimes(not always) results in main thread going to sleep for a few seconds at startup. The time of sleep varies anything between 1 sec to 15 sec. I used time profiler and it shows main thread calling usleep. Why does the main thread call usleep at all is what I do not understand. – Deepak Sharma Oct 06 '14 at 14:28
  • Methods that are shown in stack trace - is it your methods? Did you write them? They are black coloured (not grey) so I suppose you did. Could you post some code and/or profiler screenshots? – hybridcattt Oct 06 '14 at 14:45
  • What I did for such a problem was to replace all the @synchronize statements with calls to lock/unlock methods. The lock method, if blocked, would post the time it was blocked. The unlock method would compare the blocked time (if any) to current time, and if the delta was over some threshold, dump its own thread call stack. – Hot Licks Oct 06 '14 at 16:01
  • So it is taking too long to execute each call. Sometimes it happens from one iOS version to another - for example touchesMoved: method call speed significantly slowed down in iOS7. – hybridcattt Oct 06 '14 at 21:07
  • Yes, it seems to be a case of significant slowdown of one path. I am processing camera frames and do dispatch_async to main queue as soon as I receive the camera frame for further processing. Only processing that is done is to display the frame as it is to Opengles view. When I start RIO unit in parallel to capture session, looks like the main thread is blocked for sometime and opengles calls hang for sometime at the start, but get cleared after few seconds. As a workaround, I limit the number of video frames that can be under processing at any particular time to 2 and it works on iOS 8. – Deepak Sharma Oct 07 '14 at 04:54