一段获取app性能指标的py脚本

本文介绍了一种通过ADB命令实现的安卓应用性能监控方法,包括CPU占用率、内存使用情况、垃圾回收状态等关键指标的抓取,并记录了应用启动时间、网络数据交换及电量消耗等信息。

#coding:utf-8

import os
import time
import datetime
import subprocess


ActivityManager = 'homepage.MainFragmentActivity'
package_name = 'XXXX'
#获取系统当前时间
now_time = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')

#分别通过adb获取各项监控指标
subprocess.Popen("adb shell top > App_cpu_%s.txt" % now_time,shell=True)
subprocess.Popen("adb shell top > App_memory_%s.txt" % now_time,shell=True)
subprocess.Popen("adb shell dumpsys meminfo %s > Meminfo_%s.txt" % (package_name,now_time),shell=True)
subprocess.Popen("adb logcat | findstr ActivityManager > Start_Time_%s.txt" % now_time,shell=True)
subprocess.Popen("adb logcat | findstr GC > GC_Data_%s.txt" % now_time,shell=True)
subprocess.Popen("adb logcat -v time *:E | findstr > NetWorkFile_Data_%s.txt" % now_time,shell=True)
subprocess.Popen("adb logcat -v time *:E | findstr battery > batteryFile_%s.txt" % now_time,shell=True)

print u'日志正在记录中。。。请稍后'
print u'界面启动时间正在记录。。。请稍后'
print u'应用功能cpu占用率正在记录。。。请稍后'
print u'应用GC回收和使用时间正在记录。。。请稍后'
print u'应用内存正在记录。。。请稍后'
print u'应用网络数据正在记录。。。请稍后'
print u'应用电量数据正在记录。。。请稍后'

time.sleep(2)
print u'报告正在生成'

转载于:https://www.cnblogs.com/nzg-noway/p/6525870.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值