Android 抓取 trace 文件

781 阅读1分钟
  • 命令行 抓 trace
atrace -c -t 10 -b 20480 gfx view input webview wm am sm audio video camera hal dalvik res rs bionic pm ss database network disk sched freq idle binder_lock binder_driver -o /data/local/tmp/963.trace

adb pull /data/local/tmp/963.trace   C:\Users\xiangxiang1.liu\Desktop\walleve\全链路响应速度对比\原生demo
  • perfetto 抓 trance
adb shell perfetto -o /data/misc/perfetto-traces/trace_file.perfetto-trace -t 15s \ sched freq idle am wm gfx view binder_driver hal dalvik camera input res memory

参数解释:
-o : 指定 trace 文件的输出路径
-t : 表示抓取的时间,这里设置了 20s,默认情况下是 10s
sched freq idle am wm gfx view binder_driver hal dalvik camera input res memory: 里表示我们想要抓 trace 的相关模块
  • perfetto
perfetto --time 30s --buffer 512mb gfx view input wm am sm audio video hal dalvik res rs bionic pm ss database disk sched freq idle binder_lock binder_driver --out /data/misc/perfetto-traces/fps.pftrace

  • 使用代码方式抓取
//storage/emulated/0/Android/data/com.xx/files/search_launch.trace
Debug.startMethodTracingSampling(File(Utils.getApp().getExternalFilesDir(null), "search_launch.trace").absolutePath, 8 * 1024 * 1024, 1000)


Debug.stopMethodTracing()

导出文件
1. 拷贝到 u 盘: 进入到 

cp search_launch.trace  /mnt/sdcard/ 

2.u 盘拷贝到电脑
adb pull /mnt/sdcard/search_launch.trace   F:\document