本讲是Android Camera性能分析专题的第41讲,我们介Perfetto 自动化之Python SDK自动化分析性能环境搭建。
更多资源:
资源 | 描述 |
---|---|
在线课程 | 极客笔记在线课程 |
知识星球 | 星球名称:深入浅出Android Camera 星球ID: 17296815 |
极客笔记圈 |
搭建Perfetto Python SDK环境
安装Perfetto库(推荐使用Python3)
pip install perfetto
获取Trace Processor二进制文件(避免科学上网)
- 下载脚本
https://get.perfetto.dev/trace_processor
- 根据Python SDK运行的操作系统环境选择Trace Processor二进制文件下载地址,以Windows 64版本为例
https://commondatastorage.googleapis.com/perfetto-luci-artifacts/v37.0/windows-amd64/trace_processor_shell.exe
Perfetto Python SDK – Hello World
from perfetto.trace_processor import TraceProcessor
from perfetto.trace_processor import TraceProcessorConfig
tp = TraceProcessor(trace='geekcamera2_camera_launch.trace',
config=TraceProcessorConfig(
bin_path=r'trace_processor_shell_v3.7.exe',
verbose=False
))
qr_it = tp.query('SELECT name,dur FROM slice WHERE name="connectDevice"')
for row in qr_it:
print(row.name, row.dur / 1e6)
cpu_metrics = tp.metric(['android_startup'])
# print(cpu_metrics)
输出: