How to measure energy consumption with Monsoon
An easy tutorial with Physalia
In this tutorial we are going through how to measure the energy consumption of your mobile application using the Monsoon Power Monitor with the smartphone Nexus 5X.
Writing energy efficient code is very important when it comes to mobile applications development. However, having a setup for energy measurements can be a complex task. Besides, most developers (like us) don't have the knowledge required to do it without some help.
In this article we show how we have set up our experiments. We go over how to open a Nexus 5X and connect it to a power monitor. This can help developers easily start measuring their Android apps.
Warning: The procedure described in this article will void the phone's battery. It will no longer be appropriate for use with the device. Since the procedure requires opening the Nexus 5X, the device's warranty will be voided. This article intends to make things simple, but the authors cannot take responsibility for any possible harm it may cause. Do it at your own risk.
Material needed
- Nexus 5X
- Monsoon Power Monitor
- Computer
- Electronic Wire
- Pliers
- Soldering iron
Opening Nexus 5X
In order to measure energy consumption we have to replace the battery with our new power supply — Monsoon. This means that we need to remove the battery!
This task used to be simpler, however most phones nowadays do not come with a replaceable battery. The phone has to be opened. There are many tutorials online that make it simple by going through all the steps. It is the case of this one from iFixit.
Bypassing the battery
Now that we removed the battery we can see that it no longer comes with two traditional positive and negative connectors. It comes with a very small plug, which makes it hard to make a proper and isolated connection. In addition, the battery also sends a digital code that is required to make the phone work. Unfortunately, this code cannot be replicated by the power monitor.
Basically this means that our battery comes with two main parts: battery cells that provide the power and an integrated electronic component that, among other things, generates the required signal.
The cleanest solution is to disassemble the battery, and separate the cells from the electronic component. Be aware that this part requires extra care. Battery cells must be intact, and positive and negative connectors must always be isolated from each other.
Start by removing the soft cover on the top of the battery as shown in the picture. The component we need is the one with a rigid black cover. Detach it from the cell and remove the cover with the help of a pliers. Note that this point is irreversible.
The cell was connected to the electronic component simply by the negative and positive poles. As shown in the figure below, solder a black and a colored wire to these connectors in the electronic component. As a standard rule, connect the black to the negative pole, and the colored (usually red) to the positive. Use electrical tape to insulate the solderings.
Now we can assemble our component back to the phone.
The phone is ready to be connected to Monsoon!
Connecting Monsoon to the phone
Monsoon comes with two handy wires to connect the power supplier. Connect them to the wires in the phone. Positive pole with positive pole and negative pole with negative pole — i.e., black with black and colored with colored.
Controlling Monsoon from a computer
Open a terminal window and install Physalia:
$ pip install physalia
Now open your favorite editor and create a simple Python script:
# myscript.py import time from physalia.power_meters import MonsoonPowerMeter from physalia.energy_profiler import AndroidUseCase power_meter = MonsoonPowerMeter(voltage=3.8, serial=12886) def run(_): time.sleep(5) use_case = AndroidUseCase('physalia-simple-tutorial', None, 'na', 'na', run=run) measurement = use_case.run(power_meter=power_meter) print measurement
This script basically sets Monsoon's power supply to 3.8V and measures energy consumption for 5 seconds. Be sure to change serial
to your Monsoon's serial number.
Run it with:
$ python myscript.pyAfter finding and connecting Monsoon, it prompts to turn on the mobile device. Once Nexus 5X is up and running, connect it through USB to the Monsoon. If everything goes as expected, the script will give you the energy spent during five seconds expressed in Joules (J).
It's done!
Good job! Now feel free to play around and explore the rest of Physalia. It comes with many other features that make energy measurements easy for Android apps. Note that, for safety reasons, it is recommended to reassemble the other parts of the phone.
If you need extra help or have feedback, get in touch!
Acknowlegments
Kudos to Prof. Ricardo Chaves for the valuable help given to set up Monsoon. He has the credits for disassembling the battery, soldering, and specially for coming up with this solution to bypass the battery. We did not have the knowledge to do it by ourselves. We hope this article will help developers that cannot count on the help of a Prof. Ricardo.