本讲是android camera性能分析专题的第33讲,我们介绍perfetto 分析cpu usage。
更多资源:
资源 | 描述 |
---|---|
在线课程 | |
知识星球 | 星球名称:深入浅出android camera 星球id: 17296815 |
极客笔记圈 |
perfetto cpu usage分析需要打开的config
需要打开scheduling events trace config:
data_sources: {
config {
name: "linux.process_stats"
target_buffer: 1
process_stats_config {
scan_all_processes_on_start: true
}
}
}
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: "sched/sched_process_exit"
ftrace_events: "sched/sched_process_free"
ftrace_events: "task/task_newtask"
ftrace_events: "task/task_rename"
buffer_size_kb: 2048
drain_period_ms: 250
}
}
}
注意:在对比cpu usage时,要将cpu frequency固定住来对比才有意义。
perfetto统计整个系统cpu usage
在cpu区域圈2秒:
cpu usage计算
-
该阶段总的cpu运行时间 / duration
-
12367ms/1953ms = 6.3323 = 633.23%
-
注:也可以通过top命令来看整个系统的cpu usage
perfetto统计某个进程cpu usage
进程 | 圈起来的时间 | 进程执行时间 | 进程cpu占用 |
---|---|---|---|
camera.provider | 1953ms | 3463ms | 177.31% |
logd | 1953ms | 1437ms | 73.58% |
logcat | 1953ms | 1085ms | 5.56% |
perfetto统计某个进程cpu usage from sql
sql语句统计进程cpu time:
select process.name, (sum(dur)/1e9) as cpu_sec
from sched
join thread using(utid)
join process using(upid)
where ts <= (select ts 5000000000 from sched order by ts limit 1)
group by upid
order by cpu_sec desc
limit 100;
结果:
perfetto统计某个进程在各cpu上的cpu usage
有时候我们需要知道该进程在大核/小核上的cpu占比,可以使用下面的sql语句,查看cameraserver在各cpu上的cpu usage情况:
select
process.name as process,
cpu,
sum(dur) / 1e9 as cpu_sec
from sched
inner join thread using(utid)
inner join process using(upid)
where process.name like "�meraserver%"
group by upid, cpu
order by cpu_sec desc
limit 300;
输出:
perfetto统计某个线程cpu usage
线程 | 圈起来的时间 | 进程执行时间 | 线程cpu占用 |
---|---|---|---|
logcat | 1953ms | 1085ms | 55.56% |
logd.writer | 1953ms | 858ms | 43.93% |
logd.reader.per | 1953ms | 577ms | 29.54% |
perfetto统计某个线程在各cpu上的cpu usage from sql
有时候我们需要知道该线程在大核/小核上的cpu占比,可以使用下面的sql语句,查看c3dev-0-reqqueu在各cpu上的cpu usage情况:
select
thread.name as thread,
cpu,
sum(dur) / 1e9 as cpu_sec
from sched
inner join thread using(utid)
inner join process using(upid)
where thread.name like "�dev-0-reqqueu%"
group by utid, cpu
order by cpu_sec desc
limit 300;
输出: