Skip to content

Commit

Permalink
[Android] [Dropped Frames] Adding another config value for min thresh…
Browse files Browse the repository at this point in the history
…old (#231)

* Add another guard for min Jank threshold

* Add another guard for min Jank threshold

* Remove dupe

* Line break for lint fix

* PR feedback - Keep checking for main killswitch
  • Loading branch information
FranAguilera authored Feb 21, 2025
1 parent 098a741 commit 7f7ac1c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ internal class JankStatsMonitor(
return
}

if (volatileFrameData.durationToMilli()
< runtime.getConfigValue(RuntimeConfig.MIN_JANK_FRAME_THRESHOLD_MS)
) {
// The Frame is considered as Jank but it didn't reached the min
// threshold defined by MIN_JANK_FRAME_THRESHOLD_MS config
return
}

// Below API 24 [onFrame(volatileFrameData)] call happens on the main thread
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
backgroundThreadHandler.runAsync { volatileFrameData.sendJankFrameData() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class JankStatsMonitorTest {
whenever(windowManager.getCurrentWindow()).thenReturn(window)

whenever(runtime.isEnabled(RuntimeFeature.DROPPED_EVENTS_MONITORING)).thenReturn(true)
whenever(runtime.getConfigValue(RuntimeConfig.MIN_JANK_FRAME_THRESHOLD_MS)).thenReturn(16)
whenever(runtime.getConfigValue(RuntimeConfig.FROZEN_FRAME_THRESHOLD_MS)).thenReturn(700)
whenever(runtime.getConfigValue(RuntimeConfig.ANR_FRAME_THRESHOLD_MS)).thenReturn(5000)

Expand Down Expand Up @@ -129,6 +130,17 @@ class JankStatsMonitorTest {
assertLogDetails(jankDurationInMilli, LogLevel.ERROR, "ANR")
}

@Test
fun onStateChanged_withJankyFrameBelowMinThreshold_shouldNotLogAnyMessage() {
triggerLifecycleEvent(
lifecycleEvent = Lifecycle.Event.ON_RESUME,
isJankyFrame = true,
durationInMilli = 4L,
)

verify(logger, never()).log(any(), any(), any(), any())
}

@Test
fun onStateChanged_withOnCreateAndAnrFrame_shouldNotLogAnyMessage() {
val jankDurationInMilli = 5000L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,23 @@ sealed class RuntimeConfig(
*/
data object JANK_FRAME_HEURISTICS_MULTIPLIER : RuntimeConfig("client_feature.android.jank_frame_heuristics_multiplier", 2)

/**
* The lower bound threshold on what it defines a Jank Frame by its duration [JankStats]
*
* The default value is 16 ms
*
* Slow Frame: >= MIN_JANK_FRAME_THRESHOLD_MS to < FROZEN_FRAME_THRESHOLD_MS
* Frozen Frame: >= FROZEN_FRAME_THRESHOLD_MS to < ANR_FRAME_THRESHOLD_MS
* ANR Frame: >= ANR_FRAME_THRESHOLD_MS
*/
data object MIN_JANK_FRAME_THRESHOLD_MS : RuntimeConfig("client_feature.android.min_jank_frame.threshold_ms", 16)

/**
* The upper bound threshold that defines what constitutes a FROZEN frame reported via [JankStats]
*
* The default value is 700ms
*
* Slow Frame: >= 16ms to < FROZEN_FRAME_THRESHOLD_MS
* Slow Frame: >= MIN_JANK_FRAME_THRESHOLD_MS to < FROZEN_FRAME_THRESHOLD_MS
* Frozen Frame: >= FROZEN_FRAME_THRESHOLD_MS to < ANR_FRAME_THRESHOLD_MS
* ANR Frame: >= ANR_FRAME_THRESHOLD_MS
*/
Expand All @@ -99,7 +110,7 @@ sealed class RuntimeConfig(
*
* The default value is 5000ms
*
* Slow Frame: >= 16ms to < FROZEN_FRAME_THRESHOLD_MS
* Slow Frame: >= MIN_JANK_FRAME_THRESHOLD_MS to < FROZEN_FRAME_THRESHOLD_MS
* Frozen Frame: >= FROZEN_FRAME_THRESHOLD_MS to < ANR_FRAME_THRESHOLD_MS
* ANR Frame: >= ANR_FRAME_THRESHOLD_MS
*/
Expand Down

0 comments on commit 7f7ac1c

Please sign in to comment.