In this article I give a brief overview of power and performance optimization methodology on mobile devices. I hope it will help you better understand the challenges involved. I also provide instructions for how to measure device power consumption from the battery controller on Android.
Why is power and performance optimization so challenging on mobile devices? Let’s quickly review how power and performance optimization is performed in HPC (High Performance Computing).
The important metrics regarding power consumption in HPC are:
- Maximum power consumption - to calculate power plant and cooling equipment
- Performance per watt – to measure computational effectiveness
- Idle power consumption – to reduce power usage when no applications are running
Most of the optimizations for these metrics are done at the hardware or operating system level. Applications just need to process workloads as fast as possible; so it’s more about performance optimization. The first step is to implement the best algorithm and data structures for the task. The second step is to maximize the usage of all the available resources (nodes, network, accelerators, CPUs, cores, etc.) to reduce the time it takes to process a workload. When the workload is finished, the system switches to the idle state with minimal power consumption.
Power optimization on mobile devices is more complicated:
- Mobile devices contain a lot of hardware components
- Mobile devices typically don’t run computational workloads
The most important power metric for mobile devices from the user’s perspective is battery life. With a given battery capacity this metric directly depends on the device power consumption. So we will use device power consumption as the key metric.
Mobile devices have a lot of hardware components
Mobile devices have many hardware components:
- CPU
- GPU
- Wireless modules
- Wi-Fi*
- Bluetooth*
- LTE / 3G / GSM
- NFC
- Sensors
- Gyroscope
- Accelerometer
- Light sensor
- Proximity sensor
- GNSS
- Audio
- Display
- …
Each component consumes different amounts of power depending on how applications use them. For example, Wi-Fi may be enabled or disabled; the CPU may run on several frequencies; Display Brightness may be set to different levels, etc.
Device power consumption is the sum of all power consumption used by all the components.
Mobile devices typically don’t run computational workloads
We can relatively easily measure the performance of a game application. Basic game performance analysis is reviewed in the article Guidelines on How to Run a Basic Analysis for Android* Graphical Applications Using Intel® GPA tools.
Mobile devices typically execute one or more event-based applications. Latency and responsiveness are also important. An application may be using several hardware components.
Let’s take a look at the picture below:
This device has three active applications, each using several hardware components:
- CPU
- GPU
- Wi-Fi
- LTE
- GNSS
- Accelerometer
Other hardware components are disabled or set to idle mode.
It’s very important to find ways to reduce the number of active hardware components and also reduce the power consumption of each active hardware component. You’ll use different optimization strategies for each component.
The problem is when a single application extensively uses all the available hardware components, it can make all optimization efforts useless.
It’s hard to measure power consumption per component
So we have several important metrics: the device power consumption and the power consumption of each hardware component.
Total device power consumption can be measured from the battery controller. When a device is not connected to the charger, the battery is the only power source.
It’s not typically possible to directly measure a specific component’s power usage in watts (like the Wi-Fi module) without disassembling the device and using external hardware for measurements. Of course, we could measure indirect metrics like CPU frequency, network usage, screen brightness level, etc. Intel® Graphics Performance Analyzers (Intel® GPA) can be used for these indirect power measurements.
How to measure power from battery controller
It’s possible to measure device power consumption from the battery controller using Intel GPA System Analyzer from the GUI or Intel GPA Console Client from the command line.
It’s not practical to measure power with a USB connection because most devices will charge when connected via USB. It’s possible to switch ADB daemon on the device to TCP/IP mode and connect via a Wi-Fi network. The computer with the Android SDK and the Android device should be connected to the same Wi-Fi network.
Connecting the device with ADB over TCP/IP:
- Connect the device to host with USB cable.
- Run:
“adb tcpip 5555”
command on host. - Disconnect USB cable from the device.
- Discover the device’s IP address in Settings.
- Run:
adb connect
on host. - Check that the device is connected by running
“adb devices”
command.
After these steps the device is accessible using ADB but disconnected from all power sources except the internal battery. That’s why power measurements from the battery controller are the total power consumption for the device.
Collecting power metrics using Intel® GPA System Analyzer
Start Intel GPA System Analyzer and connect it to Android device. The Android device name will be the same as the one listed in “adb devices” command output.
A list of all installed applications will appear on the screen. All applications are divided into two categories: “Analyzable applications” and “Non-analyzable applications”.
Intel GPA can only analyze applications with the debuggable flag set in the application manifest on non-rooted device.
To prepare the application for analysis using Intel GPA:
- Open the AndroidManifest.xml file
- Add the Internet permission:
- Set the debuggable flag to true:
Another option is to collect power metrics using the “System Profiling -> System View” option. No application-specific metrics (like FPS) are available in this mode, but power metrics and other system-wide metrics are available in this mode.
The available power metrics are shown in the left panel:
Drag the metrics to the center to start measurement.
Collecting power metrics using Intel® GPA Console Client
You can also obtain power metrics using Intel GPA Console Client from the command line.
To obtain the list of all supported metrics run:
$ gpa-console-client -am
Typically, these power metrics are available:
# Power metric.hw.power.current_discharging # Current Discharging metric.hw.power.current_charging # Current Charging metric.hw.power.power_discharging # Power Discharging metric.hw.power.power_charging # Power Charging metric.hw.power.battery_voltage # Battery Voltage
Enter the following line into config.cfg
text file and run in “System View” mode:
$ gpa-console-client -an "System View" -cfg config.cfg
The tool will output metrics in CSV format.
To collect application-specific metrics you need to specify the application name in “-an
” parameter:
$ gpa-console-client -an "App Name" -cfg config.cfg
Intel GPA can only analyze applications with the debuggable flag set in the application manifest on non-rooted device as explained above for Intel GPA System Analyzer.
The list of all installed applications can be obtained using the following command:
$ gpa-console-client –al
Conclusion
This article reviews power and performance optimization on mobile devices. It contains the instructions for how to measure device power consumption on Android devices from the battery controller using Intel GPA. Device power consumption is a key metric in power optimization. Successful power optimization requires developers to reduce device power consumption.
Indirect power metrics like CPU frequency or network usage can help you identify which hardware component uses a higher percentage of the device’s power.
Related Resources and Articles
Intel® Graphics Performance Analyzers
Guidelines on How to Run a Basic Analysis for Android* Graphical Applications Using Intel® GPA tools
Using Intel® Graphics Performance Analyzers Console Client for Android* Application Performance Analysis
Developing Games with the Android* NDK and Intel® tools