2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/21309: add profiler markers on global layout.

This commit is contained in:
Michael Comella 2021-09-15 08:29:45 -07:00 committed by mergify[bot]
parent 595a81aec2
commit 336d681451
2 changed files with 22 additions and 0 deletions

View File

@ -207,6 +207,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
binding = ActivityHomeBinding.inflate(layoutInflater)
setContentView(binding.root)
ProfilerMarkers.addListenerForOnGlobalLayout(components.core.engine, this, binding.root)
// Must be after we set the content view
if (isVisuallyComplete) {

View File

@ -4,9 +4,12 @@
package org.mozilla.fenix.perf
import android.app.Activity
import android.view.View
import android.view.ViewTreeObserver
import androidx.core.view.doOnPreDraw
import mozilla.components.concept.base.profiler.Profiler
import mozilla.components.concept.engine.Engine
/**
* A container for functions for when adding a profiler marker is less readable
@ -14,9 +17,27 @@ import mozilla.components.concept.base.profiler.Profiler
*/
object ProfilerMarkers {
fun addListenerForOnGlobalLayout(engine: Engine, activity: Activity, rootView: View) {
// We define the listener in a non-anonymous class to avoid memory leaks with the activity.
val listener = MarkerGlobalLayoutListener(engine, activity::class.simpleName ?: "null")
rootView.viewTreeObserver.addOnGlobalLayoutListener(listener)
}
fun homeActivityOnStart(rootContainer: View, profiler: Profiler?) {
rootContainer.doOnPreDraw {
profiler?.addMarker("onPreDraw", "expected first frame via HomeActivity.onStart")
}
}
}
/**
* A global layout listener that adds a profiler marker on global layout.
*/
class MarkerGlobalLayoutListener(
private val engine: Engine,
private val activityName: String,
) : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
engine.profiler?.addMarker("onGlobalLayout", activityName)
}
}