cpu

1.静默状态的cpu值(前台,后台)
2.正常主业务的流程的cpu值
3.一段时间使用的cpu值---稳定值(正常范围内)--不能一直升高

总结:adb shell dumpsys cpuinfo | grep com.android.contacts %进行分割第一个数据下标为0 time.sleep定时取数据存到csv文件

import csv
import os
import time

#adb shell dumpsys cpuinfo | grep com.android.contacts
#adb shell dumpsys cpuinfo findstr com.android.contacts---window

#控制类
class Controller(object):
def __init__(self, count):
self.counter = count
self.alldata = [("timestamp", "cpustatus")]

#单次测试过程
def testprocess(self):
result = os.popen("adb shell dumpsys cpuinfo findstr com.android.contacts")
for line in result.readlines():
#获得cpu数据行
if '%' and 'system'in line :
cpuvaule = line.split("%")[0]

print(cpuvaule)
currenttime = self.getCurrentTime()
self.alldata.append((currenttime,cpuvaule))

#多次执行测试过程
def run(self):
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 = open('cpustatus.csv', 'w')
writer = csv.writer(csvfile)
writer.writerows(self.alldata)
csvfile.close()

if __name__ == "__main__":
controller = Controller(10)
controller.run()
controller.SaveDataToCSV()
posted @ 2022-02-10 23:03  观呼吸  阅读(107)  评论(0)    收藏  举报