第33讲 Perfetto 分析CPU Usage - Android Camera性能分析

2024年10月30日 第33讲 Perfetto 分析CPU Usage 极客笔记

本讲是Android Camera性能分析专题的第33讲,我们介绍Perfetto 分析CPU Usage。

更多资源:

资源 描述
在线课程 极客笔记在线课程
知识星球 星球名称:深入浅出Android Camera
星球ID: 17296815
Wechat 极客笔记圈

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 "%cameraserver%"
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 "%C3Dev-0-ReqQueu%"
GROUP BY utid, cpu
ORDER BY cpu_sec desc
LIMIT 300;

输出:

本文链接:http://so.lmcjl.com/news/16595/

展开阅读全文