Blogs

Performance Analysis through Instrument tool for iOS App

Instruments Tool

Instruments is a powerful and flexible performance-analysis and testing tool. It is a  part of the Xcode tool set. Instruments tool is designed to help you profile your iOS applications in order to increase their performance and better utilization of resources.

We will see

  1. How to  find hot-spots in code using Time profiler instrument.
  2. How to find and fix the memory problems like strong reference cycle using Allocations instrument.
  3. How to reduce the memory waste by finding the abandoned memory in application using Allocations instrument.
  4. Finding memory allocations which are deal located and still referenced by our application using Zombies instrument.

Launch Instruments from Xcode

To launch Instruments from the Xcode menu

  1. Open Xcode.
  2. Choose Xcode > Open Developer Tool > Instruments.

 

 

 

dotzoo

 

To profile an opened Xcode project

  1. Launch Xcode and open your project.
  2. Do one of the following:

 

    • Choose Product > Profile.

dotzoo2

 

 

  • Click and hold the Run button in the Xcode toolbar and choose Profile.

dotzoo3

 

  • Press Command+I.

Xcode builds your project, Instruments launches, and you’re prompted to select a profiling template.

 

Instruments Tool sections

 

dotzoo4

 

  • Recording control: Start/Stop and Pause the recording.
  • Timer: Running time and number of times application tested.
  • Track: Graphical Representation for selected tool w.r.t. time.
  • Details Panel: Detail output of the particular instrument.
  • Inspectors Panel: Record Setting, Display Setting and Extended Details.

CPU Uses

In Instruments tool, we can conduct testing under variety of conditions. We can also identify that how well the application uses the threads, cores and other resources. We can balance the work with multiple threads and offload work from main thread making our app more responsive. The Time Profiler instrument shows how well an application utilizes CPU cores and threads.

Steps to find CPU Use

  1. Launch Instruments tool using any one of the methods described above.
  2. When it asks to select a template, click Time Profiler.
  3. Choose your device and app from the target device and process lists if they are not selected.
  4. Click the Red Record button in the toolbar or press Command+R to begin recording.
  5. Use your app or the system normally.
  6. Click the Black Stop button in toolbar or press Command+R again when complete.
  7. Click the CPU or threads strategy button in the trace document toolbar.
  8. Examine the collected data.

 

In Detail panel, you can see the time take by each method in your application. if you want to open code then you can double click on any method and if you want to edit the code you can click small xcode icon and modify the code where needed.

Memory Leak

When we allocate some memory in our application but we never release them and the memory no longer being referenced by your app then this is called memory leak. Since we do not have any reference to that allocated memory, we cannot release it and the memory cannot be used again by application. In Instruments tool, we have Leaks template to find the memory leaks in an application.

Steps for finding memory leaks

 

  1. Launch Instruments tool using any one of the methods described above.
  2. When it asks to select a template, click Leaks.
  3. Choose your device and app from the target device and process lists if they are not selected.
  4. Click the Red Record button in the toolbar or press Command+R to begin recording.
  5. Use your app normally.
  6. Watch the Leaks instrument in the timeline pane for leaks. A leak appears as a red bar.
  7. Click the Leaks instrument in the timeline pane to display leak-related information in the detail pane.
  8. Choose Call Tree from the detail type list in the navigation bar of the detail pane. This displays a list of method calls related to any detected leaks.
  9. Press Command+2 to show the display settings area of the inspector pane.
  10. Under the Call Tree display settings, select Invert Call Tree and Hide System Libraries.
  11. In the call tree, select a method call you want to investigate.
  12. Press Command+3 to display a stack trace for the selected method call in the extended detail area of the inspector.
  13. Double-click the method call in the stack trace to display its code in Instruments.
  14. Click the small Xcode button at the top of the detail pane to open the code in Xcode for review and editing.

 

Joomla SEF URLs by Artio