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

时间:2022-11-11 07:05:51

#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'报告正在生成'