from matplotlib import pyplot as plt from matplotlib import animation import os,re # import numpy as np def getTotalPss(): lines=os.popen("adb shell dumpsys meminfo com.rn_kiosk").readlines() # print(lines) total="TOTAL" for line in lines: if re.findall(total,line): lis=line.split(‘ ‘) # print(lis) while ‘‘ in lis: lis.remove(‘‘) return lis[1] # print(lis[1]) def getCpu(): li = os.popen("adb shell top -m 100 -n 1 -s cpu").readlines() name = "com.rn_kiosk" for line in li: if re.findall(name,line): cuplist = line.split(" ") # print(cuplist) if cuplist[-1].strip() == ‘com.rn_kiosk‘: while ‘‘ in cuplist: # 将list中的空元素删除 cuplist.remove(‘‘) return(float(cuplist[2].strip(‘%‘))) #去掉百分号,返回一个float # print(cuplist) # print((cuplist[2].strip(‘%‘))) # getCpu() fig = plt.figure() ax1 = fig.add_subplot(2,1,1,xlim=(0, 1000), ylim=(0, 350)) ax2 = fig.add_subplot(2,1,2,xlim=(0, 1000), ylim=(0, 100)) line,= ax1.plot([], [], lw=2) line2,= ax2.plot([], [], lw=2) x=[] y=[] y2=[] def init(): line.set_data([], []) line2.set_data([], []) return line,line2 def getx(): t = "0" return t def animate(i): x.append(int(getx())+i) y.append(int(getTotalPss())/1024) y2.append(getCpu()) print(x,y) line.set_data(x,y) line2.set_data(x,y2) return line,line2 anim1 = animation.FuncAnimation(fig, animate, init_func=init, frames=1000, interval=30) plt.show()