Back to project page android-plotter.
The source code is released under:
Apache License
If you think the Android project android-plotter listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.solovyev.android.plotter; /* w w w. j a va2 s . c o m*/ import android.util.Log; import javax.annotation.Nonnull; import java.util.concurrent.TimeUnit; import static java.lang.System.nanoTime; /** * Seconds per frame */ final class Spf { @Nonnull private static final String TAG = Plot.getTag("SPF"); private static final long SECOND = TimeUnit.SECONDS.toNanos(1); private static final long MILLIS = TimeUnit.MILLISECONDS.toNanos(1); private long start = 0; private long end = 0; private int frames = 0; public final void logFrameStart() { if (end != 0) { if (nanoTime() - end >= 100L * MILLIS) { // too long pause between frames, probably we are not drawing frames = 0; } } if (frames == 0) { start = nanoTime(); } frames++; } public void logFrameEnd() { end = nanoTime(); final long elapsedNanos = end - start; if (elapsedNanos >= SECOND) { final long elapsedMillis = elapsedNanos / MILLIS; final long spf = elapsedMillis / frames; Log.d(TAG, "SPF=" + spf + "ms, FPS=" + (1000L / spf)); frames = 0; } } }