88package com.facebook.react.modules.debug
99
1010import android.view.Choreographer
11- import com.facebook.infer.annotation.Assertions
1211import com.facebook.react.bridge.ReactContext
1312import com.facebook.react.bridge.UiThreadUtil
1413import com.facebook.react.common.build.ReactBuildConfig
1514import 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