Skip to content

Commit

Permalink
add dropped frame count to FPS overlay
Browse files Browse the repository at this point in the history
Differential Revision: D2476082

committer: Service User <svcscm@fb.com>
  • Loading branch information
Martin Konicek authored and facebook-github-bot-7 committed Sep 24, 2015
1 parent bdb11c0 commit dfbee9f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
Expand Up @@ -43,7 +43,7 @@ public FpsView(ReactContext reactContext) {
mTextView = (TextView) findViewById(R.id.fps_text); mTextView = (TextView) findViewById(R.id.fps_text);
mFrameCallback = new FpsDebugFrameCallback(Choreographer.getInstance(), reactContext); mFrameCallback = new FpsDebugFrameCallback(Choreographer.getInstance(), reactContext);
mFPSMonitorRunnable = new FPSMonitorRunnable(); mFPSMonitorRunnable = new FPSMonitorRunnable();
setCurrentFPS(0, 0); setCurrentFPS(0, 0, 0, 0);
} }


@Override @Override
Expand All @@ -61,11 +61,13 @@ protected void onDetachedFromWindow() {
mFPSMonitorRunnable.stop(); mFPSMonitorRunnable.stop();
} }


private void setCurrentFPS(double currentFPS, double currentJSFPS) { private void setCurrentFPS(double currentFPS, double currentJSFPS, int droppedUIFrames, int total4PlusFrameStutters) {
String fpsString = String.format( String fpsString = String.format(
Locale.US, Locale.US,
"UI FPS: %.1f\nJS FPS: %.1f", "UI: %.1f fps\n%d dropped so far\n%d stutters (4+) so far\nJS: %.1f fps",
currentFPS, currentFPS,
droppedUIFrames,
total4PlusFrameStutters,
currentJSFPS); currentJSFPS);
mTextView.setText(fpsString); mTextView.setText(fpsString);
FLog.d(ReactConstants.TAG, fpsString); FLog.d(ReactConstants.TAG, fpsString);
Expand All @@ -77,14 +79,17 @@ private void setCurrentFPS(double currentFPS, double currentJSFPS) {
private class FPSMonitorRunnable implements Runnable { private class FPSMonitorRunnable implements Runnable {


private boolean mShouldStop = false; private boolean mShouldStop = false;
private int mTotalFramesDropped = 0;
private int mTotal4PlusFrameStutters = 0;


@Override @Override
public void run() { public void run() {
if (mShouldStop) { if (mShouldStop) {
return; return;
} }

mTotalFramesDropped += mFrameCallback.getExpectedNumFrames() - mFrameCallback.getNumFrames();
setCurrentFPS(mFrameCallback.getFPS(), mFrameCallback.getJSFPS()); mTotal4PlusFrameStutters += mFrameCallback.get4PlusFrameStutters();
setCurrentFPS(mFrameCallback.getFPS(), mFrameCallback.getJSFPS(), mTotalFramesDropped, mTotal4PlusFrameStutters);
mFrameCallback.reset(); mFrameCallback.reset();


postDelayed(this, UPDATE_INTERVAL_MS); postDelayed(this, UPDATE_INTERVAL_MS);
Expand Down
Expand Up @@ -41,6 +41,7 @@ public static class FpsInfo {
public final int totalFrames; public final int totalFrames;
public final int totalJsFrames; public final int totalJsFrames;
public final int totalExpectedFrames; public final int totalExpectedFrames;
public final int total4PlusFrameStutters;
public final double fps; public final double fps;
public final double jsFps; public final double jsFps;
public final int totalTimeMs; public final int totalTimeMs;
Expand All @@ -49,12 +50,14 @@ public FpsInfo(
int totalFrames, int totalFrames,
int totalJsFrames, int totalJsFrames,
int totalExpectedFrames, int totalExpectedFrames,
int total4PlusFrameStutters,
double fps, double fps,
double jsFps, double jsFps,
int totalTimeMs) { int totalTimeMs) {
this.totalFrames = totalFrames; this.totalFrames = totalFrames;
this.totalJsFrames = totalJsFrames; this.totalJsFrames = totalJsFrames;
this.totalExpectedFrames = totalExpectedFrames; this.totalExpectedFrames = totalExpectedFrames;
this.total4PlusFrameStutters = total4PlusFrameStutters;
this.fps = fps; this.fps = fps;
this.jsFps = jsFps; this.jsFps = jsFps;
this.totalTimeMs = totalTimeMs; this.totalTimeMs = totalTimeMs;
Expand All @@ -72,6 +75,8 @@ public FpsInfo(
private long mFirstFrameTime = -1; private long mFirstFrameTime = -1;
private long mLastFrameTime = -1; private long mLastFrameTime = -1;
private int mNumFrameCallbacks = 0; private int mNumFrameCallbacks = 0;
private int mExpectedNumFramesPrev = 0;
private int m4PlusFrameStutters = 0;
private int mNumFrameCallbacksWithBatchDispatches = 0; private int mNumFrameCallbacksWithBatchDispatches = 0;
private boolean mIsRecordingFpsInfoAtEachFrame = false; private boolean mIsRecordingFpsInfoAtEachFrame = false;
private @Nullable TreeMap<Long, FpsInfo> mTimeToFps; private @Nullable TreeMap<Long, FpsInfo> mTimeToFps;
Expand Down Expand Up @@ -103,18 +108,25 @@ public void doFrame(long l) {
} }


mNumFrameCallbacks++; mNumFrameCallbacks++;
int expectedNumFrames = getExpectedNumFrames();
int framesDropped = expectedNumFrames - mExpectedNumFramesPrev - 1;
if (framesDropped >= 4) {
m4PlusFrameStutters++;
}


if (mIsRecordingFpsInfoAtEachFrame) { if (mIsRecordingFpsInfoAtEachFrame) {
Assertions.assertNotNull(mTimeToFps); Assertions.assertNotNull(mTimeToFps);
FpsInfo info = new FpsInfo( FpsInfo info = new FpsInfo(
getNumFrames(), getNumFrames(),
getNumJSFrames(), getNumJSFrames(),
getExpectedNumFrames(), expectedNumFrames,
m4PlusFrameStutters,
getFPS(), getFPS(),
getJSFPS(), getJSFPS(),
getTotalTimeMS()); getTotalTimeMS());
mTimeToFps.put(System.currentTimeMillis(), info); mTimeToFps.put(System.currentTimeMillis(), info);
} }
mExpectedNumFramesPrev = expectedNumFrames;


mChoreographer.postFrameCallback(this); mChoreographer.postFrameCallback(this);
} }
Expand Down Expand Up @@ -168,6 +180,10 @@ public int getExpectedNumFrames() {
return expectedFrames; return expectedFrames;
} }


public int get4PlusFrameStutters() {
return m4PlusFrameStutters;
}

public int getTotalTimeMS() { public int getTotalTimeMS() {
return (int) ((double) mLastFrameTime - mFirstFrameTime) / 1000000; return (int) ((double) mLastFrameTime - mFirstFrameTime) / 1000000;
} }
Expand All @@ -189,6 +205,7 @@ public void reset() {
mFirstFrameTime = -1; mFirstFrameTime = -1;
mLastFrameTime = -1; mLastFrameTime = -1;
mNumFrameCallbacks = 0; mNumFrameCallbacks = 0;
m4PlusFrameStutters = 0;
mNumFrameCallbacksWithBatchDispatches = 0; mNumFrameCallbacksWithBatchDispatches = 0;
mIsRecordingFpsInfoAtEachFrame = false; mIsRecordingFpsInfoAtEachFrame = false;
mTimeToFps = null; mTimeToFps = null;
Expand Down
8 changes: 4 additions & 4 deletions ReactAndroid/src/main/res/devsupport/layout/fps_view.xml
Expand Up @@ -7,12 +7,12 @@
android:id="@+id/fps_text" android:id="@+id/fps_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="5dp" android:layout_margin="3dp"
android:background="#aa141823" android:background="#a4141823"
android:gravity="right" android:gravity="right"
android:layout_gravity="top|right" android:layout_gravity="top|right"
android:padding="5dp" android:padding="3dp"
android:textColor="@android:color/white" android:textColor="@android:color/white"
android:textSize="16sp" android:textSize="11sp"
/> />
</merge> </merge>

0 comments on commit dfbee9f

Please sign in to comment.