当前位置:网站首页>App performance test: (IV) power

App performance test: (IV) power

2022-06-13 06:16:00 Ming ruoxiao River

app Performance testing :( Four ) Electric quantity

The following is an analysis of the electric quantity :
Attention should be paid to , Cell phone through USB Connecting to a computer , The phone will be in a state of charge , It must be ensured that the mobile phone is in a non charged state

  • Switch the non charging state
    command :adb shell dumpsys battery set status 1
    among status 1 Non charged ,status 2 Is in charge state
    namely

  • Switch to charging state
    command :adb shell dumpsys battery set status 2

  • Get electricity
    command :adb shell dumpsys battery

    (UPDATES STOPPED – use ‘reset’ to restart)
    AC powered: false
    USB powered: false
    Wireless powered: false
    Max charging current: 0
    Max charging voltage: 0
    Charge counter: 0
    status: 1
    health: 2
    present: true
    level: 30
    scale: 100
    voltage: 3764
    temperature: 200
    technology: Li-ion
    Monitoring script monitoring app Electricity consumption
    python3 Code :

     #/usr/bin/python
     #encoding:utf-8
     import csv
     import os
     import time
     
     # The control class 
     class Controller(object):
         def __init__(self, count):
             # Define the number of tests 
             self.counter = count
             # Define an array to collect data 
             self.alldata = [("timestamp", "power")]
     
         # Single test process 
         def testprocess(self):
             # Execute the command to obtain power 
             result = os.popen("adb shell dumpsys battery")
             # To obtain power level
             for line in result:
                 if "level" in line:
                     power = line.split(":")[1]
     
             # Get the current time 
             currenttime = self.getCurrentTime()
             # Save the obtained data in the array 
             self.alldata.append((currenttime, power))
     
         # Test process control many times 
         def run(self):
             # Set the phone to the non charging state 
             os.popen("adb shell dumpsys battery set status 1")
             while self.counter >0:
                 self.testprocess()
                 self.counter = self.counter - 1
                 # Every time 5 Collect data once per second 
                 time.sleep(5)
     
         # Get the current timestamp 
         def getCurrentTime(self):
             currentTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
             return currentTime
     
         # Data storage 
         def SaveDataToCSV(self):
             csvfile = open('power.csv', mode='w')
             writer = csv.writer(csvfile)
             print(self.alldata.__len__())
             writer.writerows(self.alldata)
             csvfile.close()
     
     if __name__ == "__main__":
         controller = Controller(5)
         controller.run()
         controller.SaveDataToCSV()
    
原网站

版权声明
本文为[Ming ruoxiao River]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202270556300065.html