In our previous blog of Guide for making Energy efficient apps, we saw the areas which have to be concentrated to make an app energy efficient. We saw in detail about the Energy basics and possible energy hacks. In this blog, we will see in detail about some of the energy debugging tools and summary of making it energy efficient.
Energy debugging tools:
We can check the energy usage of our apps and also can able to debug what amount of energy each and individual process is consuming in our app. This can be done using various tools that are provided with XCode by default, let’s see how can we debug the energy usage of our apps and how that will be helpful for creating energy efficient apps.
Ways to check the energy impact:
i.) Debug Navigator.
i.) Debug Navigator:
By default, you can easily check the energy impact of an app in the device by looking into the “Debug Navigator” in the XCode shown in the following image,
For this to happen you need to run the project.
“Debug Navigator” will give you an overview of following details,
– Average energy impact,
– Average component utilization,
– Energy impact on each and every second(live reading)
– Other shortcut links to check, Time profile, Network profile, Location profile,…
Here it will just show you how much energy consumption is being made by the app, and you can also see what service is consuming the energy, but there is a limitation in this debug navigator that you cannot know what specific part/line of the code is the reason for the impact. For analysing deeper on this you can make use of the latter option(Instruments).
But you can make use of this option, unlike Instruments where this can be useful even when you develop the app itself, whereas the latter can be used after the development process. Keep an eye on the energy needle and try to keep is away from Hight energy impact area.
What is “Instruments”:
“Instruments is a powerful and flexible performance-analysis and testing tool that’s part of the Xcode toolset. It’s designed to help you profile your OS X and iOS apps, processes, and devices in order to better understand and optimize their behaviour and performance. Incorporating Instruments into your workflow from the beginning of the app development process can save you time later by helping you find issues early in the development cycle.” – Apple
On Instruments, you have an option called “Energy Diagnostics” which is used for monitoring and analysing the energy consumption details of your app. It also includes the energy consumed by app functionalities, network actions, display usage and so on as shown in the image below.
Whenever you test the app, have an eye on the Energy debugging gauge, so that you will be able to get any Energy leak issue upfront as soon the new changes had been made in the app.
If in case you find any abnormal energy usage you can use the instruments link provided in the energy efficiency gauge in Xcode where it will directly take you to the Instruments to the specific debugging option. A sample energy diagnostics report is shown in the image below,
Few important scenarios
Points to be considered during energy efficiency testing process are,
1. Launch and idle:
In some cases we may launch the app and user may not perform any action yet but still, unwanted usage may happen, consider those cases.
Test this scenario by making the app go background when energy debugging is in the process, check whether any unwanted process is happening which results in energy consumption. Try to avoid unwanted background processes as much as possible unless it required for your app’s functionality.
3. Application specific:
There are few other cases that need to be considered based on the type of application that you are developing, like in case you are developing a cab tracking app and your app needs to continuously fetch cab’s current location and update on the app. In those cases, consider whether the location service is used only when the cab update information is shown or location is fetching even when we are on that particular screen. And other cases like getting direction, navigation,…
Use the location accuracy based on the need like, because the more the accuracy the more energy consumption happens. Try to use less accurate if you don’t need precise accuracy.
Use the “Energy” logging feature given in the iOS when you test or giving your app to your testing team. It will record the energy usage details. Also, you can make use of the above report by importing the same to Instruments.
For more information on how to test using Instruments and using the Energy logging in iOS device check out the following link.
Energy efficiency is so important in a mobile app, keep in mind that the more an app consumes energy from user’s device the possibility of removing your app from the device is high.
Keep tracking of “Energy gauges” as a part of your regular app development lifecycle itself for greater improvements to your app and keep tracking of the energy impact as well.
Here are some of the important things we discussed in this blog, keep in mind these points whenever you develop an app,
– Use NSURLSession Background Session
– Minimise use of continuous location and choose accuracy efficiently
– Avoid timers
– Use energy gauges
Also, check out the following WWDC session for further details on working with App energy efficiency,