[fenix] For https://github.com/mozilla-mobile/fenix/issues/22054: add marker for root view layout/measure.
The onLayout marker may be redundant to onGlobalLayout marker but I'm not sure yet so let's leave them both in and observe if that's the case. Here's a profile with the markers: https://share.firefox.dev/3lZaOQbpull/600/head
parent
888e9365cc
commit
2f7d5c03f6
@ -0,0 +1,33 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.perf
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.LinearLayout
|
||||
import mozilla.components.concept.base.profiler.Profiler
|
||||
|
||||
private const val DETAIL_TEXT = "RootLinearLayout"
|
||||
|
||||
/**
|
||||
* A [LinearLayout] that adds profiler markers for various methods. This is intended to be used on
|
||||
* the root view of the view hierarchy to understand global measure/layout events.
|
||||
*/
|
||||
class RootLinearLayout(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) {
|
||||
|
||||
var profilerProvider: () -> Profiler? = { null }
|
||||
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
val profilerStartTime = profilerProvider.invoke()?.getProfilerTime()
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||
profilerProvider.invoke()?.addMarker("onMeasure", profilerStartTime, DETAIL_TEXT)
|
||||
}
|
||||
|
||||
override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
|
||||
val profilerStartTime = profilerProvider.invoke()?.getProfilerTime()
|
||||
super.onLayout(changed, l, t, r, b)
|
||||
profilerProvider.invoke()?.addMarker("onLayout", profilerStartTime, DETAIL_TEXT)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue