Android抓取Trace的正确方式

https://wiki.n.miui.com/pages/viewpage.action?pageId=610315534

trace抓取方法一:

进入systrace.py所在文件夹(/home/fuyao/Android/Sdk/platform-tools/systrace)

输入以下命令:

python systrace.py —time=10 -o trace_1.html

trace抓取方法二:

\1. 下载脚本:perfettotrace_1.sh

\2. 运行该脚本 sh perfettotrace_1.sh,滑动桌面

\3. 将产生的trace pull到当前文件夹下并命名为trace1 adb pull data/misc/perfetto-traces/trace ./trace1.html

\4. 打开当前文件夹 nautilus .

\5. ./trace1.html即为trace文件

trace的打开方法:

1.在该网址中打开 https://ui.perfetto.dev/#!/

2.也可将其转换为legacy UI 点击switch to legacy UI部分

trace文件转换:

python systrace.py —from-file ‘/home/hezhenqi/下载/bugreport/1-1.atrace’ -o trace_1.html

添加掉帧信息:

python atrace_parser.py -v 12 —output true —debug true -d ‘/home/mi/sda/mission/7_atrace/13-文件管理/1-41.atrace’

添加掉帧信息的脚本需要python2.7

sudo ln -sf /usr/bin/python2.7 /usr/bin/python

T版本抓取trace:

adb root;
adb shell "echo 1 > /d/tracing/tracing_on"
adb shell "echo 1 > /d/tracing/events/sde/enable"
adb shell "echo 1 > /d/tracing/events/sde/tracing_mark_write/enable"
python2 systrace.py sched load workq webview rs power database memreclaim freq idle am gfx view res dalvik binder_lock sm ss wm input audio video camera hal sync binder_driver i2c irq -o test.html

最新版本的Android studio是没有/Android/Sdk/platform-tools/systrace这个目录的需要重新下载。

systrace下载

Android systrace(platform-tools)下载

转换atrace格式文件:

python systrace.py —from-file=3-1.atrace -o test.html转换.html格式的trace文件

1.进入开发者选项 2.系统跟踪 3.打开显示快捷设置图块 4.控制中心中录制跟踪记录,点击开始,开始抓取trace, 5.滑动桌面 6.再次点击,结束