BLOG

Flags: very useful when debugging with Instruments

There is a very nice feature in Instruments that helps you to point your loupe to a very precise spot in your code.

I am writing an app that process images captured by the camera in real-time. I am using GCD to launch different queues both in asynchronous and synchrous mode and when it is time to debug, it’s a mess. Most of the time I need to know extactly what is doing what and where something is executing. Using the breakpoints interrupting the execution and analyze the status of your variable, it is not always useful in a multi-threaded environment, because you alter the real flow of your application.

My mind went immediately to Instruments and I found a very cool tool that you can use to know when something is executing.

Performance Session

To use this feature, you need to add to your Xcode project the DTPerfomanceSession.framework and #import into the class you want to analyze.

Now, wherever you need to send a signal to Instruments from your app, you just add this line of code:

DTSendSignalFlag("com.invasivecode.mytracepoints.app.point", DT_POINT_SIGNAL, TRUE);

You can also mark the start and the end of something, inserting these lines at the beginning and at the end of your code chunk:

// Put this line at the begining
DTSendSignalFlag("com.invasivecode.mytracepoints.app.start", DT_START_SIGNAL, TRUE);

// ... more code here

// put this at the end
DTSendSignalFlag("com.invasivecode.mytracepoints.app.end", DT_END_SIGNAL, TRUE);

Done that, you can now lunch your Instruments, select the tool or the set of tools (Allocation, Profiler, etc.) you need and start to analyze your code. When the execution hits the above macros, Instruments will show a flag in the timeline as illustrated here:

Instruments flags

You can also click on each flag and it will provide you with some detail information:

Flag details

You can imagine how this is useful during the debugging and especially in a multi-threaded environment, where lots of things are happening in parallel. If you combine this with small tricks like putting a short sleep in your code, you can really get very close to each bit of execution.

Geppy

8 Notes/ Hide

  1. do-nothing reblogged this from invasivecode
  2. i0sdev reblogged this from invasivecode
  3. scottdensmore reblogged this from invasivecode
  4. martinpilch reblogged this from invasivecode
  5. geppyp reblogged this from invasivecode
  6. invasivecode posted this

Recent comments

Blog comments powered by Disqus
Designed and developed in California © 2008-2014 iNVASIVECODE INC