Android CPU Power consumption test

Source: Internet
Author: User

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
    1. install battery management software, Butler, guardian of a class of software.
    2. Read the Android kernel log yourself, power change broadcast, etc.
    3. 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:

    1. Crawl CPU time consumed by the specified app
    2. Get CPU run time at each frequency
    3. 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" > &LT;VALUE&GT;577&LT;/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
  1. get pid, ADB Shell PS | grep {appName} or adb Shell Top-n 1 | grep ${appname}
  2. 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.
  3. Keep going cat /proc/${pid}/stat , get CPU time, minus the second step of T1, that's the time the app's CPU takes.
  4. 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.
  5. http://www.yeetrack.com/?p=1045

Android CPU Power consumption test

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.