In app battery usage - android

Is there any way to determine what is using power in an app? From what I have found, the most granular I can get is how much power an app itself is using. I want to know what I can do to make my app more efficient in the most empirical way possible as it is easy to justify a change when there are numbers to back it up.

Is there any way to determine what is using power in an app?
You can buy a Qualcomm MDP device and use Trepn to get fairly accurate and detailed power analysis of your app. However, an MDP is expensive.
Otherwise, there is little you can do, simply because current Android production hardware is not instrumented to try to collect this level of information. Even the Battery screen in Settings is mostly just an educated guess.

Related

Android Power consumption of a method

For a research project I need to measure the power consumption of some functionality. So I would like to measure the power consumption of a method. For example: method computeSomething() needed x microampere-hours. Is this possible? If yes, how?
I tried to measure the remaining battery capacity in microampere-hours and the remaining energy in nanowatt-hours before and after execution with the BatteryManager. But this isn't accurate enough. Is that even possible to do it?
this is what i tried:
mBatteryManager.getLongProperty(BatteryManager.BATTERY_PROPERTY_ENERGY_COUNTER);
EDIT:
for sure it's the emulator which don't consume energy and that's why I get a consumption of 0. Is it possible to simulate power consumption with the android emulator or do I need a real phone?
Here's how I would measure the energy used (because that's what you want and not power).
Shutdown (or don't use) everything I can, including network, cell, USB, etc.
Disable any power saving features on the phone
Log any data you get on the phone's file system (vs through the USB or wireless)
Wrap the program in a large loop that makes its runtime at least a few seconds, perhaps a few minutes
Run the test program you just made many times (>=16 times for statistical significance)
Measure the phone at rest over the same amount of time and collect the energy used.
ANALYSIS: (and you need to do this)
Check on the statistical deviation (std dev) of both your function run and the "at rest" run. If the std dev is large, something else is going on that is using energy.
Find out the resolution of BatteryManager. Just because the field is labeled in nWatts doesn't mean the hardware measures it at that resolution (and it probably doesn't). The people who develop a data structure want that structure to be useful on a lot of hardware and for the foreseeable future. Thus they make the field measure in something very small (e.g. nWatts) even if most hardware can only measure at best, say, in tenth of watts.
If possible, use a hardware interposer between the battery and the phone to measure energy/power directly. This gets around the uncertainty in the implementation of BatteryManager.
Just to be safe, you might also find out how long of an integration window the BatteryManager uses for measuring power. These measurements usually involve a moving window for computing averages.
An emulator isn't going to give you any useful information. Emulators test functionality and little else. Even a rough measure of performance is very iffy.
I've developed a similar App before but is used to evaluate the power consumption of each Application. But as far as I know, the Google's battery static API evaluate power consumption according to each UID, both hardware and software. I think you can find more information by looking into the source code of Android, especially for BatterySipper.java and BatteryStatsHelper.java.
For emulator, Android system uses power_profile.xml as reference to calculate the power consumption. This file is usually modified by manufacturer. Maybe it's not included in emulator.

Android Battery level in mA

I need to get statistics about the battery in milliAmpere.
I've already found how to get the battery percentage and voltage but not the current.
There are applications like this that can do it but i wonder how.
Thank you
I believe the only way to get the current is via the logcat. The system will occasionally post it to there so you'll need to go back find the last update for it.
There is no way of measuring current drawn from within the system - this or any other app can only estimate it based on timing information and voltage discharge that the system reports. You are not likely to have anything accurate based on just that though - to have more accurate information you need an accurate device power model.
There is a nice article by the Android framework guys about how the power model is built (also applies to the built-in battery power monitor).
TL;DR
Measurement can be accomplished using a bench power supply or using specialized battery-monitoring tools (such as Monsoon Solution Inc.’s Power Monitor and Power Tool software).
Need to control what components of the device are active (screen on/off/brightness level, cellular/wifi/bluetooth radio, gps, CPU, etc.)
Based on those you build an energy profile similar to the example at the bottom of the page
There are also typical values in the table in the document. Warning: these are highly hardware-dependent
You can then apply the model by monitoring the state of the device and activities of applications (screen state, foreground/background, CPU/network use by an app, etc.)
This is a lot of hard work (sorry about that :) ), but there isn't another good way - it is actually an active research problem...

Monitoring per Application power usage in android

Is there a way to get the average current/power consumption of a particular application in Android? I could only find private API PowerProfile.java and PowerUsageSummary.java which give some information, but I am hitting a dead end, can someone please help?
Is there a way to get the average current/power consumption of a particular application in Android?
No, because applications do not consume current/power. Hardware does. If six applications are using WiFi, it is very difficult to "assign blame" for the WiFi power consumption, for example.
Now, even getting hardware power information is difficult in Android, as there are no public APIs for it, and most hardware is not instrumented particularly well to indicate what is consuming power. The Qualcomm MDP has great instrumentation for this, along with Trepn software to help you collect it, but it is rather expensive.

make display to remain turn on

I want to have my control to make display remain turn on on some event and release my control on display turn on/off based on some other event. I know that I can easily do this using wakelock. But device battery life will be significantly affected by the use of this API. Is there any other way to do so?
It is good that you are considering battery consumption in your app, however, what you are effectively asking is if there's any way to make the display use less power, since regardless of the method used to keep it on, you are keeping the display on.
Since the display is usually the largest battery drain on modern smartphones, I'm afraid the answer is no, there is no way to keep the display enabled and at the same time significantly reduce power consumption.
You may be able to dim the display, but that is unlikely to result in a significant power saving and WakeLocks are the correct way to use this functionality.
Battery life will be significantly affected by your app keeping the scree on all the time, so you must think twice if you want your app to use this functionality. If you indeed need this option, you can use getCurrentFocus().setKeepScreenOn(true); Hope this helps.

Android Power Profiler

I need to perform power measurements for android applications. I tried "powertutor" and it gives the power consumption per every application. Yet, I don't know how accurate its readings are. Does anyone know how accurate it is?
Also, I have used the DDMS to profile the android application. I obtain the processes as memory info about it. Is there a way that i can know the power consumption per process in Android? (some rough estimation?) or is it impossible?
I really need to perform "power" profiling for android applications but I don't know how.
In my academic research for measuring power consumption on Android, we use a power supply hooked up to the phone's battery terminals that outputs the voltage and current to a PC. Measure without the app to get a baseline and then compare against measurements with the app running. It's not extremely accurate, but it's the best way we know how.

Categories

Resources