- SurfaceView可以直接adb获取(旧版本美摄的渲染组件)
- 打开要测试的APP, 正式版本或者测试版本都可以
- APP准备好要测试的画面,比如编辑页面的第一帧或者最后一帧
- 命令行里输入
adb shell dumpsys SurfaceFlinger --timestats -clear -enable
但不要点击回车 - 左手点击播放按钮,右手同时点击回车
此时命令行会显示
---- TIME: 2024-08-02 15:31:42.685 ----
表示从此时开始记录设备窗口绘制的FPS数据 - 在命令行输入
adb shell dumpsys SurfaceFlinger --timestats -dump
表示下载到当前为止的FPS数据。在Track播最后一帧的时候点击回车,就是记录从Track第一帧播到最后一帧的FPS数据 - 命令行里显示的数据如下图所示:
---- TIME: 2024-08-02 15:32:07.338 ----
SurfaceFlinger TimeStats:
Legacy stats are as follows:
statsStart = 1722583908
statsEnd = 1722583927
totalFrames = 1051
missedFrames = 0
clientCompositionFrames = 0
clientCompositionReusedFrames = 0
refreshRateSwitches = 0
compositionStrategyChanges = 0
compositionStrategyPredicted = 0
compositionStrategyPredictionSucceeded = 0
compositionStrategyPredictionFailed = 0
displayOnTime = 18428 ms
displayConfigStats is as below:
totalP2PTime = 17132 ms
presentToPresent histogram is as below:
0ms=0 ...忽略显示=0
averageFrameDuration = 3.721 ms
frameDuration histogram is as below:
displayRefreshRate = 60 fps
renderRate = 60 fps
uid = 10487
layerName = xxx.xxx.xxx/xxx.xxx.xxx.VideoEditActivity#66694
packageName =
gameMode = Unsupported
totalFrames = 1046
droppedFrames = 0
lateAcquireFrames = 0
badDesiredPresentFrames = 0
Jank payload for this layer:
totalTimelineFrames = 1045
jankyFrames = 2
sfLongCpuJankyFrames = 0
sfLongGpuJankyFrames = 0
sfUnattributedJankyFrames = 0
appUnattributedJankyFrames = 2
sfSchedulingJankyFrames = 0
sfPredictionErrorJankyFrames = 0
appBufferStuffingJankyFrames = 1043
SetFrateRate vote for this layer:
frameRate = 0.00
frameRateCompatibility = Undefined
seamlessness = Undefined
averageFPS = 61.109
present2present histogram is as below:
0ms=0 ...忽略显示000ms=0
layerName = SurfaceViewxxx.xxx.xxx.VideoEditActivity#66155
...忽略显示
frameRate = 0.00
frameRateCompatibility = Undefined
seamlessness = Undefined
averageFPS = 29.826
present2present histogram is as below:
0ms=0 ...忽略显示 1000ms=0
latch2present histogram is as below:
0ms=0 ...忽略显示
拷贝到txt编辑器里之后,搜索关键字averageFPS,可以看到有三个数据,表示是三个窗口的FPS数据,根据上方的layerName来判断是哪个组件的FPS,比如我们需要的渲染特效的FPS为
layerName = SurfaceView[xxx.xxx.xxx.VideoEditActivity]
averageFPS = 29.826获取性能日志后,记得关掉性能监控:
adb shell dumpsys SurfaceFlinger --timestats -disable
- TextureView
TextureView不是通过SurfaceFlinger管理渲染流水线,而是直接和GPU交互,所以不能通过
类似adb shell dumpsys SurfaceFlinger的命令来获取性能数据,只能通过API接口如SurfaceTextureListener来打log记录帧率等数据。如:
private static final int BUFFER_SIZE = 250; // 缓冲区大小, 需要根据模版的总时长调整
private long lastUpdateTime = 0;
private float[] fpsBuffer = new float[BUFFER_SIZE];
private int bufferIndex = 0;
private float currentFps = 0;
private float averageFps = 0;
public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surface) {
...
long currentTime = System.nanoTime();
long interval = currentTime - lastUpdateTime;
lastUpdateTime = currentTime;
currentFps = (float) (1e9 / interval);
fpsBuffer[bufferIndex] = currentFps;
bufferIndex = (bufferIndex + 1) % BUFFER_SIZE;
float sum = 0;
for (float fps : fpsBuffer) {
// AxLog.e(TAG, "fps: " + fps);
if(fps < 1){
sum = 0;
return;
}
sum += fps;
}
averageFps = sum / BUFFER_SIZE;
//AxLog.e(TAG, "Current FPS: " + currentFps);
AxLog.e(TAG, "Average FPS: " + averageFps);
}