通过PC查询Android的CPU使用量的2种方法

已知 通过adb查询app 的cpu占用的命令是:

 

1 Linux:
2 adb shell top -m 10 | grep packagename
3 
4 Windows:
5 adb shell top -m 10 | FINDSTR packagename

则可以使用shell 完成监控app 的cpu使用量的监控

while true;do (adb shell top -m 10 -n 1 |grep com.jingdong.app.mall|tee -a cpu.log);done

 

另外,如果使用python,则有如下实现:

import os,time

def wCMD(cmd):
    #os.system(str(cmd))
    p = os.popen(cmd)
    rr = p.read()
    return rr

def timestamp():
    stamp = time.strftime('%Y-%m-%d_%H-%M-%S',time.localtime(time.time()))
    return stamp
    
def addText(path,text):
    a = open(path,'a')
    a.write(text)
    
def newfile(path):
    a = open(path,'w')
    a.write('')
    a.close()    
    
def getCpu(appNAME):
    command = 'adb shell top -m 10 -n 1 | '+ appNAME
    
    newfile('cpu.log')
    
    while True:
        a = wCMD(command)
        t = timestamp()
        text = t+"  "+a
        
        text=text.strip('\n')
        addText('cpu.log',text)
        print text,

getCpu('com.jingdong.app.mall')

  

posted @ 2018-05-24 21:54  白的云  阅读(163)  评论(0)    收藏  举报