4

I'd like to measure the FPS (refresh rate) of a certain Android View which uses TextureView. To do this, I need some way to measure FPS programmatically (e.g. not using ADB.exe and not using third party apps or tools).

I have seen this question but it does not answer where to log frame time.

Is there an API within Android to get an event when the screen refreshes or is composed? Using this it would be relatively simple to measure frame time and hence calculate FPS.

Same question for CPU usage. Any or all APIs to measure performance appreciated!

Community
  • 1
  • 1
Dr. Andrew Burnett-Thompson
  • 20,980
  • 8
  • 88
  • 178

2 Answers2

4

Well, it looks like TinyDancer can do what you want:

 //you can add a callback to get frame times and the calculated
 //number of dropped frames within that window
 TinyDancer.create()
     .addFrameDataCallback(new FrameDataCallback() {
        @Override
        public void doFrame(long previousFrameNS, long currentFrameNS, int droppedFrames) {
           //collect your stats here
        }
      })
      .show(this);
}

If you need to know the CPU usage you can always use top. Smth like this:

root@android:/data # top -n 1 -s cpu

User 28%, System 29%, IOW 0%, IRQ 0%
User 189 + Nice 162 + Sys 355 + Idle 509 + IOW 0 + IRQ 0 + SIRQ 2 = 1217

  PID PR CPU% S  #THR     VSS     RSS PCY UID      Name
31096  0  20% S    20 463368K  78884K  fg u0_i77   com.android.chrome:sandboxed_process0
29042  1  11% S    54 451036K  84876K  fg u0_a10   com.android.chrome
  130  2   9% S    25  79228K  37136K  fg system   /system/bin/surfaceflinger
...
...
...

Calling system command from Android app is not difficult.

Mikalai Daronin
  • 8,590
  • 2
  • 35
  • 47
0

SystemClock.elapsedRealtime Is the key to measure FPS. The method is very simple: long YOUR_VARIABLE = SystemClock.elapsedRealtime / 1000.0

The code calculates the frames that has been shown on screen. elapsedRealtime Is calculating in Milliseconds. One second in milliseconds is 1000 milliseconds.