Skip to content

Commit cf6569b

Browse files
cortinicofacebook-github-bot
authored andcommitted
Cleanup and internalize FpsDebugFrameCallback (facebook#51982)
Summary: Pull Request resolved: facebook#51982 This class should not be accessed externally. I'm making it internal. On top of this, it was not fully reimplemented on NewArch so is not working consistently. This is gonna break one library which is unmaintained and not properly udpated to work with NewArch https://github.com/hannojg/react-native-performance-stats Changelog: [Android] [Breaking] - Cleanup and internalize FpsDebugFrameCallback Reviewed By: huntie Differential Revision: D76531175 fbshipit-source-id: 25598eb7c1ecf476b69bb6a2f2f8088a57b9fbc2
1 parent c64f698 commit cf6569b

File tree

2 files changed

+11
-85
lines changed

2 files changed

+11
-85
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2747,36 +2747,6 @@ public final class com/facebook/react/modules/debug/DevSettingsModule : com/face
27472747
public final class com/facebook/react/modules/debug/DevSettingsModule$Companion {
27482748
}
27492749

2750-
public final class com/facebook/react/modules/debug/FpsDebugFrameCallback : android/view/Choreographer$FrameCallback {
2751-
public fun <init> (Lcom/facebook/react/bridge/ReactContext;)V
2752-
public fun doFrame (J)V
2753-
public final fun get4PlusFrameStutters ()I
2754-
public final fun getExpectedNumFrames ()I
2755-
public final fun getFps ()D
2756-
public final fun getFpsInfo (J)Lcom/facebook/react/modules/debug/FpsDebugFrameCallback$FpsInfo;
2757-
public final fun getJsFPS ()D
2758-
public final fun getNumFrames ()I
2759-
public final fun getNumJSFrames ()I
2760-
public final fun getTotalTimeMS ()I
2761-
public final fun reset ()V
2762-
public final fun start ()V
2763-
public final fun start (D)V
2764-
public static synthetic fun start$default (Lcom/facebook/react/modules/debug/FpsDebugFrameCallback;DILjava/lang/Object;)V
2765-
public final fun startAndRecordFpsAtEachFrame ()V
2766-
public final fun stop ()V
2767-
}
2768-
2769-
public final class com/facebook/react/modules/debug/FpsDebugFrameCallback$FpsInfo {
2770-
public fun <init> (IIIIDDI)V
2771-
public final fun getFps ()D
2772-
public final fun getJsFps ()D
2773-
public final fun getTotal4PlusFrameStutters ()I
2774-
public final fun getTotalExpectedFrames ()I
2775-
public final fun getTotalFrames ()I
2776-
public final fun getTotalJsFrames ()I
2777-
public final fun getTotalTimeMs ()I
2778-
}
2779-
27802750
public final class com/facebook/react/modules/debug/SourceCodeModule : com/facebook/fbreact/specs/NativeSourceCodeSpec {
27812751
public static final field Companion Lcom/facebook/react/modules/debug/SourceCodeModule$Companion;
27822752
public static final field NAME Ljava/lang/String;

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.kt

Lines changed: 11 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
package com.facebook.react.modules.debug
99

1010
import android.view.Choreographer
11-
import com.facebook.infer.annotation.Assertions
1211
import com.facebook.react.bridge.ReactContext
1312
import com.facebook.react.bridge.UiThreadUtil
1413
import com.facebook.react.common.build.ReactBuildConfig
1514
import com.facebook.react.uimanager.UIManagerModule
16-
import java.util.TreeMap
1715

1816
/**
1917
* Each time a frame is drawn, records whether it should have expected any more callbacks since the
@@ -25,17 +23,8 @@ import java.util.TreeMap
2523
* idle and not trying to update the UI. This is different from the FPS above since JS rendering is
2624
* async.
2725
*/
28-
public class FpsDebugFrameCallback(private val reactContext: ReactContext) :
26+
internal class FpsDebugFrameCallback(private val reactContext: ReactContext) :
2927
Choreographer.FrameCallback {
30-
public class FpsInfo(
31-
public val totalFrames: Int,
32-
public val totalJsFrames: Int,
33-
public val totalExpectedFrames: Int,
34-
public val total4PlusFrameStutters: Int,
35-
public val fps: Double,
36-
public val jsFps: Double,
37-
public val totalTimeMs: Int
38-
)
3928

4029
private var choreographer: Choreographer? = null
4130
private val didJSUpdateUiDuringFrameDetector: DidJSUpdateUiDuringFrameDetector =
@@ -46,9 +35,7 @@ public class FpsDebugFrameCallback(private val reactContext: ReactContext) :
4635
private var expectedNumFramesPrev = 0
4736
private var fourPlusFrameStutters = 0
4837
private var numFrameCallbacksWithBatchDispatches = 0
49-
private var isRecordingFpsInfoAtEachFrame = false
5038
private var targetFps = DEFAULT_FPS
51-
private var timeToFps: TreeMap<Long, FpsInfo>? = null
5239

5340
override fun doFrame(l: Long) {
5441
if (firstFrameTime == -1L) {
@@ -65,25 +52,12 @@ public class FpsDebugFrameCallback(private val reactContext: ReactContext) :
6552
if (framesDropped >= 4) {
6653
fourPlusFrameStutters++
6754
}
68-
if (isRecordingFpsInfoAtEachFrame) {
69-
Assertions.assertNotNull(timeToFps)
70-
val info =
71-
FpsInfo(
72-
numFrames,
73-
numJSFrames,
74-
expectedNumFrames,
75-
fourPlusFrameStutters,
76-
fps,
77-
jsFPS,
78-
totalTimeMS)
79-
timeToFps?.put(System.currentTimeMillis(), info)
80-
}
8155
expectedNumFramesPrev = expectedNumFrames
8256
choreographer?.postFrameCallback(this)
8357
}
8458

8559
@JvmOverloads
86-
public fun start(targetFps: Double = this.targetFps) {
60+
fun start(targetFps: Double = this.targetFps) {
8761
// T172641976: re-think if we need to implement addBridgeIdleDebugListener and
8862
// removeBridgeIdleDebugListener for Bridgeless
8963
@Suppress("DEPRECATION")
@@ -101,13 +75,7 @@ public class FpsDebugFrameCallback(private val reactContext: ReactContext) :
10175
}
10276
}
10377

104-
public fun startAndRecordFpsAtEachFrame() {
105-
timeToFps = TreeMap()
106-
isRecordingFpsInfoAtEachFrame = true
107-
start()
108-
}
109-
110-
public fun stop() {
78+
fun stop() {
11179
@Suppress("DEPRECATION")
11280
if (!ReactBuildConfig.UNSTABLE_ENABLE_MINIFY_LEGACY_ARCHITECTURE) {
11381
val uiManagerModule = reactContext.getNativeModule(UIManagerModule::class.java)
@@ -123,53 +91,41 @@ public class FpsDebugFrameCallback(private val reactContext: ReactContext) :
12391
}
12492
}
12593

126-
public val fps: Double
94+
val fps: Double
12795
get() =
12896
if (lastFrameTime == firstFrameTime) {
12997
0.0
13098
} else numFrames.toDouble() * 1e9 / (lastFrameTime - firstFrameTime)
13199

132-
public val jsFPS: Double
100+
val jsFPS: Double
133101
get() =
134102
if (lastFrameTime == firstFrameTime) {
135103
0.0
136104
} else numJSFrames.toDouble() * 1e9 / (lastFrameTime - firstFrameTime)
137105

138-
public val numFrames: Int
106+
val numFrames: Int
139107
get() = numFrameCallbacks - 1
140108

141-
public val numJSFrames: Int
109+
private val numJSFrames: Int
142110
get() = numFrameCallbacksWithBatchDispatches - 1
143111

144-
public val expectedNumFrames: Int
112+
val expectedNumFrames: Int
145113
get() {
146114
val totalTimeMS = totalTimeMS.toDouble()
147115
return (targetFps * totalTimeMS / 1000 + 1).toInt()
148116
}
149117

150-
public fun get4PlusFrameStutters(): Int = fourPlusFrameStutters
118+
fun get4PlusFrameStutters(): Int = fourPlusFrameStutters
151119

152-
public val totalTimeMS: Int
120+
private val totalTimeMS: Int
153121
get() = ((lastFrameTime.toDouble() - firstFrameTime) / 1000000.0).toInt()
154122

155-
/**
156-
* Returns the FpsInfo as if stop had been called at the given upToTimeMs. Only valid if
157-
* monitoring was started with [startAndRecordFpsAtEachFrame].
158-
*/
159-
public fun getFpsInfo(upToTimeMs: Long): FpsInfo? {
160-
Assertions.assertNotNull(timeToFps, "FPS was not recorded at each frame!")
161-
val (_, value) = timeToFps?.floorEntry(upToTimeMs) ?: return null
162-
return value
163-
}
164-
165-
public fun reset() {
123+
fun reset() {
166124
firstFrameTime = -1
167125
lastFrameTime = -1
168126
numFrameCallbacks = 0
169127
fourPlusFrameStutters = 0
170128
numFrameCallbacksWithBatchDispatches = 0
171-
isRecordingFpsInfoAtEachFrame = false
172-
timeToFps = null
173129
}
174130

175131
private companion object {

0 commit comments

Comments
 (0)