背景:
前面讲解perfetto的查看信息时候,没有重点讲解cpu区域的内容,今天本文将补充讲解perfetto/systrace的CPU Trace信息详解,同时以前有讲解如何抓取开机时刻的perfetto/systrace的方法,但是也有同学反馈使用了对应config后,没有抓取到对应的cpu相关信息,本文针对上面两个知识来进行补充讲解。
CPU Trace信息区域
cpu这块内容展示其实systrace展示的信息量还比perfetto要大一些。
CPU Trace信息区域详解
perfetto这部分展示如下:
主要包含各个cpu的执行任务片段,还有cpu的对应频率部分。
systrace展示如下:
相比perfetto而言,systrace对cpu展示内容还多了,不过其实多的地方相对不那么核心,主要内容还是cpu的执行片段内容和cpu频率最重要。
因为perfetto和systrace这一块核心内容都是一样的,所以只需要介绍systrace就可以了,会了systrace自然perfetto也肯定没问题,如上图所示,Systrace 中 CPU Trace一般在最上面显示,展示Kernel中的 CPU Info 区域信息,一般包含如下信息:
CPU的组成架构,包含多少颗CPU运行核心,以及编号信息。
每颗CPU核心的实时运行频率信息;
每颗CPU核心当前支持的运行频率的最高与最低的门限值;
每颗CPU核心的状态信息,是否进入节能或断电关闭状态;
每颗CPU核心上运行的线程任务信息与统计,按时间轴排开;
CPU运行任务分布统计部分:
查看cpu部分信息的作用
总的来说,Systrace 中的CPU Trace 这里一般是看任务调度信息,查看是否是CPU频率或者是CPU调度逻辑导致当前任务出现性能问题,举例如下:
某个场景的任务执行比较慢,我们就可以查看是不是这个任务被CPU调度器安排到了小核上运行?
某个场景的任务执行比较慢,当前执行这个任务的 CPU 运行频率是不是不够?是否因为门限值的设置不合理导致CPU被限频了?
我的任务对性能要求比较高,比如指纹解锁,能不能把我这个任务持续放到CPU超大核去运行?
我的前台应用任务线程长时间处于Runnable状态无法执行而卡顿,当前到底是什么任务在抢占了CPU资源在运行?
开机抓perfetto\systrace部分更新
上一篇文章有给大家分析如何开机抓取perfetto方法:
性能优化:官方文档抓取开机trace给perfetto分析–Recording traces on Android boot
但是有学员朋友反馈使用对应的config时候发现抓取的perfetto没有cpu相关的区域的信息
针对这个问题需要重新配置一下
更新boottrace.pbtxt文件内容如下:
buffers {
size_kb: 65536
fill_policy: DISCARD
}
buffers {
size_kb: 4096
fill_policy: DISCARD
}
data_sources {
config {
name: "linux.ftrace"
ftrace_config {
ftrace_events: "sched/sched_process_exit"
ftrace_events: "sched/sched_process_free"
ftrace_events: "task/task_newtask"
ftrace_events: "task/task_rename"
ftrace_events: "sched/sched_switch"
ftrace_events: "power/suspend_resume"
ftrace_events: "sched/sched_blocked_reason"
ftrace_events: "sched/sched_wakeup"
ftrace_events: "sched/sched_wakeup_new"
ftrace_events: "sched/sched_waking"
ftrace_events: "sched/sched_process_exit"
ftrace_events: "sched/sched_process_free"
ftrace_events: "task/task_newtask"
ftrace_events: "task/task_rename"
ftrace_events: "power/cpu_frequency"
ftrace_events: "power/cpu_idle"
ftrace_events: "power/suspend_resume"
ftrace_events: "ftrace/print"
atrace_categories: "adb"
atrace_categories: "aidl"
atrace_categories: "am"
atrace_categories: "audio"
atrace_categories: "binder_driver"
atrace_categories: "binder_lock"
atrace_categories: "bionic"
atrace_categories: "database"
atrace_categories: "gfx"
atrace_categories: "hal"
atrace_categories: "input"
atrace_categories: "pm"
atrace_categories: "power"
atrace_categories: "res"
atrace_categories: "ss"
atrace_categories: "view"
atrace_categories: "wm"
disable_generic_events: true
}
}
}
data_sources {
config {
name: "linux.process_stats"
process_stats_config {
}
}
}
data_sources {
config {
name: "linux.sys_stats"
sys_stats_config {
stat_period_ms: 500
stat_counters: STAT_CPU_TIMES
stat_counters: STAT_FORK_COUNT
cpufreq_period_ms: 500
}
}
}
duration_ms: 10000
*上面的size_kb和时间duration_ms都可以自己根据需要进行更新,不然可能因为内存不足抓到时间太短 *
上面的文件内容,也可以直接去perfetto抓取网页
https://ui.perfetto.dev/#!/record/cpu
自己配置cpu相关选项:
然后再去拷贝相关config到文件
配置后抓取的perfetto如下:
更多framework实战开发干货,请关注下面“千里马学框架”