Perfetto Trace抓取

本文介绍了Perfetto,Android系统的新一代性能追踪工具,对比Systrace具有多进程追踪和便捷分析功能。详细讲解了轻量模式和普通模式的抓取方法,以及如何配置和打开Perfettotrace文件进行分析。
摘要由CSDN通过智能技术生成

1. Perfetto简介

Perfetto 是一个用于 Android 系统的性能跟踪工具,可以帮助开发者分析系统性能和调试问题。
Perfetto 是 Android 10 中引入的全新平台级跟踪工具。这是适用于 Android、Linux 和 Chrome 的更加通用和复杂的开源跟踪项目。
在低于Android R的版本上面默认是关闭的,需要先执行命令打开:

adb shell setprop persist.traced.enable 1

对比Systrace 有很多优点:

进程名称显示完整
Binder跨进程点击跳转,跟踪方便,不需要类似systrace一样跟踪Binder跳转时需要挨个查看线程号
支持置顶你感兴趣的线程,放在一起分析更容易
看线程被谁唤醒非常方便
可以同时跟踪内存/电压/event log等信息

2. 抓取方式

perfetto 命令包含以下两种模式:

轻量模式:只能选择一部分数据源,具体来说就是 atrace 和 ftrace。但此模式可提供类似于 systrace 的接口。
普通模式:从协议缓冲区获取其配置,并且可以让您使用 atrace 和 ftrace 之外的数据源,从而更加充分地利用 perfetto 的功能。

2.1 轻量模式

在轻量模式下使用 perfetto 的一般语法如下:

adb shell perfetto [ --time TIMESPEC ] [ --buffer SIZE ] [ --size SIZE ] [ ATRACE_CAT | FTRACE_GROUP/FTRACE_NAME | FTRACE_GROUP/* ]…

抓取:
adb shell perfetto -o /data/misc/perfetto-traces/trace_file.perfetto-trace -t 20s sched freq idle am wm gfx view
取出文件:
adb pull /data/misc/perfetto-traces/trace_file.perfetto-trace

在这里插入图片描述

参考链接:
抓取Systrace方法汇总

2.2 普通模式

在普通模式下使用 perfetto 的一般语法如下:
adb shell perfetto [ --txt ] --config CONFIG_FILE

选项说明
- -config CONFIG_FILE 或 -c CONFIG_FILE指定配置文件的路径。
- -txt指示 perfetto 将配置文件解析为 pbtxt。此标记为实验性标记,不建议您在正式版中启用此标记。

执行命令

adb push perfetto–config.pbtx /data/misc/perfetto-traces/
adb shell perfetto --txt --config /data/misc/perfetto-traces/perfetto_config.pbtx --out /data/misc/perfetto-traces/1.perfetto-trace
adb pull /data/misc/perfetto-traces/1.perfetto-trace

配置文件:perfetto_config.pbtx

buffers: {
    size_kb: 522240
    fill_policy: RING_BUFFER
}
buffers: {
    size_kb: 2048
    fill_policy: RING_BUFFER
}
data_sources: {
    config {
        name: "linux.process_stats"
        target_buffer: 1
        process_stats_config {
            scan_all_processes_on_start: true
        }
    }
}
data_sources: {
    config {
        name: "android.log"
        android_log_config {
        }
    }
}
data_sources: {
    config {
        name: "android.surfaceflinger.frametimeline"
    }
}
data_sources: {
    config {
        name: "android.game_interventions"
    }
}

data_sources: {
    config {
        name: "android.packages_list"
    }
}

data_sources: {
    config {
        name: "linux.ftrace"
        ftrace_config {
            ftrace_events: "sched/sched_switch"
            ftrace_events: "power/suspend_resume"
            ftrace_events: "sched/sched_wakeup"
            ftrace_events: "sched/sched_wakeup_new"
            ftrace_events: "sched/sched_waking"
            ftrace_events: "power/cpu_frequency"
            ftrace_events: "power/cpu_idle"
            ftrace_events: "power/gpu_frequency"
            ftrace_events: "raw_syscalls/sys_enter"
            ftrace_events: "raw_syscalls/sys_exit"
            ftrace_events: "sched/sched_process_exit"
            ftrace_events: "sched/sched_process_free"
            ftrace_events: "task/task_newtask"
            ftrace_events: "task/task_rename"
            ftrace_events: "ftrace/print"
            atrace_categories: "gfx"
            atrace_categories: "input"
            atrace_categories: "view"
            atrace_categories: "wm"
            atrace_categories: "am"
            atrace_categories: "hal"
            atrace_categories: "res"
            atrace_categories: "dalvik"
            atrace_categories: "bionic"
            atrace_categories: "pm"
            atrace_categories: "ss"
            atrace_categories: "database"
            atrace_categories: "aidl"
            atrace_categories: "binder_driver"
            atrace_categories: "binder_lock"
            atrace_categories: "sched"
            atrace_categories: "freq"
            atrace_apps: "*"
        }
    }
}
duration_ms: 10000
write_into_file: true
file_write_period_ms: 2500
max_file_size_bytes: 256000000
flush_period_ms: 30000
incremental_state_config {
    clear_period_ms: 5000
}

在这里插入图片描述

3. 打开Trace文件

打开网站:
https://ui.perfetto.dev/
将trace文件拖入即可
在这里插入图片描述
在这里插入图片描述

  • 29
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 11
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值