mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 04:35:36 +08:00
add dropped frame count to FPS overlay
Differential Revision: D2476082 committer: Service User <svcscm@fb.com>
This commit is contained in:
committed by
facebook-github-bot-7
parent
bdb11c05a8
commit
dfbee9f558
@@ -43,7 +43,7 @@ public class FpsView extends FrameLayout {
|
|||||||
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
|
||||||
@@ -61,11 +61,13 @@ public class FpsView extends FrameLayout {
|
|||||||
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);
|
||||||
@@ -77,14 +79,17 @@ public class FpsView extends FrameLayout {
|
|||||||
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);
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ public class FpsDebugFrameCallback implements Choreographer.FrameCallback {
|
|||||||
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;
|
||||||
@@ -49,12 +50,14 @@ public class FpsDebugFrameCallback implements Choreographer.FrameCallback {
|
|||||||
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;
|
||||||
@@ -72,6 +75,8 @@ public class FpsDebugFrameCallback implements Choreographer.FrameCallback {
|
|||||||
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;
|
||||||
@@ -103,18 +108,25 @@ public class FpsDebugFrameCallback implements Choreographer.FrameCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
@@ -168,6 +180,10 @@ public class FpsDebugFrameCallback implements Choreographer.FrameCallback {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
@@ -189,6 +205,7 @@ public class FpsDebugFrameCallback implements Choreographer.FrameCallback {
|
|||||||
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;
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user