Android性能分析工具perfetto (1)pefetto抓trace

1. 启动perfetto关联进程

        perfetto依赖traced、traced_probes等进程,首先检查这两个进程是否已经启动,如果没有启动,则设置属性adb shell setprop persist.traced.enable 1启动这些进程。

2. perfetto配置

(1)模式选择

        Stop when full模式:当缓存的数据大小超过In-memory buffer size,或者抓取时长超过Max duration,都会自动停止抓取

        Ring buffer模式:当时长超过Max duration时会自动停止抓取,当数据大于In-memory buffer size时会循环覆盖前面的数据

 

        Long trace模式:每隔Flush on disk every时长,就会将内存中的数据缓存到Flash上,文件最长Max file size;内存中的数据达到In-memory buffer size时还没有缓存到Flash上,会循环覆盖;超时Max duration后,停止抓取。 

(2)atrace配置

        以下界面中选取要抓取哪些模块的atrace

(3)trace event配置

        如下界面中选取抓取哪些模块的atrace,并且配置ring buffer的大小,和间隔多久去读取ring buffer。

 

(4)保存配置文件

        Saved configs中把配置内容保存到指定文件。

3. perfetto抓trace命令

(1)把配置文件push到手机,要放到shell用户有权限访问的目录,一般放在/data/misc/perfetto-configs/

(2)抓取trace

adb shell perfetto --txt -c /data/misc/perfetto-configs/xxx.pbtx -o /data/misc/perfetto-traces/trace_file.perfetto-trace

(3)离线抓取

adb shell perfetto --txt -c /data/misc/perfetto-configs/xxx.pbtx -o /data/misc/perfetto-traces/trace_file.perfetto-trace --detach=perf_debug

离线抓取可以主动停止adb shell perfetto --attach=perf_debug --stop

4.perfetto大文件解析

        抓取到的文件在网页Perfetto UI上完成可视化,当trace文件大于1G时,浏览器会提示文件过大,并提供了解决办法。但是这个解决办法只适用于Linux开发环境。

        在windows上需要下载windows-amd64.zip,下载链接为https://github.com/google/perfetto/releases/,选择最新的版本下载。

        运行命令:trace_processor_shell.exe --httpd trace路径

        trace文件load完毕后,打开perfetto网站,会自动弹出如下提示,选择即可 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值