Archie.bpgc
Archie.bpgc

Reputation: 24012

How to get the FPS of my ListView

There are not much questions about it on SOF:

Android - How can I measure performance of ListView and other Views?

Has a solution to use Hierarchy Viewer. But I just want to get the FPS on a ListView.

Moreover that Hierarchy Viewer doc states:

Hierarchy Viewer can only connect to devices running a developer version of the Android system

And that console doesn't detect my device. And I have no idea what a developer version is.

Somewhere I read Emulators are kind of developer versions, but they might not be accurate.

Also, I found this in my log cat when I scroll the ListView:

05-04 11:14:24.697: I/SurfaceTextureClient(20849): [STC::queueBuffer] (this:0x5e74b878) fps:0.39, dur:17832.35, max:17194.94, min:17.54

Is that the FPS related to my ListView?

Because it varies from 0.3 to 60.1

And AFAIK 60 is the max you get.

Upvotes: 0

Views: 778

Answers (1)

2cupsOfTech
2cupsOfTech

Reputation: 6073

You'll need to subclass a ListView and override its onDraw(), here is a sample code that should pretty much work out of the box:

public class FPSListView extends ListView
{
    private Toast fpsToast;
    private long currentTime;
    private long prevTime;

    public FPSListView(Context context){
        super(context);
        fpsToast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
    }

    public FPSListView(Context context, AttributeSet attrs){
        super(context, attrs);
        fpsToast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
    }

    @Override
    protected void onDraw(Canvas canvas) {          
        super.onDraw(canvas);

        currentTime = SystemClock.currentThreadTimeMillis();
        long deltaTime = currentTime - prevTime;
        long fps = 1000/deltaTime;
        fpsToast.setText("FPS: " + fps);
        fpsToast.show();
        prevTime = currentTime;
    }
}

Upvotes: 1

Related Questions