@@ -82,41 +82,42 @@ internal class JankStatsMonitor(
8282 }
8383
8484 override fun onFrame (volatileFrameData : FrameData ) {
85+ if (! volatileFrameData.isJank) {
86+ return
87+ }
8588 // From the docs: note that the FrameData object sent in the callback is reused on every frame
8689 // to prevent having to allocate new objects for data reporting.
8790 // This means that you must copy and cache that data elsewhere since that object should be considered stale
8891 // and obsolete as soon as the callback returns.
8992 val frameData = volatileFrameData.copy()
90- if (frameData.isJank) {
91- if (! runtime.isEnabled(RuntimeFeature .DROPPED_EVENTS_MONITORING )) {
92- stopCollection()
93- return
94- }
93+ if (! runtime.isEnabled(RuntimeFeature .DROPPED_EVENTS_MONITORING )) {
94+ stopCollection()
95+ return
96+ }
9597
96- val durationNano = frameData.toDurationNano()
97- val durationMillis = frameData.toDurationMillis()
98- if (durationNano < 0 || durationMillis > ERROR_DURATION_THRESHOLD_MILLIS ) {
99- val errorMessage =
100- " Unexpected frame duration. durationInNano: $durationNano ." +
101- " durationMillis: $durationMillis "
102- errorHandler.handleError(errorMessage)
103- return
104- }
98+ val durationNano = frameData.toDurationNano()
99+ val durationMillis = frameData.toDurationMillis()
100+ if (durationNano < 0 || durationMillis > ERROR_DURATION_THRESHOLD_MILLIS ) {
101+ val errorMessage =
102+ " Unexpected frame duration. durationInNano: $durationNano ." +
103+ " durationMillis: $durationMillis "
104+ errorHandler.handleError(errorMessage)
105+ return
106+ }
105107
106- if (durationMillis < runtime.getConfigValue(RuntimeConfig .MIN_JANK_FRAME_THRESHOLD_MS )
107- ) {
108- // The Frame is considered as Jank but it didn't reached the min
109- // threshold defined by MIN_JANK_FRAME_THRESHOLD_MS config
110- return
111- }
108+ if (durationMillis < runtime.getConfigValue(RuntimeConfig .MIN_JANK_FRAME_THRESHOLD_MS )
109+ ) {
110+ // The Frame is considered as Jank but it didn't reached the min
111+ // threshold defined by MIN_JANK_FRAME_THRESHOLD_MS config
112+ return
113+ }
112114
113- // Below API 24 [onFrame(volatileFrameData)] call happens on the main thread
114- if (Build .VERSION .SDK_INT < Build .VERSION_CODES .N ) {
115- backgroundThreadHandler.runAsync { frameData.sendJankFrameData() }
116- } else {
117- // For >= 24 this happens on `FrameMetricsAggregator` thread
118- frameData.sendJankFrameData()
119- }
115+ // Below API 24 [onFrame(volatileFrameData)] call happens on the main thread
116+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .N ) {
117+ backgroundThreadHandler.runAsync { frameData.sendJankFrameData() }
118+ } else {
119+ // For >= 24 this happens on `FrameMetricsAggregator` thread
120+ frameData.sendJankFrameData()
120121 }
121122 }
122123
0 commit comments