You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用ADB获取Android应用运行时的屏幕当前FPS

Android应用运行时FPS测量方案

一、系统自带开发者工具(无需改代码)

  • 开启开发者选项,找到**"显示实时帧率"**(部分机型叫"显示FPS"),开启后屏幕右上角会实时显示当前FPS数值,直观看到帧率波动。
  • 开启**"GPU呈现模式分析"**,选择"在屏幕上显示条形图":每个条形代表一帧的渲染耗时,绿色线对应60FPS的耗时阈值(约16ms),超过绿色线的部分就是卡顿帧,能快速定位卡顿时段。

二、代码嵌入统计(适合自定义监控)

通用应用(基于Choreographer)

利用Android系统的Choreographer监听每帧回调,统计单位时间内的帧数来计算FPS:

private long lastFrameTime = 0;
private int frameCount = 0;
private float currentFps = 0;

// 启动FPS统计
private void startFpsMonitor() {
    Choreographer.getInstance().postFrameCallback(frameTimeNanos -> {
        if (lastFrameTime == 0) {
            lastFrameTime = frameTimeNanos;
        }
        long timeDiff = frameTimeNanos - lastFrameTime;
        // 每1秒更新一次FPS
        if (timeDiff >= 1_000_000_000) {
            currentFps = frameCount / (timeDiff / 1_000_000_000f);
            Log.d("AppFPS", "当前FPS: " + String.format("%.1f", currentFps));
            frameCount = 0;
            lastFrameTime = frameTimeNanos;
        }
        frameCount++;
        Choreographer.getInstance().postFrameCallback(this);
    });
}

调用startFpsMonitor()即可在日志中查看实时FPS,卡顿发生时能直接记录异常数值。

游戏类应用(基于GLSurfaceView)

如果是使用GLSurfaceView的游戏或渲染类应用,可在渲染循环中统计:

private long lastUpdateTime = System.currentTimeMillis();
private int frameCount = 0;

@Override
public void onDrawFrame(GL10 gl) {
    long currentTime = System.currentTimeMillis();
    frameCount++;
    // 每1秒计算一次FPS
    if (currentTime - lastUpdateTime >= 1000) {
        float fps = frameCount / ((currentTime - lastUpdateTime) / 1000f);
        Log.d("GameFPS", "当前FPS: " + String.format("%.1f", fps));
        frameCount = 0;
        lastUpdateTime = currentTime;
    }
    // 你的渲染逻辑...
}

三、卡顿排查补充

当FPS明显低于目标值(通常是60或120FPS)时,可结合Android Studio的Profiler工具:

  • 查看主线程的CPU占用,定位是否有耗时操作(如IO、复杂计算)阻塞UI线程;
  • 分析GPU渲染数据,确认是否存在过度绘制、纹理加载过慢等问题。

内容的提问来源于stack exchange,提问作者Prijesh Devanand

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 09:12:39