8
8
package com.facebook.react.modules.debug
9
9
10
10
import android.view.Choreographer
11
- import com.facebook.infer.annotation.Assertions
12
11
import com.facebook.react.bridge.ReactContext
13
12
import com.facebook.react.bridge.UiThreadUtil
14
13
import com.facebook.react.common.build.ReactBuildConfig
15
14
import com.facebook.react.uimanager.UIManagerModule
16
- import java.util.TreeMap
17
15
18
16
/* *
19
17
* 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
25
23
* idle and not trying to update the UI. This is different from the FPS above since JS rendering is
26
24
* async.
27
25
*/
28
- public class FpsDebugFrameCallback (private val reactContext : ReactContext ) :
26
+ internal class FpsDebugFrameCallback (private val reactContext : ReactContext ) :
29
27
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
- )
39
28
40
29
private var choreographer: Choreographer ? = null
41
30
private val didJSUpdateUiDuringFrameDetector: DidJSUpdateUiDuringFrameDetector =
@@ -46,9 +35,7 @@ public class FpsDebugFrameCallback(private val reactContext: ReactContext) :
46
35
private var expectedNumFramesPrev = 0
47
36
private var fourPlusFrameStutters = 0
48
37
private var numFrameCallbacksWithBatchDispatches = 0
49
- private var isRecordingFpsInfoAtEachFrame = false
50
38
private var targetFps = DEFAULT_FPS
51
- private var timeToFps: TreeMap <Long , FpsInfo >? = null
52
39
53
40
override fun doFrame (l : Long ) {
54
41
if (firstFrameTime == - 1L ) {
@@ -65,25 +52,12 @@ public class FpsDebugFrameCallback(private val reactContext: ReactContext) :
65
52
if (framesDropped >= 4 ) {
66
53
fourPlusFrameStutters++
67
54
}
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
- }
81
55
expectedNumFramesPrev = expectedNumFrames
82
56
choreographer?.postFrameCallback(this )
83
57
}
84
58
85
59
@JvmOverloads
86
- public fun start (targetFps : Double = this.targetFps) {
60
+ fun start (targetFps : Double = this.targetFps) {
87
61
// T172641976: re-think if we need to implement addBridgeIdleDebugListener and
88
62
// removeBridgeIdleDebugListener for Bridgeless
89
63
@Suppress(" DEPRECATION" )
@@ -101,13 +75,7 @@ public class FpsDebugFrameCallback(private val reactContext: ReactContext) :
101
75
}
102
76
}
103
77
104
- public fun startAndRecordFpsAtEachFrame () {
105
- timeToFps = TreeMap ()
106
- isRecordingFpsInfoAtEachFrame = true
107
- start()
108
- }
109
-
110
- public fun stop () {
78
+ fun stop () {
111
79
@Suppress(" DEPRECATION" )
112
80
if (! ReactBuildConfig .UNSTABLE_ENABLE_MINIFY_LEGACY_ARCHITECTURE ) {
113
81
val uiManagerModule = reactContext.getNativeModule(UIManagerModule ::class .java)
@@ -123,53 +91,41 @@ public class FpsDebugFrameCallback(private val reactContext: ReactContext) :
123
91
}
124
92
}
125
93
126
- public val fps: Double
94
+ val fps: Double
127
95
get() =
128
96
if (lastFrameTime == firstFrameTime) {
129
97
0.0
130
98
} else numFrames.toDouble() * 1e9 / (lastFrameTime - firstFrameTime)
131
99
132
- public val jsFPS: Double
100
+ val jsFPS: Double
133
101
get() =
134
102
if (lastFrameTime == firstFrameTime) {
135
103
0.0
136
104
} else numJSFrames.toDouble() * 1e9 / (lastFrameTime - firstFrameTime)
137
105
138
- public val numFrames: Int
106
+ val numFrames: Int
139
107
get() = numFrameCallbacks - 1
140
108
141
- public val numJSFrames: Int
109
+ private val numJSFrames: Int
142
110
get() = numFrameCallbacksWithBatchDispatches - 1
143
111
144
- public val expectedNumFrames: Int
112
+ val expectedNumFrames: Int
145
113
get() {
146
114
val totalTimeMS = totalTimeMS.toDouble()
147
115
return (targetFps * totalTimeMS / 1000 + 1 ).toInt()
148
116
}
149
117
150
- public fun get4PlusFrameStutters (): Int = fourPlusFrameStutters
118
+ fun get4PlusFrameStutters (): Int = fourPlusFrameStutters
151
119
152
- public val totalTimeMS: Int
120
+ private val totalTimeMS: Int
153
121
get() = ((lastFrameTime.toDouble() - firstFrameTime) / 1000000.0 ).toInt()
154
122
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 () {
166
124
firstFrameTime = - 1
167
125
lastFrameTime = - 1
168
126
numFrameCallbacks = 0
169
127
fourPlusFrameStutters = 0
170
128
numFrameCallbacksWithBatchDispatches = 0
171
- isRecordingFpsInfoAtEachFrame = false
172
- timeToFps = null
173
129
}
174
130
175
131
private companion object {
0 commit comments