A powerful tool that you can use to improve your app’s performance which comes along with Xcode itself. Instruments provides so many options inside to analyse, test and improve the memory usage and performance of an iOS app.
What you can do using Instruments,
- Analyze performance issues in your app
- Check for memory leaks
- Check for any continuously running method which blocks your main thread
- Find zombies that leads to crash
- Find your app’s memory usage
What are the tools to use,
- Allocations
- Timeprofiler
- Zombies
- Leaks
- Activity Monitor
How to run or launch instruments,
- Clicking on Profile icon (or)
- Command + I (or)
- Xcode -> Product -> Build for -> Profiling
After start running instruments the above selection panel will show up, select the tool as per your need.
Profile Memory Usage of your app:
- Allocations allows you to analyze the abandoned memory
- Activity Monitor allows you to find over all memory usage
- Use Leaks to find the memory leaks
- Use Zombies with the detection of over released Zombie objects
Improve performance of your app:
- Activity monitor allows you to find the CPU usage of your app
- Time Profiler to check the time related processes
- Use Counters to find the events occurs in the processor. Can check for excessive no of events of same type
How to use Allocations ?
- Select allocations from the panel
- Start recording using the Record (
) button
- Cmd+2 -> shows Inspector pane
- Shows the Overall bytes generated/destroyed/live
- Mark generation to inspect a specific task
- Check whether the memory is getting deallocated by checking the Statistics
- Check Call trees to view the methods which is creating the bytes
Leaks
Memory that is allocated to an object that are no longer referenced or reachable
How to identify Memory Leaks?
- Select Leaks from the panel
- Start recording using the Record (
) button
- Cmd+2 -> shows Inspector pane
- Shows the Leaks in the Timeline panel
- Leaks are marked as red in the Leaks timeline
- Click on the leak mark to view more details about it
- Check the details pane for responsible caller
- Can view the method in Xcode for editing purpose
- Leaks view with responsible caller
Zombies :
Objects that are called after they’ve been released and no longer exist.
How to find Zombies?
- Select Zombies from the panel
- Start recording using the Record button
- Do the steps that leads your app to crash because of zombie objects
- Once it crashes you will be able to see the responsible caller by clicking on the arrow mark
- Can rectify the issue and profile it once again
- Toggle the environment variable NSZombieEnabled to true
- This tells the compiler to substitute the zombie object as an NSZombie object
Time Profiler: Make use of this tool for resolving time related issues. When going through your application, at some places/screens it might take time to load or respond. You can see what’s happening or what’s using the time behind using Time profiler.
This takes the stack trace of your app at particular time intervals.
![Time Profiler.png](https://aswathhasina.wordpress.com/wp-content/uploads/2016/09/time-profiler.png?w=1200)
![screen-shot-2016-09-20-at-2-49-22-pm](https://aswathhasina.wordpress.com/wp-content/uploads/2016/09/screen-shot-2016-09-20-at-2-49-22-pm1.png?w=1200)
These are the important tools that we need to improve our App’s performance generally. Please write to me in case of any clarifications or concerns.
Thanks for reading 🙂