import datetime
import subprocess
import time
import os
import re
import threading

si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW

dev_list =[]

def get_devices():
devices = []
result = subprocess.Popen("adb devices", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.readlines()
# print(result[1].decode())
#print(len(result))
if len(result)-2 == 1:
for line in result[1:]:
devices.append(line.strip().decode())
#print(devices[0].split()[0])
return devices[0].split()[0]
else:
print('No device')
return 'No device found'

def get_monkey():
os.popen("adb shell monkey -p com.kugou.android.ringtone --throttle 500 -s 1000 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -v -v -v 1000 >D:\monkey_log.txt").readlines() # 逐行读取

def getBerforeTotalPss():
lines = os.popen("adb shell dumpsys meminfo com.kugou.android.ringtone ").readlines() # 逐行读取
total = "TOTAL"
for line in lines:
if re.findall(total, line): # 找到 TOTAL 这一行
lis = line.split(" ") # 将这一行,按空格分割成一个 list
while '' in lis: # 将 list 中的空元素删除
lis.remove('')
#return lis[1] # 返回总共内存使用
print('前端应用的内存是:',int(lis[1])/1024,'M')
break

def getPss():
print('z 来到这里吗')
t=time.time()
i=5
t1 = time.time()

while t1 - t <= 5:
t1 = time.time()
print('看看这里')
getBerforeTotalPss()
print('----------------------------------------------------------------------------------------------------')
time.sleep(1)

if name == "main":
print('测试开始啦。。。。{}'.format(time.ctime()))
threadl = []
t1 = threading.Thread(target=get_monkey())
t2 = threading.Thread(target=getBerforeTotalPss())
t1.start()
t2.start()
t1.join()
t2.join()
print('测试结束啦。。。。{}'.format(time.ctime()))


↙↙↙阅读原文可查看相关链接,并与作者交流