码迷,mamicode.com
首页 > 移动开发 > 详细

python获取安卓app性能参数并绘图

时间:2018-10-26 13:10:33      阅读:367      评论:0      收藏:0      [点我收藏+]

标签:can   pre   div   nes   plist   [1]   imp   add   lines   

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()

 

python获取安卓app性能参数并绘图

标签:can   pre   div   nes   plist   [1]   imp   add   lines   

原文地址:https://www.cnblogs.com/paul-wang/p/9855576.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!