标签:lld shel adb com popen [1] bat python sharp
一、监控指令:
adb shell dumpsys battery
level:电量
手机连接电脑时通常都在充电,这样测试就不准确了,需要设置到不充电状态,手机status不等于就不是充电状态
adb shell dumpsys battery set status 1
二、监控脚本:
#/usr/bin/python #encoding:utf-8 import csv import os import time #控制类 class Controller(object): def __init__(self, count): #定义测试的次数 self.counter = count #定义收集数据的数组 self.alldata = [("timestamp", "power")] #单次测试过程 def testprocess(self): #执行获取电量的命令 result = os.popen("adb shell dumpsys battery") #获取电量的level for line in result: if "level" in line: power = line.split(":")[1] #获取当前时间 currenttime = self.getCurrentTime() #将获取到的数据存到数组中 self.alldata.append((currenttime, power)) #多次测试过程控制 def run(self): #设置手机进入非充电状态 os.popen("adb shell dumpsys battery set status 1") while self.counter >0: self.testprocess() self.counter = self.counter - 1 #每5秒钟采集一次数据 time.sleep(5) #获取当前的时间戳 def getCurrentTime(self): currentTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) return currentTime #数据的存储 def SaveDataToCSV(self): csvfile = file(‘power.csv‘, ‘wb‘) writer = csv.writer(csvfile) writer.writerows(self.alldata) csvfile.close() if __name__ == "__main__": controller = Controller(5) controller.run() controller.SaveDataToCSV()
标签:lld shel adb com popen [1] bat python sharp
原文地址:http://www.cnblogs.com/wtao741/p/6240130.html