Calculate FPS in an Android app which does rendering via SKIA

110 views
Skip to first unread message

pearleye

unread,
Apr 27, 2023, 8:35:05 AM4/27/23
to skia-discuss
Hi

I'm using the below android application which does some rendering via JNI calls to SKIA library.


And I would like to measure/calculate the FPS which I haven't figured it out yet. Can someone let me know how to do it?

Thank you.

Jim Van Verth

unread,
Apr 27, 2023, 10:37:36 AM4/27/23
to skia-d...@googlegroups.com
You can look at StatsLayer in tools/viewer for some ideas. But basically you accumulate the frame time over a certain number of frames, and then compute <# frames>/<accumulated time>.  Usually there's a circular buffer of times that you cycle through so that old times get purged, or you can try to compute a running average. And milliseconds/frame is usually a better measure.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/118d0aad-d4c9-4f12-a21c-07a457203314n%40googlegroups.com.


--

Jim Van Verth |
 Software Engineer | Google.com

craste...@gmail.com

unread,
Apr 30, 2023, 10:38:02 AM4/30/23
to skia-discuss
Is there any sort of "system time" API in android which will tell you how many milliseconds have passed since 1970-something?
The standard FPS calculation is to gather those numbers for each rendering pass and do a bit of softening of the peaks and valleys by averaging a certain number of them against each other.
It isn't really Skia's job to provide such an API. The platform should already offer tools to do it yourself.

pearleye

unread,
Apr 30, 2023, 7:30:22 PM4/30/23
to skia-discuss
@jvan, Thanks for your input. I had a look at the file which you mentioned and wanted to know if I can consider a frame is created
 on each call of onPaint() which does the drawing in canvas?

Jim Van Verth

unread,
May 1, 2023, 9:57:42 AM5/1/23
to skia-d...@googlegroups.com
Skia provides SkTime which is a platform-independent way to get at the system time.

As far as a "frame", that's whatever you want to consider it to be. The usual approach is to measure the time between swaps of the backbuffer (e.g., that's swapBuffers() in sk_app::WindowContext).  To do that you could start a timer when you start drawing content, and then stop and record it when you start drawing content for the next frame (and start a new one, etc.). But you could measure the time from when you start drawing the content to when you call SkCanvas::flush(). That would leave out any time taken up by the swapchain, however, so may not be what you're looking for.

But other than the SkTime interface this is outside of Skia really -- StackOverflow has some examples of how to do this in general.

Reply all
Reply to author
Forward
0 new messages