1. 前言:
Perfetto工具是Android全新的统一的trace收集和分析框架,可以抓取平台和app的trace信息,是用来取代systrace的,但systrace由于历史原因也还会一直存在,并且Perfetto抓取的trace文件也可以同样转换成systrace视图,如果习惯用systrace的,可以用Perfetto UI的"Open with legacy UI"转换成systrace视图来看。
1.1 perfetto 文档地址:
https://perfetto.dev/docs/quickstarthttps://perfetto.dev/docs/quickstart
1.2 perfetto UI工具地址:
Perfetto UIhttps://ui.perfetto.dev/
1.3 perfetto 主页面
Perfetto - System profiling, app tracing and trace analysishttps://perfetto.dev/
1.4 Trace Viewer界面:
2. 如何使用
2.1 使用google python工具:record_android_trace
2.1.1 下载地址:
2.1.2 下载并使用
Linux:
下载:
curl -O https://raw.githubusercontent.com/google/perfetto/master/tools/record_android_trace
修改权限:
chmod u+x record_android_trace # See ./record_android_trace --help for more
执行:./record_android_trace -o trace_file.perfetto-trace -t 10s -b 32mb \ sched freq idle am wm gfx view binder_driver hal dalvik camera input res memory
Windows:
下载:
curl -O https://raw.githubusercontent.com/google/perfetto/master/tools/record_android_trace
执行:
python3 record_android_trace -o trace_file.perfetto-trace -t 10s -b 32mb \ sched freq idle am wm gfx view binder_driver hal dalvik camera input res memory
2.2 ADB Shell 直接运行 perfetto抓取trace
运行shell:
adb shell perfetto -o /data/misc/perfetto-traces/trace_file.perfetto-trace -t 20s \ sched freq idle am wm gfx view binder_driver hal dalvik camera input res memory
2.3 通过perfetto config 抓取 trace
2.3.1 配置perfetto
>配置完后:
> 拷贝文件,删除头跟尾
> 删除后,保存文件为 perfetto_config.pbtx
2.3.2 更新设备perfetto config
adb push perfetto_config.pbtx data/misc/perfetto-traces/
2.2.3 执行,抓取trace
adb shell perfetto --txt -c data/misc/perfetto-traces/perfetto_config.pbtx -o data/misc/perfetto-traces/trace_file.perfetto-trace
导出:
adb pull /data/misc/perfetto-traces/trace_file.perfetto-trace
2.4 分析
用工具打开trace_file.perfetto-tracePerfetto UIhttps://ui.perfetto.dev/#!/record