[fenix] Closes https://github.com/mozilla-mobile/fenix/issues/21424: add marker for StrictMode.resetAfter.

This helps identify file IO. Unfortunately, with this marker, it's
difficult to separate code we own from code we don't own. However, I
wasn't sure what the best implementation would be to address that
(e.g. ideally, we would ignore violations in code we don't own rather than
annotate the markers) so I thought we can land it this simple way and
improve it incrementally.
pull/600/head
Michael Comella 3 years ago committed by mergify[bot]
parent e3b2309ac2
commit 257ae4b118

@ -113,6 +113,18 @@ class StrictModeManager(
* @return the value returned by [functionBlock].
*/
fun <R> resetAfter(policy: StrictMode.ThreadPolicy, functionBlock: () -> R): R {
fun instrumentedFunctionBlock(): R {
val startProfilerTime = components.core.engine.profiler?.getProfilerTime()
val returnValue = functionBlock()
if (mainLooper.thread === Thread.currentThread()) { // markers only supported on main thread.
components.core.engine.profiler?.addMarker("StrictMode.resetAfter", startProfilerTime)
}
return returnValue
}
// Calling resetAfter takes 1-2ms (unknown device) so we only execute it if StrictMode can
// actually be enabled. https://github.com/mozilla-mobile/fenix/issues/11617
return if (isEnabledByBuildConfig) {
@ -122,15 +134,11 @@ class StrictModeManager(
val suppressionCount = suppressionCount.incrementAndGet()
// We log so that devs are more likely to notice that we're suppressing StrictMode violations.
// We add profiler markers so that the perf team can easily identify IO locations in profiles.
logger.warn("StrictMode violation suppressed: #$suppressionCount")
if (Thread.currentThread() == mainLooper.thread) { // markers only supported on main thread.
components.core.engine.profiler?.addMarker("StrictMode.suppression", "Count: $suppressionCount")
}
policy.resetAfter(functionBlock)
policy.resetAfter(::instrumentedFunctionBlock)
} else {
functionBlock()
instrumentedFunctionBlock()
}
}

Loading…
Cancel
Save