@ -5,12 +5,14 @@
package org.mozilla.fenix.perf
package org.mozilla.fenix.perf
import android.content.Context
import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import android.util.AttributeSet
import android.widget.LinearLayout
import android.widget.LinearLayout
import mozilla.components.concept.base.profiler.Profiler
import mozilla.components.concept.base.profiler.Profiler
import org.mozilla.fenix.HomeActivity
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
* 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 ) {
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 ) {
override fun onMeasure ( widthMeasureSpec : Int , heightMeasureSpec : Int ) {
val profilerStartTime = profiler Provider. invoke ( ) ?. getProfilerTime ( )
val profilerStartTime = profiler ?. getProfilerTime ( )
super . onMeasure ( widthMeasureSpec , heightMeasureSpec )
super . onMeasure ( widthMeasureSpec , heightMeasureSpec )
profiler Provider. 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 ) {
override fun onLayout ( changed : Boolean , l : Int , t : Int , r : Int , b : Int ) {
val profilerStartTime = profiler Provider. invoke ( ) ?. getProfilerTime ( )
val profilerStartTime = profiler ?. getProfilerTime ( )
super . onLayout ( changed , l , t , r , b )
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) " )
}
}
}
}