Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate FPS on device level in android

Tags:

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.

like image 702
Robust Avatar asked May 07 '12 18:05

Robust


People also ask

What is the formula for FPS calculation?

To calculate frames per second, you just take the number of rendered frames and divide it by the seconds passed.

How can I tell the frame rate of my phone?

By far, the simplest and easiest way to measure FPS on Android is to use the GameBench Android or Desktop App. GameBench takes care of querying the correct OS services and returns the FPS value.

What is Android frame rate?

Traditionally, most devices have supported only a single display refresh rate, typically 60Hz, but this has been changing. Many devices now support additional refresh rates such as 90Hz or 120Hz. Some devices support seamless refresh rate switches, while others briefly show a black screen, usually lasting a second.


1 Answers

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;
}
like image 176
slayton Avatar answered Sep 21 '22 17:09

slayton