2024年10月31日 第45讲 Perfetto 自动化之Camera录像帧率自动化分析 极客笔记
本讲是Android Camera性能分析专题的第45讲,我们介Perfetto 自动化之Camera录像帧率自动化分析。
更多资源:
资源 | 描述 |
---|---|
在线课程 | 极客笔记在线课程 |
知识星球 | 星球名称:深入浅出Android Camera 星球ID: 17296815 |
极客笔记圈 |
录像除了要关注平均帧率外,每两帧之间的时间间隔,也需要重点关注,这个时间间隔用于衡量抖动
Python 代码
from perfetto.trace_processor import TraceProcessor
from perfetto.trace_processor import TraceProcessorConfig
import matplotlib.pyplot as plt
tp = TraceProcessor(trace=r'Codec2_MediaRecorder_getSurface_Android12', config=TraceProcessorConfig(
bin_path=r'trace_processor_shell_v3.7.exe',
verbose=False))
android12_surfaceview_fps_sql = """
SELECT ts/1e6
FROM counters
WHERE name like '%BufferTX - SurfaceView%' AND value=1
ORDER BY counters.ts ASC"""
surfaceview_fps_counter = tp.query(android12_surfaceview_fps_sql).as_pandas_dataframe()
if surfaceview_fps_counter.empty:
pass
else:
surfaceview_fps_gap = surfaceview_fps_counter.diff().iloc[1:]
avg_gap_ms = surfaceview_fps_gap['ts/1e6'].mean()
surfaceview_fps = round(1000 / avg_gap_ms, 2)
print('FPS:' + str(surfaceview_fps))
print('Gap:' + str(surfaceview_fps_gap))
plt.subplot(211)
plt.plot(surfaceview_fps_gap.index, surfaceview_fps_gap['ts/1e6'])
plt.xlabel('Index')
plt.ylabel('Gap(ms)')
plt.title('Camera Preview - SurfaceView Frame Duration(' + str(surfaceview_fps) + " FPS)")
plt.axhline(avg_gap_ms, color='r', linestyle='--', label='Average')
plt.annotate(f'{round(avg_gap_ms,2)}', xy=(0, avg_gap_ms), color='black')
# plt.show()
android12_codec2_mediaserver_fps_sql = """
SELECT ts/1e6 FROM
slice
JOIN thread_track ON slice.track_id = thread_track.id
JOIN thread USING(utid)
JOIN process USING(upid)
WHERE slice.name='queueBuffer' AND process.name='/system/bin/mediaserver'
ORDER BY slice.ts ASC
"""
mediaserver_fps_counter = tp.query(android12_codec2_mediaserver_fps_sql).as_pandas_dataframe()
if mediaserver_fps_counter.empty:
print("No MediaServer FPS Data.")
else:
mediaserver_fps_gap = mediaserver_fps_counter.diff().iloc[1:]
avg_gap_ms = mediaserver_fps_gap['ts/1e6'].mean()
mediaserver_fps = round(1000 / avg_gap_ms, 2)
print('FPS:' + str(mediaserver_fps))
print('Gap:' + str(mediaserver_fps_gap))
plt.subplot(212)
plt.plot(mediaserver_fps_gap.index, mediaserver_fps_gap['ts/1e6'])
plt.xlabel('Index')
plt.ylabel('Gap(ms)')
plt.title('Camera Recording - MediaServer Frame Duration(' + str(mediaserver_fps) + " FPS)")
plt.axhline(avg_gap_ms, color='r', linestyle='--', label='Average')
plt.annotate(f'{round(avg_gap_ms, 1)}', xy=(0, 40),color='black')
plt.show()
输出:
FPS:29.99
Gap: ts/1e6
1 30.025521
2 38.370052
3 30.871041
4 30.58724
5 34.343021
.. ...
164 30.254323
165 39.080417
166 23.453958
167 39.89
168 35.142969
[168 rows x 1 columns]
FPS:29.98
Gap: ts/1e6
1 30.157083
2 39.070729
3 31.485886
4 30.791146
5 33.955572
.. ...
164 33.912448
165 38.380521
166 25.375365
167 39.878177
168 34.983385
[168 rows x 1 columns]
本文链接:http://so.lmcjl.com/news/16683/