Android App power consumption - android

How to check the power consumption in each applications in Android?
At least the power consumption should be relative when compared with different applications and these applications might be using any of the services like WIFI,GPS,LCD,wakelock, etc.
Are there any APIs in android regarding the same in order to measure the power consumption for the applications using the above resources?

There is a research paper called “Accurate Online Power Estimation and Automatic Battery Behavior Based Power Model Generation for Smartphones”. For this paper the researchers developed a tool called PowerTutor, the sources of which you can find here. It should be mentioned that your device has to be rooted to use this application.

First, the powertutor from Google Play is out of date. I've checked the source code of it, and find that the power estimation model is for some old mobile models. The value from power tutor is way smaller than the actual power consumption.
Therefore, I would recommend you to use Battery Historian which is developed by google used to estimate battery consumption of each App. But it's written in Python/Go. It will illustrate the hardware invocation in a html file. And you can find battery consumption of each App in a corresponding text file.
Battery Historian Example

Check out Powertutor. It is in my experience the best application out there to measure application wise power consumption. It is not 100% accurate but is good enough for estimations.

You cannot programatically check the battery consumption for each application.
Instead you can check the overall consumption like this:
energyLeftInmAh = device battery capacity in mAh * battery level in % * 0.01;
E.g
Nexus 5,
battery capacity: 2300 mAh
mBatteryManager = (BatteryManager)MainActivity.this.getSystemService(Context.BATTERY_SERVICE);
int level = mBatteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
double mAh = (2300 * level * 0.01);

(disclaimer: I co-founded the company which built the below mentioned product)
Try Little Eye from Little Eye Labs, that does exactly this. One can track an individual app's power and get the breakdown by CPU/display & Wifi (the upcoming version will support GPS and 3G). It also goes beyond power and tracks data, memory and CPU consumption of an individual app. Note its a desktop tool that you need to download and install from here.
Hope this helps.

One easy guide to see which is consuming how much battery from ICS onwards is to check Settings->Battery. Here it shows the % consumed by the app. Other ways could be to physically monitor battery drop by using the app intensively, for e.g. battery may be 80% before u start using the app. Then you try for 30 minutes and then check battery % again.

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.

How is it possible that Google Fit app measures number of steps all the time without draining battery?

The Google Fit app, when installed, measures the duration you are walking or running, and also the number of steps all the time. However, strangely, using it does not seem to drain the battery. Other apps like Moves which seems to record number of steps pretty accurately declares that it uses a lot of power because of it constantly monitoring the GPS and the accelerometer.
I imagine several possibilities:
Wakes up the phone every minute or so, then analyses the sensors for a few seconds and then sleeps again. However it seems that the records are pretty accurate to the minute, so the waking up must be frequent.
Actually turns on the accelerometer all the time, and analyzes it only after the accelerometer measurement data buffer is full. However I think the accelerometer has a small buffer to store the latest measurements.
Use GPS to estimate the number of steps instead of actually counting it. However this should not be the case, since it works even indoors.
The app still feels magical. Counting steps the whole time without perceptible battery drain.
Thanks for asking this question!
Battery is one of our top most concerns and we work hard to optimize Google Fit's battery usage and provide a magical experience.
Google Fit uses a mix of sensors(Accelerometer, Step counter, Significant Motion counter), Machine Learning and heuristics to get the data right. Our algorithm is pretty similar to your 1st option plus a little bit of magic.
We periodically poll accelerometer and use Machine Learning and heuristics to correctly identify the activity and duration.
For devices with hardware step counters, we use these step counters to monitor step counts. For older devices, we use the activity detected to predict the right number of steps.
Our algorithms merge these activities, steps and sometimes location to correlate and further increase accuracy.
We do not poll GPS to estimate steps or detect activities.
-- Engineer on Google Fit Team.
On some very recent phones like the Nexus 5 (released in late 2013 with Android 4.4 KitKat), there is a dedicated low-power CPU core that can serve as a pedometer. Since this core consumes very little power and can compute steps by itself without the need for the entire CPU or the GPS, overall battery use is reduced greatly. On the recent iPhones, there is a similar microcontroller called the M7 coprocessor in the iPhone 5s and the M8 in the iPhone 6.
More information here:
https://developer.android.com/about/versions/kitkat.html
http://nexus5.wonderhowto.com/how-to/your-nexus-5-has-real-pedometer-built-in-heres-you-use-0151267/
http://www.androidbeat.com/2014/01/pedometer-nexus5-hardware-count-steps-walked/
having a 3 year old HTC OneX I can say that THERE IS NO DEDICATED HARDWARE, Google Fit just uses standard sensors in a very clever way. I come from Runtastic Pedometer: there is a clear battery consume when in use, it would be impossible to keep it on all the time as it needs the full accelerometer power. On the other side, if you stand still and shake the phone Runtastic will count the shakes, while Google Fit apparently does nothing... Still it works perfectly when you actually walk or run. Magic.
Google fit try to learn use pedo step pattern and try to create its own personal walking patterns and its clusters. This eliminates the need of having huge mathematics calculations on receiving sensor data every time. This makes Google fit more power efficient compared other software pedo apps. Having said that, there is compromise on accuracy factors here. Between power-accuracy trade off, google seems to be more aligned towards power factor here.
At this moment the most power efficient detection happens Samsung flagship & its other high end models. Thanks to Samsung's dedicated hardware chip! No matter how power efficient your software pedo algorithm be but its hard to beat dedicated hardware unit advantage. I also heard about Google's bringing dedicated hardware unit for Ped upcoming nexus devices.
It would seem like the solution would be device dependent, with devices where a co-motion processor or "wimpier" core is available for low power operations, that it would default to this once the buffer is full or similar condition. With devices where a low-power core is not available, it seems like waking the device could trigger a JIT operation that would/should finish by the time the app is called.
While the Nexus 5 does have a dedicated "low-power" pedometer built in. It isn't as "low power" as you might think.
My Nexus 5 battery life was decreased by about 25% when I had Google Fit Activity Detection switched on.
Also, the pedometer doesn't show up in the battery usage stats. Presumably, because it is a hardware thing.
I don't know for the other phones out there, but Google Fit was really draining my battery life on my Nexus 5. Disabling it definitely improved my battery life.

Application Battery Consumption Tool

Is there a tool that would allow you to measure the battery used in milli amps or milli watts by your application on an iPhone or an Android. Specifically, I want to run my application with a few test cases, then be able to see how much more battery was used by me running the application versus the phone sitting idle. I was able to find a tool for Android here from Intel, however, it does not offer a similar solution for IOS. Preferably, I would like to use the same tool for both IOS and Android..
PowerTutor is an application for Google phones that displays the power consumed by major system components such as CPU, network interface, display, and GPS receiver and different applications. The application allows software developers to see the impact of design changes on power efficiency. Application users can also use it to determine how their actions are impacting battery life. PowerTutor uses a power consumption model built by direct measurements during careful control of device power management states. This model generally provides power consumption estimates within 5% of actual values. A configurable display for power consumption history is provided. It also provides users with a text-file based output containing detailed results. You can use PowerTutor to monitor the power consumption of any application.
http://ziyang.eecs.umich.edu/projects/powertutor/

Energy consumption of smartphone components

I'm looking for a list of all the components and their power drainage on an up-to-date smart phone.
Accelerometer, gyroscope, magnetometer, etc.
Display
WiFi
Bluetooth
GPS
CPU
Camera
Microphone
etc.
Preferably in mA so it can be easily compared to the battery's capacity (usually specified in mAh).
The Sensor's power is actually available via the SDK and can also easily figured out for most devices on AndroidFragmentation. However what I'm looking for is comparable data for the other hardware components to consider their efficency.
Bonus: Will a request for less frequent updates of a Sensor decrease energy consumption of the Sensor, as it returns only one value for getPower()?
There are a couple of detailed studies that I am able to find on this.
A study from the USENIX meeting in 2010 which studies various components of a smartphone (except the camera)
Another study from the Hotmobile mobile computing workshop 2013 that has more information on cameras and displays.
Reference 1 especially seems a great starting point.
I'm looking for a list of all the components and their power drainage on an up-to-date smart phone.
That is impossible to answer.
First, different devices will use different varieties of these components, with different power characteristics.
Second, many, if not most, of those components will have no published power statistics, or the specific components themselves may not be knowable without a complete teardown of a device.
Will a request for less frequent updates of a Sensor decrease energy consumption of the Sensor, as it returns only one value for getPower()?
That will depend on the sensor. Some sensors are effectively always "on" (e.g., ambient light sensor), courtesy of the OS, in which case the only incremental power drain for your use of that sensor will be in passing that sensor data to your process. Other sensors might not be regularly used by the OS, meaning that your request for events from that sensor might turn it "on", resulting in power drain from the sensor itself in addition to supplying you with that data.
It would be truly wonderful if all Android devices were instrumented in the way the Qualcomm MDP is, so that we could get fine-grained power detail for our apps and their usage of various components.
There was a Google I/O session on this very subject a few years ago; you can see the video here and slides pdf here.
I know it's against the rules to plug your own startup, but what you're asking sounds exactly like what we're working on.
There's an Android performance monitoring tool called "Little Eye Labs". It shows real-time power consumption of an App as it runs on a phone. It currently only supports CPU, Display, GPS, Wifi and 3G, but you'll be able to get the instantaneous power consumed (in mW) by these components.
/end of plug
Note that there's no real way to get this information directly from a device, so the best you can do is model the phone, gather device resource consumption, and model power usage.
Display is the most power consuming part of the smartphones; accounting for up to 60% of total battery life (Can draw power up to 2W). There is a book called Green IT and its Applications; you can read it online in Google books.
On any modern Android, go to Settings > Battery (sometimes Settings > About > Battery). You should see a graph of power drain over time, as well as how much was used by what component.
Although consumption varies a lot based on usage patterns, in my experience the top consumers are display, radio, and CPU. I have not seen sensors rank high in energy use on any of my devices, in the absence of bugs. The link provided by Yusuf X places game sensors above CPU.
For more information about optimizing battery use on Android, see Reducing the battery impact of apps that downloads content over a smartphone radio and Optimizing Battery Life.
There is an app called PowerTutor that it does some battery consumption measurements for every phone component and for every process. The code is open so you can pick up some ideas from there. Note that this app was optimized for Google's phone, especially for the Nexus One.

Power consumption for various colors in android

I wanted to measure the battery consumption of various colors in the range of 0-255 in android. Wanted to do it through an application. Currently I am using the PowerManager to measure the initial level of Battery and then keeping the screen bright for say 10-20 mins and check the final battery level, the difference giving me the usage in %. But I am getting weird results as in "white" uses same power as "black" (both having a drop of 4%). So I think my appraoch may be wrong. Can someone please suggest me to appraoch the problem in a correct way. Please help !!
I dont know what device you are using, but usually what really consumes the battery is the backlight, while the color is disposable in terms of power consumption.
(disclaimer: I co-founded the company that built the below product)
Try Little Eye from Little Eye Labs, which lets you track an individual apps power consumption and breaks it down into its various hardware usage, including display, CPU and wifi (and shortly GPS). Based on the pixel color and the brightness levels used, the power consumption trend of the app will vary, and Little Eye helps you visualize that quite easily. Note its a desktop product (which connects to your phone) that you need to download and install from here
There's an official power estimation tool called Battery Historian.It will create a text file which will show the power consumption of each component of the device in mAh.
I also suggest you to run you App for a longer time like 1 hour because the power consumption difference may be very small.
I hope this will help you.

Categories

Resources