APP专项测试

该代码段用于统计APP的启动时间,通过adb命令执行并记录每次启动的总时间,然后使用pyecharts绘制启动时间的折线图。此外,提到了清理缓存数据和停止进程的adb命令,以及监控APP占用CPU和内存的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

APP启动时间统计

启动10次app

import subprocess,time
from pyecharts.charts import *

current_activity = "com.v2ay.ang/.ui.MainActivity"
cmd1 = "adb -s ANP4C20410007003 shell am start -S -W " + current_activity + " | findstr TotalTime"
print(cmd1)  # adb -s ANP4C20410007003 shell am start -S -W com.v2ay.ang/.ui.MainActivity | findstr TotalTime

start_list = []  # ['第1次', '第2次', '第3次', '第4次', '第5次', '第6次', '第7次', '第8次', '第9次', '第10次']
time_list = []  # [' 263', ' 329', ' 263', ' 256', ' 262', ' 263', ' 275', ' 266', ' 258', ' 268']
for i in range(1, 11):
    start_list.append('第{0}次'.format(i))
    console = subprocess.getstatusoutput(cmd1)
    total_time = list(console)[1].split(": ")[1]
    time_list.append(total_time)
    time.sleep(1)
print(time_list)
print(start_list)

line = (
    Line().add_xaxis(start_list).add_yaxis('', time_list)
      )
# line.render_notebook()
line.render()

绘成折线图

# 包名:com.v2ay.ang
清理缓存数据:adb shell pm clear com.v2ay.ang
停止进程:adb shell am force-stop com.v2ay.ang

获取数据:adb logcat |grep -i displayed

 APP占用CPU及内存统计

思维导图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值