Robust
Robust

Reputation: 259

How to calculate FPS on device level in android

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.

Upvotes: 5

Views: 5460

Answers (2)

jsrz
jsrz

Reputation: 6052

That isn't something you can do unless you root the device and get under the hood somehow.

Upvotes: 0

slayton
slayton

Reputation: 20319

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;
}

Upvotes: 5

Related Questions