Is my Android App Draining Battery?

家住魔仙堡 提交于 2019-11-27 17:04:35

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

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.

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.

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

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

For anyone looking, one resource we've been using that is extremely helpful is a free app from AT&T called ARO.

Give it a look: ARO

It has helped me before and I don't see it mentioned very often so thought I'd drop it here for anyone looking.

"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."

The first thing I'd do is hunt for an app already out there that has a known, consistent battery usage, and then you can just use that as a reference to determine your app's usage.

If there is no such app, you will have to hope for an answer from someone else... and if you are successful making such an app, I would suggest selling your new "battery usage reference" app so that other programmers could use it. :)

I know this question is old and it's late, but for anyone who comes here looking for a solution I suggest you take a look at JouleUnit test: http://dnlkntt.wordpress.com/2013/09/28/how-to-test-energy-consumption-on-android-devices/

It integrates into eclipse and gives you a great amount of detail about how much battery your app is consuming.

I know of three options that can help you for a having scientific measure:

  1. Use a hardware specifically built for this. Monsoon HIGH VOLTAGE POWER MONITOR. https://msoon.github.io/powermonitor/PowerTool/doc/Power%20Monitor%20Manual.pdf
  2. Download and install Trepn Profiler (a tools from Qualcomm) on your phone. You wont need a computer for reporting. Reports are live and realtime on the phone. You can download Trepn Profiler from the following link: https://play.google.com/store/apps/details?id=com.quicinc.trepn&hl=en_US

Please take note that for recent phone (with android 6+) it works in estimation mode. If you need accurate numbers, you need to a list of select devices. Check the following link for the list: https://developer.qualcomm.com/software/trepn-power-profiler/faq You can profile apps separately, and the whole system.

  1. Use Batterystats and Battery Historian from google. https://developer.android.com/studio/profile/battery-historian
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!