第43讲 Perfetto 自动化之Camera前后切换性能自动化分析

2024年10月31日 第43讲 Perfetto 自动化之Camera前后切换性能自动化分析 极客笔记

本讲是Android Camera性能分析专题的第43讲,我们介Perfetto 自动化之Camera前后切换性能自动化分析。

更多资源:

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

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 "%deliverInputEvent%" '
                          '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 "%CameraHal::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 "%beginConfigure%" '
                          '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")

输出

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

展开阅读全文
相关内容