How to check battery usage of an iPhone/Android app?

I think the title says Enough. For example Unity can generate you a report how much CPU/GPU power it's using or how fast it's going to drain device battery, but what about the applications developed using Cocos2d or the ones you develop directly using OpenGL? How should you profile them? In general what should you profile? or Should I simply run the application and wait for it's battery to run out?

On the iPhone, you can go to Settings > Developer > Energy Diagnostics and turn logging on. You can then use the Energy Diagnostics template in Instruments to analyze the data from this log. It will break it down into several kinds of events and graph it over time, correlate it with CPU and network spikes, and generally work like any other Instruments session.

As far as I know (and I have looked, but not exhaustively) there is no equivalent tool for Android. There are some third-party apps that can sample battery across a long period of time to give you an idea of what the discharge curve looks like if you do choose to run your program for a long time. On shorter time scales DDMS can help you figure out some details like your general CPU usage and network usage, which you can then work on batching or reducing. But this is just general optimization help and a big step removed from detailed energy consumption data.

• In the settings on Android there is a section for battery. It shows detailed information about your energy consumption and even which apps are using how much (given as a percentage of overall battery use). – Amplify91 Sep 9 '12 at 18:15
• @Amplify91: That's not present on some handsets which have OEM-customized settings apps. Even when it's there it's good for a very limited set of views (how much did I use in the past five minutes, how much did I use over the past 24 hours), none of which are good for telling you exactly what your program is doing to drain battery. It's like trying to use top for CPU profiling - it can sometimes tell you if you need to profile, but can't actually do it for you. – user744 Sep 9 '12 at 20:17
• yes, it is very bad for precise profiling, but as far as I have seen, I have never known a phone that didn't have it. – Amplify91 Sep 9 '12 at 22:55