diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index 058e989d06..c05f9a07ce 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -213,7 +213,6 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { binding = ActivityHomeBinding.inflate(layoutInflater) setContentView(binding.root) - binding.root.profilerProvider = { components.core.engine.profiler } ProfilerMarkers.addListenerForOnGlobalLayout(components.core.engine, this, binding.root) // Must be after we set the content view diff --git a/app/src/main/java/org/mozilla/fenix/perf/HomeActivityRootLinearLayout.kt b/app/src/main/java/org/mozilla/fenix/perf/HomeActivityRootLinearLayout.kt index c015a17989..c62617b8f1 100644 --- a/app/src/main/java/org/mozilla/fenix/perf/HomeActivityRootLinearLayout.kt +++ b/app/src/main/java/org/mozilla/fenix/perf/HomeActivityRootLinearLayout.kt @@ -5,12 +5,14 @@ package org.mozilla.fenix.perf import android.content.Context +import android.graphics.Canvas import android.util.AttributeSet import android.widget.LinearLayout import mozilla.components.concept.base.profiler.Profiler import org.mozilla.fenix.HomeActivity +import org.mozilla.fenix.ext.components -private const val DETAIL_TEXT = "RootLinearLayout" +private const val MARKER_NAME = "Measure, Layout, Draw" /** * A [LinearLayout] that adds profiler markers for various methods. This is intended to be used on @@ -18,17 +20,25 @@ private const val DETAIL_TEXT = "RootLinearLayout" */ class HomeActivityRootLinearLayout(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) { - var profilerProvider: () -> Profiler? = { null } + private val profiler: Profiler? = context.components.core.engine.profiler override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { - val profilerStartTime = profilerProvider.invoke()?.getProfilerTime() + val profilerStartTime = profiler?.getProfilerTime() super.onMeasure(widthMeasureSpec, heightMeasureSpec) - profilerProvider.invoke()?.addMarker("onMeasure", profilerStartTime, DETAIL_TEXT) + profiler?.addMarker(MARKER_NAME, profilerStartTime, "onMeasure (HomeActivity root)") } override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) { - val profilerStartTime = profilerProvider.invoke()?.getProfilerTime() + val profilerStartTime = profiler?.getProfilerTime() super.onLayout(changed, l, t, r, b) - profilerProvider.invoke()?.addMarker("onLayout", profilerStartTime, DETAIL_TEXT) + profiler?.addMarker(MARKER_NAME, profilerStartTime, "onLayout (HomeActivity root)") + } + + override fun dispatchDraw(canvas: Canvas?) { + // We instrument dispatchDraw, for drawing children, because LinearLayout never draws itself, + // i.e. it never calls onDraw or draw. + val profilerStartTime = profiler?.getProfilerTime() + super.dispatchDraw(canvas) + profiler?.addMarker(MARKER_NAME, profilerStartTime, "dispatchDraw (HomeActivity root)") } }