本讲是android camera性能分析专题的第43讲,我们介perfetto 自动化之camera前后切换性能自动化分析。
更多资源:
资源 | 描述 |
---|---|
在线课程 | |
知识星球 | 星球名称:深入浅出android camera 星球id: 17296815 |
极客笔记圈 |
camera前后摄切换性能拆解
模块 | 开始点 | 结束点 |
---|---|---|
app | 点击camera switch icon | 开始调用disconnect |
hal | 开始调用disconnect | 调用disconnect结束 |
app | 调用disconnect结束 | 开始调用connectdevice |
hal | 开始调用connectdevice | 调用connectdevice结束 |
app | 调用connectdevice结束 | 开始调用endconfigure |
hal | 开始调用endconfigure | 调用endconfigure结束 |
app | 调用endconfigure结束 | 调用submitrequestlist |
hal | 调用submitrequestlist | cameraserver收到第一帧 |
camera前后摄切换性能自动化分析代码
代码见视频讲解
#!/usr/bin/env python3
from perfetto.trace_processor import traceprocessor
from perfetto.trace_processor import traceprocessorconfig
tp = traceprocessor(trace=r'switch_camera.perfetto-trace', config=traceprocessorconfig(
bin_path=r'trace_processor_shell_v3.7.exe',
verbose=false))
### click switch camera icon
click_app_icon = tp.query('select (slice.ts slice.dur)/1e6 '
'from slice '
'where ts <(select ts from slice where name == "connectdevice" limit 1) '
'and name like "�liverinputevent%" '
'order by ts desc '
'limit 1')
click_app_icon_ms = click_app_icon.as_pandas_dataframe().values[0][0]
### closcamera
closecamera_sql = """select ts/1e6, dur/1e6 from
slice
join thread_track on slice.track_id = thread_track.id
join thread using(utid)
join process using(upid)
where slice.name='disconnectimpl' and process.name='/system/bin/cameraserver'
limit 1"""
close_camera_df = tp.query(closecamera_sql).as_pandas_dataframe()
close_camera_begin = close_camera_df.values[0][0]
close_camera_dur = close_camera_df.values[0][1]
### opencamera
open_session = tp.query('select (slice.ts/1e6), (slice.dur/1e6) '
'from slice '
'where slice.name like "�merahal::opensession%"')
open_session_df = open_session.as_pandas_dataframe()
open_session_begin_ms = open_session_df.values[0][0]
open_session_duration_ms = open_session_df.values[0][1]
### beginconfigure
begin_configure = tp.query('select (slice.ts/1e6) '
'from slice '
'where slice.name like "�ginconfigure%" '
'limit 1')
begin_configure_df = begin_configure.as_pandas_dataframe()
begin_configure_ms = begin_configure_df.values[0][0]
### endconfigure
end_configure = tp.query('select (slice.ts/1e6), (slice.dur/1e6) '
'from slice '
'where slice.name like "%endconfigure%" '
'limit 1')
end_configure_df = end_configure.as_pandas_dataframe()
end_configure_begin_ms = end_configure_df.values[0][0]
end_configure_duration_ms = end_configure_df.values[0][1]
### submitrequestlist
submit_request_list = tp.query('select (slice.ts/1e6) '
'from slice '
'where ts >(select ts from slice where name == "endconfigure" limit 1) '
'and slice.name like "%submitrequestlist%" '
'order by slice.ts asc '
'limit 1')
submit_request_list_df = submit_request_list.as_pandas_dataframe()
submit_request_list_begin_ms = submit_request_list_df.values[0][0]
### cameraserver queue first frame
first_full_buffer = tp.query('select (slice.ts/1e6), (slice.dur/1e6) '
'from slice '
'where slice.name like "%first full buffer%"')
first_full_buffer_df = first_full_buffer.as_pandas_dataframe()
first_full_buffer_queued_ms = first_full_buffer_df.values[0][0] first_full_buffer_df.values[0][1]
### print results
print("total switch camera time:" str(round((first_full_buffer_queued_ms - click_app_icon_ms), 2)) " ms, break down as following:")
print(" [app] click --> closcamera: "
str(round((close_camera_begin - click_app_icon_ms), 2)) " ms")
print(" [hal] --> closcamera: "
str(round((close_camera_dur), 2)) " ms")
print(" [app] closcamera --> camerahal::opensession: "
str(round((open_session_begin_ms - close_camera_begin - close_camera_dur), 2)) " ms")
print(" [hal] camerahal::opensession: "
str(round((open_session_duration_ms), 2)) " ms")
print(" [app] camerahal::opensession --> beginconfigure: "
str(round((begin_configure_ms - open_session_duration_ms - open_session_begin_ms), 2)) " ms")
print(" [hal] beginconfigure --> endconfigure: "
str(round((end_configure_begin_ms end_configure_duration_ms - begin_configure_ms), 2)) " ms")
print(" [app] endconfigure --> submitrequestlist: "
str(round((submit_request_list_begin_ms - end_configure_begin_ms - end_configure_duration_ms), 2)) " ms")
print(" [hal] submitrequestlist --> stream x: first full buffer: "
str(round((first_full_buffer_queued_ms - submit_request_list_begin_ms), 2)) " ms")
输出