mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/21309: add profiler markers on global layout.
This commit is contained in:
parent
595a81aec2
commit
336d681451
@ -207,6 +207,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
|
|||||||
|
|
||||||
binding = ActivityHomeBinding.inflate(layoutInflater)
|
binding = ActivityHomeBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
ProfilerMarkers.addListenerForOnGlobalLayout(components.core.engine, this, binding.root)
|
||||||
|
|
||||||
// Must be after we set the content view
|
// Must be after we set the content view
|
||||||
if (isVisuallyComplete) {
|
if (isVisuallyComplete) {
|
||||||
|
@ -4,9 +4,12 @@
|
|||||||
|
|
||||||
package org.mozilla.fenix.perf
|
package org.mozilla.fenix.perf
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.ViewTreeObserver
|
||||||
import androidx.core.view.doOnPreDraw
|
import androidx.core.view.doOnPreDraw
|
||||||
import mozilla.components.concept.base.profiler.Profiler
|
import mozilla.components.concept.base.profiler.Profiler
|
||||||
|
import mozilla.components.concept.engine.Engine
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A container for functions for when adding a profiler marker is less readable
|
* A container for functions for when adding a profiler marker is less readable
|
||||||
@ -14,9 +17,27 @@ import mozilla.components.concept.base.profiler.Profiler
|
|||||||
*/
|
*/
|
||||||
object ProfilerMarkers {
|
object ProfilerMarkers {
|
||||||
|
|
||||||
|
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")
|
||||||
|
rootView.viewTreeObserver.addOnGlobalLayoutListener(listener)
|
||||||
|
}
|
||||||
|
|
||||||
fun homeActivityOnStart(rootContainer: View, profiler: Profiler?) {
|
fun homeActivityOnStart(rootContainer: View, profiler: Profiler?) {
|
||||||
rootContainer.doOnPreDraw {
|
rootContainer.doOnPreDraw {
|
||||||
profiler?.addMarker("onPreDraw", "expected first frame via HomeActivity.onStart")
|
profiler?.addMarker("onPreDraw", "expected first frame via HomeActivity.onStart")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A global layout listener that adds a profiler marker on global layout.
|
||||||
|
*/
|
||||||
|
class MarkerGlobalLayoutListener(
|
||||||
|
private val engine: Engine,
|
||||||
|
private val activityName: String,
|
||||||
|
) : ViewTreeObserver.OnGlobalLayoutListener {
|
||||||
|
override fun onGlobalLayout() {
|
||||||
|
engine.profiler?.addMarker("onGlobalLayout", activityName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user