Where is iOS Background Thread Being Called From - Stack Trace Via Instruments - ios

I am trying to figure out why my program is hanging at one point. I know full well about the hefty call I make on the main thread but I don't know what the dispatch queue is that accounts for nearly half of the time. How can I trace where that call is coming from? Here is a screenshot from Instruments:

Related

iOS how to inspect items on the main OS Dispatch Queue

I am developing an app using React Native and running end to end tests with Detox (this is for context but not particularly relevant). The e2e tool automatically pauses execution when it detects actions taking place, such as in flight network requests, animations, items on the main thread etc.
My problem is that my tests are hanging due to an item on the OS Dispatch Queue that is never dequeued. This is all the information that the tool gives me. Is there a way, perhaps through an Xcode debugger, that I can inspect items on the dispatch queue? Perhaps that might give me a clue as to the nature of the items on the queue which might in turn help me find out how to prevent enqueuing them or removing them from the queue.
If this isn't the best place to ask perhaps you might point me to a more suitable place. Thanks
TLDR: How can I view items on the main OS Dispatch Queue?

How is threads view useful in performance/cpu profilers?

After I profile an ASP.NET Core application, JetBrain's dotTrace tool by default opens up the All Calls tab and shows a list of threads.
Could you please clarify some of my questions?
During my profiling session, I sent around 100K requests to the web application. Are these threads (apart from Main and some system threads like Finalizer thread) the only ones which were used by the thread pool to serve all those requests based on the image below?
Ideally I would prefer to know the details of the function that took lot of CPU (i.e hottest method in the profiling session), so I keep wondering how this threads view actually helps?
Do you think there could have been many more threads from the thread pool which could have been used and returned back to the thread pool, but the profiler was only able to 'capture' the information of particular thread pool threads because those thread pool threads were executing during that time? I say this because for ~100K requests the number of threads shown here seem less, but I could be wrong. (Probably its based on number of concurrent requests executed?)
The Threads view is usefull when you use real Threads in your application.
For example, in a WPF the main thread just for dispatcher and your custom thread for background working.
In your case, you still can expand the dispatch to see what's executed inside.
You can also use Tracing mode to see the number of request inside a pool worker.
All the threads actually used during your profiling recording are displayed, each thread will execute lots of requests
For this kind of use, I prefer the Timeline mode, so you can filter all your requests and see all the threads where is was executed.

ios - detect disk operations on main thread

is it possible to detect disk operations on main thread? ie queries to sqlite executed on main thread. In android there is Strict mode which will crash application every time when app does disk operation on main thread but. Is there something like this in ios?
I have inherited big codebase and randomly discovered database queries executing on main thread. I would like to have some option to simply discover all. (I used instruments but something like throwing exception every time there is unallowed operation on main thread will be better)
Only possible solution which I see is to check Thread.current.isMainThread before every disk operation
Thanks
You can enable Core data concurrency debug mode which is like a Strict mode, it will throw an exception when core data entities are accessed from an incorrect thread.
You can enable it by passing the following argument when running
-com.apple.CoreData.ConcurrencyDebug 1
You can get more information and a more in-depth explanation here

iOS main thread freezes for few seconds

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.
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.

In iOS when must I run something on the main thread?

I have a game that I'm getting ready to submit. I've tested it a lot and it seems to be solid -- no crashes and no unexpected behavior. I am not forcing anything to run on the main thread (except for one place where I followed a sample in a book) and now I'm concerned that under some circumstance, on somebody else's device, the game will not work right or crash because I'm not doing something on the main thread that should be on the main thread. But I don't understand what needs to be run on the main thread. I googled for a checklist or summary of what methods need run on the main thread and didn't find anything useful. Is this something I need to worry about? The app is for iOS 5.1 and up and it uses in-app purchases and Game Center. I use the cocos2d framework and also a lot of UIKit stuff.
most methods running on the main thread are fine,
especially the UI,
you want to use the back thread for processes that can take long, like http requests, database or data sorting, or any other process that can pause the user experience while is processing.
if you load lots of objects you can produce a memory warning that can result in a crash,
so you can release non needed objects when you get a memory release.
good luck

Resources