Android性能分析工具记录

本文介绍了如何使用LeakCanary进行内存泄漏检测,通过Systrace分析应用卡顿,以及Perfetto的高级trace收集和分析。涉及技术包括gradle配置、ddms使用、Python配置及命令行操作。

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

0.Profiler

分析内存泄漏

分析调用堆栈?

 

1.leakcanary 检测内存泄漏

gradle:debugCompile 'com.squareup.leakcanary:leakcanary-android:1.6.1'

@Override

public void onCreate() {

    super.onCreate();

    if (BuildConfig.DEBUG){

        if (LeakCanary.isInAnalyzerProcess(this)) {

            // This process is dedicated to LeakCanary for heap analysis.

             // You should not init your app in this process.

            return;

        }

        LeakCanary.install(this);

    }

}

 

2.systrace: 检测卡顿

打开ddms的方法:

异常Failed to load the jvm library.

解决方案:https://stackoverflow.com/questions/59415053/javavm-fatal-failed-to-load-the-jvm-library

使用方法:

https://blog.csdn.net/vicwudi/article/details/100191529

使用ddms抓去trace.html遇到chrom无法解析的异常,于是采取以下方法:

https://blog.csdn.net/r_Jimy/article/details/116789902

首先安装python(Mac自带了):

https://docs.python.org/zh-cn/3/using/mac.html

然后配置mac的adb环境变量:

https://blog.csdn.net/wt9402/article/details/52369417

抓取命令:

cd /Users/xiaoguagua/Library/Android/sdk/platform-tools/systrace

python systrace.py -b 8000 -t 5 -o systrace.html

在chrome输入:chrome://tracing

查看文件

分析教程:https://blog.csdn.net/vicwudi/article/details/100191529

 

3.Perfetto:

Android下一代全新的统一的trace收集和分析框架,可以抓取平台和app的trace信息,可以显示为systrace,有图形化配置,使用极其简单。

工具地址:

https://ui.perfetto.dev/?spm=ata.21736010.0.0.6b827d98BrZGjA#!/

使用参考:

https://developer.android.google.cn/studio/command-line/perfetto

https://www.jianshu.com/p/ab22238a9ab1

https://blog.csdn.net/zhendong_hu/article/details/103858660

部分功能对设备的android版本有要求,比如帧率扫描需要android12以上。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值