31

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

Roman Minenok
  • 9,328
  • 4
  • 26
  • 26
  • Guess your question is a bit too general. Are you talking about some stock UI stuff you're using or are you running an OpenGL context or something similar? In later case I'd just count the frames myself. – Mario Jan 18 '12 at 09:43

4 Answers4

31

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

Nick Moskalenko
  • 941
  • 9
  • 10
19

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)

Robert Rouhani
  • 14,512
  • 6
  • 44
  • 59
  • Oh and if you're trying to do interpolation/animation, you can use the same frametime as a way to get smooth time-based motion. – Robert Rouhani Jan 18 '12 at 09:48
  • 5
    The difference between 1000-1200 is .17 seconds approximately, the difference between 60 and 61 fps is about .017 seconds. So that's definitely a huge difference. – Sietse Jun 12 '13 at 15:03
  • 1
    your elapsed time calculation is in milliseconds as you said. So, shouldn't the framerate calculation be 1000.0 / frametime? I guess it's not clear what units your answer is specifying, but since the OP is mentioning frames per second, i think you need to do 1000.0 – Stealth Rabbi Apr 15 '14 at 12:30
  • Simple but ... how do you get a notification of 'frame completed' ? – Dr. Andrew Burnett-Thompson Mar 30 '16 at 15:19
  • 1
    @Dr.ABT For this clock just call elapsedRealtime at any point during the frame and your FPS will be accurate after the first frame. If you want to be pedantic, call and store elapsedRealtime just before your main loop and then every frame just after you call SwapBuffers in whatever framework you're using. – Robert Rouhani Mar 30 '16 at 20:30
  • There's typically no built-in way to get some sort of event or notification fired after finishing a frame rendering. You could build it yourself by calling your notification stuff just after SwapBuffers – Robert Rouhani Mar 30 '16 at 20:31
  • That's the thing -- Im trying to measure the performance of a third party control, so I don't have access to the main loop. I'll try the TinyDancer approach. – Dr. Andrew Burnett-Thompson Mar 31 '16 at 07:47
  • Yeah, that may work. If not, it would be a separate question specific to your third-party code. – Robert Rouhani Mar 31 '16 at 07:59
6

I have used GameBench for FPS Analysis of an android application(it is not a game, I wanted to check the FPS when an animation of my app starts running). GameBench captures key frame rate (FPS) metrics, which are the best objective indicator of the fluidity of a UX.

My requirement was to verify the FPS to be 30FPS when an animation of my android application starts.

I have verified the following with the Graph report provided by the GameBench tool,

  • When the animation starts, the FPS moved from 0 FPS to 30FPS.
  • When the animation ends the FPS moved from 30FPS to 0 FPS

See screenshot.

enter image description here

To use this tool, you have to install an android application and a desktop launcher.

  1. Install the GameBench application in your android device.
  2. Register to GameBench using an email address and install the desktop application.
  3. Download and install the GameBench Desktop Launcher.
  4. Connect the device with the desktop. You may receive a pop-up on your device asking you to allow USB Debugging
  5. In the GameBench Android app, you can select the app(which I already installed on the tablet) for the analysis.
  6. Then you can record the Frame per seconds and generate the report(its available in web dashboard too, the FPS,screenshot, performance,battery etc).

Reference:

  1. https://play.google.com/store/apps/details?id=com.gamebench.metricscollector
  2. https://www.gamebench.net/
  3. https://docs.gamebench.net/web-dashboard/getting-started

As a side note,

I have used FPS Meter app also, but it seems inaccurate in my case. Got 29FPS to 31 FPS when my animation in the android application starts. Expected FPS is 30FPS.

https://play.google.com/store/apps/details?id=com.ftpie.fpsmeter&hl=en

Hardian
  • 1,922
  • 22
  • 23
3

There are apps in the playstore that can measure FPS of a play session. Please look at GameBench. It can measure performance of any game while its being played and you can correlate FPS drops to what was being rendered on the screen.

Karthik H
  • 123
  • 1
  • 11