一、App启动性能分析

1、基本的测试checklist和手段

image.png

2、专项测试(用户维度)

  • 崩溃(Crash,弱网)
  • 卡顿(掉帧、gc、cpu)
  • 响应慢(启动时间、交互响应、H5加载)
  • 发热(cpu,mem、io、network、gps等硬件使用)
  • 掉电快(硬件占用)
  • 兼容性问题(机型覆盖、回归)

3、专项测试(技术维度)

  • 崩溃
    • 自动遍历、monkey测试、横竖屏切换、快速进退
  • 卡顿(掉帧、gc、cpu)
    • 卡顿测试、内存泄漏测试、method profile
  • 响应慢(启动时间、交互响应、H5加载)
    • 冷热启动、界面切换、h5性能测试
  • 发热(cpu,mem、io、network、gps等硬件使用)
    • method profile、gc统计、io统计、流量统计、硬件使用统计、耗电量分析
  • 兼容性问题(机型覆盖、回归)
    • 兼容性测试、自动化测试、自动遍历、monkey测试

4、App性能

Activity启动流程

image.png

主要流程

  • Application OnCreate
    • 加载第三方的sdk
  • Activity OnCreate
    • 加载自身的逻辑
    • 发送远程数据请求xxx.json
    • 渲染界面List

App启动性能指标

  • 冷启动:在进程中已被kill掉,或者刚安装好的app。不包括other stuff的时间。(最重要)
  • 暖启动:App在后台运行久了,内存系统将其kill掉,此时进行重启App,会保存App的一些初始化设置。不包括other stuff的时间。
  • 热启动:App在后台运行。不包括other stuff的时间。
  • 首屏启动:加上other stuff的时间,比如动图加载等。

建议时间

  • Cold startup takes 5 seconds or longer.
  • Warm startup takes 2 seconds or longer.
  • Hot startup takes 1.5 seconds or longer.

5、主要工具及流程

  • adb logcat
  • 录屏+视频拆帧
  • uiautomator等自动化工具200ms巡检界面变化
  • traceview
  • 硬埋点

使用adb logcat

  • package=com.xueqiu.android
  • 清理缓存数据: adb shell pm clear $package
  • 停止进程: adb shell am force-stop $package
  • 启动app: adb shell am start -S -W $package/.view.WelcomeActivity Alias
    • -S在启动之前停止app,起保险作用
    • -W等待Activity启动完成
  • 获取数据: adb logcat lgrep -i displayed

adb logcat结果

  • startTime:记录刚准备调用startActivity AndWait()的时间点;
  • endTime:记录startActivityAndWait()函数调用返回的时间点
  • WaitTime: startActivity AndWait()调用耗时
    • WaitTime = endTime - startTime

实战

image.png

image.png

6、使用ffmpeg拆针

adb shell am force-stop $package #停止app
adb shell screenrecord --bugreport --time-limit 30 /data/local/tmp/xueqiu.mp4 & #进行录屏并保存视频到手机路径
adb shell am start -S -W $package/.view.WelcomeActivityAlias
wait
adb pull /data/local/tmp/xueqiu.mp4 . #将视频推到本地
ffmpeg -i xueqiu.mp4 xueqiu.gif #将视频合成动图
ffmpeg -i xueqiu.mp4 -r 10 frames_%03d.jpg #1秒拆成10针
  • 实战


    image.png

    image.png
    • 图片拆分结果:


      image.png

下一节:接口性能分析,包括DNS、HTTP/HTTPS的接口性能分析。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容