Is my Android App Draining Battery?

20,049

Solution 1

Here is my suggestion:

I watch power consumption while developing my apps (that sometimes poll the sensors at rates of <25ns) using PowerTutor. Check it out, it sounds like this maybe what you are looking for, the app tells you what you are using in mW, J, or relative to the rest of the system. Also, results are broken down by CPU, WiFi, Display, (other radios installed). The only catch is that it is written for a specific phone model, but I use it with great success on my EVO 4G, Galaxy S (Sprint Epic), and Hero.

Good luck, -Steve

Solution 2

There is a possibility that your game is draining battery. I believe this depends on several reasons, which reads as follows:

  • Your application is a game. Games drains battery quickly.
  • You're iterating with help from a Thread. Have you limited the FPS to make the CPU skip unnecessary iterations? Since you're working with 2D I assume you're using the SurfaceView. 60 FPS will be enough for a real-time game.
  • You don't stop the Thread when your application terminates. Hence you reiterate code when your application isn't alive.
  • Have you an iterate lock that does wait(); during onPause?

The people commenting that your game is leaking battery probably aims when your application isn't in use. Otherwise, it would be wierd because every game on Android Market drains battery - more or less.

Solution 3

If you're trying to gauge the "improvement over your previous version", I don't think it makes sense to compare to another game! Unless those two games do the exact thing, this is as unscientific as it gets.

Instead, I would grab the previous version of your app from source control, run it, measure it, and then run it with the latest code and compare it again.

To compare, you could for example use the command line tool "top" (definitely available in busybox if your phone is rooted, not sure if it comes with a stock phone. Probably not). That shows you the CPU usage of your process in percent.

Solution 4

There is a battery profiler developed by Qualcomm called Trepn Profiler: https://developer.qualcomm.com/mobile-development/increase-app-performance/trepn-profiler

Solution 5

how I can use the data coming from Traceview (ie: CPU time in ms spent on each frame of the game) to determine battery usage (if this is at all possible)

In theory it would be possible to extrapolate the battery usage for your app by looking at the power consumption on a frame by frame basis. The best way to accomplish this would be to evaluate the power consumption of the CPU (only) for a given period (say two seconds) while your app is running the most CPU intensive operation, (additionally, GPU power usage could be gleaned this way also) while recording TraceView data (such as frames per second or flops per second) giving you the the traffic across the CPU/GPU for a given millisecond. Using this data you could accurately calculate the average peak power consumption for your app by running the above test a few times.

Here is why I say it is theory only: There are many variables to consider:

  1. The number and nature of other processes running at the time of the above test (processor intensive)
  2. Method of evaluating the power draw across the CPU/GPU (while tools such as PowerTutor are effective for evaluating power consumption, in this case the evaluation would not be as effective because of the need to collect time stamped power usage data. Additionally, just about any method of collecting power data would introduce an additional overhead (Schrödinger's cat) but that strictly depends on the level of accuracy you require/desire.)
  3. The reason for the power consumption information - If you are looking to define the power consumption of your app for testing or BETA testing/evaluation purposes then it is a feasible task with some determination and the proper tools. If you are looking to gain usable information about power consumption "in the wild", on user's devices, then I would say it is plausible but not realistic. The vairables involved would make even the most determined and dedicated researcher faint. You would have to test on every possible combination of device/Android version in the wild. Additionally, the combinations of running processes/threads and installed apps is likely incalculable.

I hope this provides some insight to your question, although I may have gone deeper into it than needed.

-Steve

Share:
20,049
Tom R
Author by

Tom R

Good times with C, Java, Python on web and embedded devices.

Updated on July 05, 2022

Comments

  • Tom R
    Tom R almost 2 years

    I'm developing a game for Android. It uses a surface view and uses the sort of standard 2D drawing APIs provided. When I first released the game, I was doing all sorts of daft things like re-drawing 9-patches on each frame and likewise with text. I have since optimised much of this by drawing to Bitmap objects and drawing them each frame, only re-drawing onto the Bitmap objects when required.

    I've received complaints about battery drain before, and following my modifications I'd like to know (scientifically) if I've made any improvements. Unfortunately, I don't have any prior data to go by, so it would be most useful to compare the performance to some other game.

    I've been running Traceview, and using the results of it mostly for the purposes of identifying CPU-time-consuming methods.

    So -- what's the best way of determining my app's battery performance, and what's a good benchmark?

    I know I can look at the %s of different apps through the settings, but this is again unscientific, as the figure I get from this also depends on what's happening in all of the other apps. I've looked through (most of) Google's documentation, and although the message is clear that you should be saving battery (and it gives the occasional tip as to how), there is little indication of how I can measure how well my app is performing. The last thing I want are more complaints of battery drain in the Android Market!

    Thanks in advance.


    EDIT

    Thanks for all your helpful advice/suggestions. What I really want to know is how I can use the data coming from Traceview (ie: CPU time in ms spent on each frame of the game) to determine battery usage (if this is at all possible). Reading back on my original question, I can see I was a bit vague. Thanks again.

  • Tom R
    Tom R about 13 years
    The problem is that since everything is in %s, this is still unreliable. As an example: when I unplug my Nexus from the charger and start playing the app for a few minutes, when I look up the battery consumption, it's more than 50%. But that (hopefully) doesn't mean the battery usage is extremely high. (sorry that wasn't very well worded)
  • TimFoolery
    TimFoolery about 13 years
    Right, but if there was an app out there that consistently used a certain amount of mA, then you could figure out how much your app was using in relation to it... e.g. the reference app is at 10%, and you're at 5%, then you're using half of that static amount of mA... similarly, if you are at 50%, but it is at 10%, then you are using 5x as many mA. Like I was saying, it's possible that there is no such app, but it would probably be worth making if you're going to go to the trouble anyhow.
  • Tom R
    Tom R about 13 years
    It's a good idea and worth trying, but I don't think my users care whether or not the performance of my app has improved -- I think they just don't want to see a massive battery drain that they can associate with my app. I know this is a bit of a contradiction to when I said "scientific", but what I really want to know is not "what is better battery usage" but "what is appropriate". And then take it from there...
  • Tom R
    Tom R about 13 years
    Actually, the issue you bring up is one I (thought) I'd fixed a while ago by exactly the method in your last bullet point: the CPU usage while the game was paused was through the roof, but adding wait() in the pause loop fixed the problem. I've been monitoring all my apps recently with Watchdog and my app hasn't once been detected above the threshold.
  • Wroclai
    Wroclai about 13 years
    I have hard to see that battery is draining if above points has been fixed. These points are the most realistic way to solve power consumption. See it like this - how can your game possibly eat battery if above points are checked?
  • hackbod
    hackbod about 13 years
    "Appropriate" is all relative. Nobody can give you an answer for that.
  • hackbod
    hackbod about 13 years
    The most accurate way to measure battery use (barring having hardware to measure actual power draw) is probably to fully charge your device, and then see how long your application can run until the battery is discharged. Everything else is an approximation of varying accuracy. For example -- the battery usage currently doesn't take into account OpenGL power drain.
  • EboMike
    EboMike about 13 years
    A good game with flashy graphics will make considerable use of the CPU. But that's what all the CPU horsepower is for. If you're really concerned, you could add a "light" mode that makes the visuals more static but has a fraction of the CPU expense.
  • TimFoolery
    TimFoolery about 13 years
    Yip, I was going to suggest doing that too. See how long it lasts while doing nothing. If it lasts, say, 48 hours, then it uses 2% while idle. If you know the mAh of the battery, then that can be put into mAh as well, not just a percentage. Then, see how long it lasts with your game being played. Eight hours (get some help from a kid or two) would be 12.5% battery usage per hour, except you might want to remove that baseload of 2%.
  • Tom R
    Tom R about 13 years
    Thanks for being the only one to directly answer my question! Will try what you suggest then accept your answer.
  • Kingsolmn
    Kingsolmn about 13 years
    Np, I was afraid that I would be way off target based on how every one else was answering. But, the other answers will help us both I think, lots of good tips to keep the app from being a power hog, what leads to an app being uninstalled by the user!
  • L. G.
    L. G. over 11 years
    PowerTutor is great app that helped me a lot but it does not include the GPS usage in Application details. Dr Power is a great complementary app to do this. It doesn't show graphs but include more modules in the app details.