For #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/3lZaOQb
upstream-sync
Michael Comella 3 years ago committed by mergify[bot]
parent 1234d8f518
commit 623914bd89

@ -211,6 +211,7 @@ 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

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

@ -1,7 +1,8 @@
<!-- 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/. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<org.mozilla.fenix.perf.RootLinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
@ -24,4 +25,4 @@
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph" />
</LinearLayout>
</org.mozilla.fenix.perf.RootLinearLayout>

Loading…
Cancel
Save