Android adb: 内存使用情况

内存,主要是统计pss值(实际使用的物理内存(比例分配共享库占用的内存)

adb命令:

adb shell dumpsys meminfo 包名
Android adb: 内存使用情况_第1张图片

完整的脚本如下:

#!/usr/bin/env python
# -*- coding: utf8 -*-
# 2017-03-28 

__auther__ = "youxian_tester "
__version__ = "v1.10"

import os
import random
import time
# from mobileDetecting import get_serialno

package_name = "com.jiuxi.marriage"

#get mobile sn
# phone_sn = get_serialno()
phone_sn = "xxxxxxxxx"

info = []

#统计pss值(实际使用的物理内存(比例分配共享库占用的内存)
def meminfo(phone_sn,apk_package_name):
    try:
        meminfo = os.popen("adb -s {0} shell dumpsys meminfo {1} | findstr TOTAL".format(phone_sn,apk_package_name)).read()
        pss = meminfo.split()[1]   
    except IndexError:
        pss = ""
    return pss

#获取内存pss值,并写入到文件
with open("mem.txt",'w+') as m:  
    for i in range(10): 
        pss_value = meminfo(phone_sn,package_name)
        time.sleep(2)
        m.write(pss_value +"\n")

你可能感兴趣的:(Android adb: 内存使用情况)