Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to measure FPS on Android during app development

Is there a way (maybe some apps, hacks, libs) to measure frames per second (FPS) during app development for Android?

like image 936
Roman Minenok Avatar asked Jan 18 '12 09:01

Roman Minenok


People also ask

How do I see FPS in developer options?

Go to the Settings menu. Scroll down to Developer options. Scroll down almost to the bottom until you find the monitoring section. Enable show FPS value.


2 Answers

You can use TinyDancer library.

Simply add code like:

public class DebugApplication extends Application {    @Override public void onCreate() {     // default config    TinyDancer.create().show(this);     //or customazed config    TinyDancer.create()       .redFlagPercentage(.1f) // set red indicator for 10%       .startingGravity(Gravity.TOP)       .startingXPosition(200)       .startingYPosition(600)       .show(this);   } } 

And you'll see interactive view with information about current FPS on top of your screens.

enter image description here

like image 185
Nick Moskalenko Avatar answered Sep 22 '22 00:09

Nick Moskalenko


Note that performance will be terrible with the debugger attached.

From my own Android game, frame time can be measured with android.os.SystemClock. That is, you call SystemClock.elapsedRealtime() once per frame and subtract the value from the previous frame. Since elapsedRealtime() is measured in milliseconds, calculating framerate is as simple as 1000.0 / frametime.

You can post your code into an ongoing frame by using Choreographer#postFrameCallback if targeting API level 16 or newer (Jelly Bean).

Also note that frametime is generally a better gauge of performance than framerate. The difference between 1000fps and 1200fps is the same amount of time as the difference between 60fps and 61fps (approximately, probably less than that though)

like image 40
Robert Rouhani Avatar answered Sep 23 '22 00:09

Robert Rouhani