For #22177: change onMeasure/onLayout markers into a single track + draw.

When you want to look at one of these markers, you usually want to look
at all three so I found that having them on a single track was easier to
follow. Since they run in sequence, they should never overlap and that
should minimize confusion.
upstream-sync
Michael Comella 3 years ago committed by mergify[bot]
parent ed8f2c0bc3
commit bc6d8be9c1

@ -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

@ -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)")
}
}

Loading…
Cancel
Save