For #22177: add SearchDialogFragmentConstraintLayout; has markers.

Here's a profile with these changes: https://share.firefox.dev/3vTpZha
upstream-sync
Michael Comella 3 years ago committed by mergify[bot]
parent bc6d8be9c1
commit 7d67b84a92

@ -11,8 +11,7 @@ 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 MARKER_NAME = "Measure, Layout, Draw"
import org.mozilla.fenix.perf.ProfilerMarkers.MEASURE_LAYOUT_DRAW_MARKER_NAME
/**
* A [LinearLayout] that adds profiler markers for various methods. This is intended to be used on
@ -25,13 +24,13 @@ class HomeActivityRootLinearLayout(context: Context, attrs: AttributeSet) : Line
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val profilerStartTime = profiler?.getProfilerTime()
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
profiler?.addMarker(MARKER_NAME, profilerStartTime, "onMeasure (HomeActivity root)")
profiler?.addMarker(MEASURE_LAYOUT_DRAW_MARKER_NAME, profilerStartTime, "onMeasure (HomeActivity root)")
}
override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
val profilerStartTime = profiler?.getProfilerTime()
super.onLayout(changed, l, t, r, b)
profiler?.addMarker(MARKER_NAME, profilerStartTime, "onLayout (HomeActivity root)")
profiler?.addMarker(MEASURE_LAYOUT_DRAW_MARKER_NAME, profilerStartTime, "onLayout (HomeActivity root)")
}
override fun dispatchDraw(canvas: Canvas?) {
@ -39,6 +38,6 @@ class HomeActivityRootLinearLayout(context: Context, attrs: AttributeSet) : Line
// i.e. it never calls onDraw or draw.
val profilerStartTime = profiler?.getProfilerTime()
super.dispatchDraw(canvas)
profiler?.addMarker(MARKER_NAME, profilerStartTime, "dispatchDraw (HomeActivity root)")
profiler?.addMarker(MEASURE_LAYOUT_DRAW_MARKER_NAME, profilerStartTime, "dispatchDraw (HomeActivity root)")
}
}

@ -18,6 +18,8 @@ import mozilla.components.concept.engine.Engine
*/
object ProfilerMarkers {
const val MEASURE_LAYOUT_DRAW_MARKER_NAME = "Measure, Layout, Draw"
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")

@ -0,0 +1,43 @@
/* 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.graphics.Canvas
import android.util.AttributeSet
import androidx.constraintlayout.widget.ConstraintLayout
import mozilla.components.concept.base.profiler.Profiler
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.perf.ProfilerMarkers.MEASURE_LAYOUT_DRAW_MARKER_NAME
import org.mozilla.fenix.search.SearchDialogFragment
/**
* Adds markers for measure/layout/draw to the root layout of [SearchDialogFragment].
*/
class SearchDialogFragmentConstraintLayout(context: Context, attrs: AttributeSet) : ConstraintLayout(context, attrs) {
private val profiler: Profiler? = context.components.core.engine.profiler
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val profilerStartTime = profiler?.getProfilerTime()
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
profiler?.addMarker(MEASURE_LAYOUT_DRAW_MARKER_NAME, profilerStartTime, "onMeasure (SearchDialogFragment root)")
}
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
val profilerStartTime = profiler?.getProfilerTime()
super.onLayout(changed, left, top, right, bottom)
profiler?.addMarker(MEASURE_LAYOUT_DRAW_MARKER_NAME, profilerStartTime, "onLayout (SearchDialogFragment root)")
}
override fun draw(canvas: Canvas?) {
// We instrument draw, rather than onDraw or dispatchDraw, because ConstraintLayout's draw includes
// both of the other methods. If we want to track how long it takes to draw the children,
// we'd get more information by instrumenting them individually.
val profilerStartTime = profiler?.getProfilerTime()
super.draw(canvas)
profiler?.addMarker(MEASURE_LAYOUT_DRAW_MARKER_NAME, profilerStartTime, "draw (SearchDialogFragment root)")
}
}

@ -2,7 +2,7 @@
<!-- 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/. -->
<androidx.constraintlayout.widget.ConstraintLayout
<org.mozilla.fenix.perf.SearchDialogFragmentConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
@ -190,4 +190,4 @@
app:layout_constraintBottom_toBottomOf="@id/pill_wrapper"
app:layout_constraintStart_toEndOf="@id/qr_scan_button"
app:layout_constraintTop_toTopOf="@id/pill_wrapper" />
</androidx.constraintlayout.widget.ConstraintLayout>
</org.mozilla.fenix.perf.SearchDialogFragmentConstraintLayout>

Loading…
Cancel
Save