1.首先需要获得应用的package name,拿微博来说:package name 为com.sina.weibo
2. 在cmd 中执行命令 adb shell top |grep com.sina.weibo
出现以下结果:
9231 0% S 89 270564K 40000K fg app_67 com.tuan800.android
9231为UID,然后执行如下python 脚本:
# -*- coding:utf-8 -*-
import os
sysInfo = os.popen("adb shell top -n 1").readlines()
#创建文件memoryinfo.txt
f1=open('memoryinfo.txt','a')
for info in sysInfo:
f1.write(info)
f1.close()
UID=‘9231’
f2 = open("memoryinfo.txt",'r')
while 1:
line = f2.readline()
if line.find(UID)==1:
print line
if not line:
break
pass
f2.close()
这样执行完后就可以查看应用对内存的消耗情况了
查看指定进程的内存情况:
# -*- coding:utf-8 -*-
import os
import re
sysInfo = os.popen("adb shell top -n 1").readlines()
#创建文件memoryinfo.txt
f1=open('memoryinfo.txt','a')
for info in sysInfo:
f1.write(info)
f1.close()
UID='app_67'
packName='com.sina.weibo'
f2 = open("memoryinfo.txt",'r')
while 1:
line = f2.readline()
if re.search(packName,line):
print line
if not line:
break
pass
f2.close()