本讲是android camera性能分析专题的第45讲,我们介perfetto 自动化之camera录像帧率自动化分析。
更多资源:
资源 | 描述 |
---|---|
在线课程 | |
知识星球 | 星球名称:深入浅出android camera 星球id: 17296815 |
极客笔记圈 |
camera 录像帧率和抖动
录像除了要关注平均帧率外,每两帧之间的时间间隔,也需要重点关注,这个时间间隔用于衡量抖动
camera 录像帧率自动化分析
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]