Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android frames per second

Is it possible to get these values programmatically:

  • frames per second
  • how often the method onDraw() is called if the whole View is invalidated immediately.
like image 987
A.G. Avatar asked Sep 28 '22 13:09

A.G.


1 Answers

1) Here is how I'm counting fps:

public class MyView extends View {
    private int    mFPS = 0;         // the value to show
    private int    mFPSCounter = 0;  // the value to count
    private long   mFPSTime = 0;     // last update time

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

        if (SystemClock.uptimeMillis() - mFPSTime > 1000) {
            mFPSTime = SystemClock.uptimeMillis();
            mFPS = mFPSCounter;
            mFPSCounter = 0;
        } else {
            mFPSCounter++;
        }

        String s = "FPS: " + mFPS;
        canvas.drawText(s, x, y, paint);

        invalidate();
    }
}

or just write your own object that would calculate this for you :)...

2) Try using

Log.d(tag, "onDraw() is called");

in your onDraw() method.

like image 102
GV_FiQst Avatar answered Oct 10 '22 10:10

GV_FiQst