How to calculate FPS on device level in android

android

Solution

In your main `Activity` class override the `onDraw()` method. Invoke `super.onDraw()` then store the current system time. Calculate the `delta_time` in ms between the current call to draw and the previous call to draw. Then calculate FPS using `1000 ms / delta_time ~ FPS`

Here is some pseudocode:

void onDraw(){
  super.onDraw()
  curTime = getTime();
  deltaTime = curTime - prevTime();
  aproxFps = 1000 / deltaTime;
  prevTime = curTime;
}

Problem

Anyone having any idea about how to get FPS(frame per second) of android device ? There is an option in development settings to display FPS, but I want to write an app to do the same. It internally calls `surfaceflinger` api.

Original source