Android CPU Power consumption test
When testing Android apps, don't just focus on the app's features, but the app's performance metrics, CPU, memory, traffic, power, and more. Briefly describe the CPU power consumption in the battery test.
Factors that affect power consumption
- Cpu
- Screen
- Network (3g/wifi)
- Sensor & GPS
- WakeLock
- ...
Battery test method
- install battery management software, Butler, guardian of a class of software.
- Read the Android kernel log yourself, power change broadcast, etc.
- physical device, ampere wheel, etc.
The main introduction here is to read the kernel file, calculate the CPU power consumption.
The main steps are as follows:
- Crawl CPU time consumed by the specified app
- Get CPU run time at each frequency
- According to different power consumption at different frequencies, the total consumption is calculated.
Power_profile. Xml
Every Android device has such a file that defines the power of each hardware. Different phone, the content is different. I have the following (unit mah, meaning one hours, can consume how much mah):
<?xml version= "1.0" encoding= "Utf-8"?> <device name= "Android" > <item name= "None" >0</i tem> <item name= "Screen.on" >71</item> <item name= "Bluetooth.active" >17</item> <item name= "Bluetooth.on" >0.3</item> <item name= "Screen.full" >380</item> &L T;item name= "Wifi.on" >0.3</item> <item name= "wifi.active" >96</item> <item name= "wi Fi.scan ">70</item> <item name=" Dsp.audio ">44</item> <item name=" Dsp.video ">280& lt;/item> <item name= "radio.active" >250</item> <item name= "radio.scanning" >82</ite m> <item name= "Gps.on" >1</item> <array name= "Radio.on" > <value>3.4& lt;/value> <value>3.4</value> </array> <array name= "Cpu.speeds" > <value>12000000</value> <value>10000000</value> <value>800000</value> <value>500000</value> <value>200000</value> </array> <i TEM name= "Cpu.idle" >4</item> <array name= "cpu.active" > <VALUE>577</VALUE&G T <value>408</value> <value>249</value> <value>148</value> <value>55</value> </array> <item name= "Battery.capacity" >2100</item> </device>
How to get Power_profile.xml file
The file exists in the/system/framework/framework-res.apk package of the phone, you need to use Apk-tool to decompile the APK, decompile, in the $output/res/xml folder.
Get app Execution time
- get pid,
ADB Shell PS | grep {appName}
or adb Shell Top-n 1 | grep ${appname}
- Get PID execution time,
cat/proc/${pid}/stat
, the 14th column in this file is added to the 17 column to get the total amount of CPU time (set here to T1) from boot to the moment. Here the unit is jiffies, this unit means the number of CPU operations, if the CPU frequency is 1G, then 1 jiffies = 1/1g seconds.
- Keep going
cat /proc/${pid}/stat
, get CPU time, minus the second step of T1, that's the time the app's CPU takes.
- Gets the operating probability of the CPU at different frequencies. The Android CPU will work at different frequencies,/sys/devices/system/cpu/cpu0/cpufreq/stats/time_instate
Put the CPU in each frequency band occupy time, note is the entire system occupies the time, according to this probability, calculates the CPU each frequency working time, then multiplies the unit power consumption which is defined in the Power_profile.xml, accumulates obtains the CPU to consume.
- http://www.yeetrack.com/?p=1045
Android CPU Power consumption test