Introducing Powergremlin

powergremlin-banner

Introduction

Using power effeciently is essential to making a successful app. Not only is it rude to drain your users’ batteries but if their phones run out of battery quickly they physically can’t use your app. Sadly, the built-in Instruments energy diagnostics are fairly limited. You can see which major power draws (GPS, screen, cell radio, etc) are currently on but there’s no way to see how much current the device is currently drawing. This is the crucial piece of information because ultimately you want to be able to answer two basic questions:

  1. How long will the battery last when running my app?
  2. How much is the battery life extended when I perform a particular optimization?

Powergremlin leverages private APIs to measure the battery’s current capacity over time and determine current draw. Using this information you can easily answer these questions.

Note: Powergremlin only works with iOS 6 and below

Tutorial

powergremlin_screenshot

First you’ll need to clone the repo from Github. The README has instructions for building; essentially open in XCode and run.

Now, let’s imagine you’re working on off-brand Foursquare. Your users complain that even an hour of use decimates their batteries. Intuitively you know that doing things like reducing CPU usage, turning off location services as much as possible, minimizing network traffic and so on should help but it’s risky to start making optimizations without profiling. So let’s profile! Here’s what you do:

  1. Make sure that location services aren’t active. If you have a solid arrow in the status bar then something is using location services and you should turn it off so that it won’t skew results. A hollow arrow indicates geofencing. Remove any reminders that depend on a location to make it go away.
  2. Now restart your phone to minimize the number of background processes. Background processes can cause CPU activity and network activity that would skew your results.
  3. Start Powergremlin and tap “Reset”.
  4. Use your app for at least 15mins, preferably more like 30mins.
  5. Go back to Powergremlin. The cruical figure in this case is “Current Draw (mA)”. It indicates the average current draw since you tapped “Reset”. You divide the battery capacity in milliamp-hours by the average draw in milliamps to get a rough sense of how long your battery will last while running your app.

Now that you have a baseline you can try implementing different optimizations and check their improvements. For example, if your baseline is a draw of 300 mA and after switching to a less chatty API the draw goes down to 270 mA then you just bought an iPhone4 user an extra 30 minutes.

As you embark on your power profiling adventures there are several things to keep in mind:

  1. Never test while on external power. Powergremlin doesn’t take into account the current supplied by the charger so the numbers are incorrect. Also, even if Powergremlin handled this case gracefully you’d never want to do this because the phone uses much more power when charging.
  2. Batteries degrade over time. A brand new iPhone 4 has a capacity 1420 mAh. My year old iPhone, however, has a capacity of 1350 mAh. In practice most of your users’ phones will have batteries with less capacity than what the specs claim.
  3. Power usage is extremely variable. Always make several measurements of at least 15 minutes each.
  4. Test usage in the real world as much as possible. The power characteristics of an iPhone on WiFi in an area with good cell coverage are radically different from those of a phone in an an area with only spotty EDGE.

Posted by Manuel Wudka-Robles

Manuel is a sponge for software knowledge. Manuel’s software development expertise ranges from Rails web development to obscure 3rd party APIs and long-forgotten web properties. Manuel was the “API guy” at Genius.com, recognized for his deep knowledge of how to build and scale APIs. At Turn, Manuel focused on improving the exciting world of display advertising. Most recently at Tello, Manuel led the integration with Twilio and KISSMetrics. At Palomino Labs, Manuel also serves as Director of IE Compatibility.

About Palomino Labs

Palomino Labs unlocks the potential of software to change people and industries. Our team of experienced software developers, designers, and product strategists can help turn any idea into reality.

See the Palomino Labs website for more information, or send us an email and let's start talking about how we can work together.