From 857907977478e1a9cb72323e6a7eb2a4be80a4d1 Mon Sep 17 00:00:00 2001 From: Michael Comella Date: Thu, 28 Oct 2021 14:30:13 -0700 Subject: [PATCH] [fenix] Closes https://github.com/mozilla-mobile/fenix/issues/22213: add marker for LayoutInflater.inflate. Here is a profile with this change: https://share.firefox.dev/3mlQSHu --- .../mozilla/fenix/perf/PerformanceInflater.kt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/perf/PerformanceInflater.kt b/app/src/main/java/org/mozilla/fenix/perf/PerformanceInflater.kt index 2476cb8b5b..755d8901ee 100644 --- a/app/src/main/java/org/mozilla/fenix/perf/PerformanceInflater.kt +++ b/app/src/main/java/org/mozilla/fenix/perf/PerformanceInflater.kt @@ -10,6 +10,8 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.annotation.VisibleForTesting +import mozilla.components.concept.base.profiler.Profiler +import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.getAndIncrementNoOverflow import java.lang.reflect.Modifier.PRIVATE import java.util.concurrent.atomic.AtomicInteger @@ -23,7 +25,6 @@ private val classPrefixList = arrayOf( * Counts the number of inflations fenix does. This class behaves only as an inflation counter since * it takes the `inflater` that is given by the base system. This is done in order not to change * the behavior of the app since all we want to do is count the inflations done. - * */ open class PerformanceInflater( inflater: LayoutInflater, @@ -33,13 +34,24 @@ open class PerformanceInflater( context ) { + private val profiler: Profiler? = context.components.core.engine.profiler + override fun cloneInContext(newContext: Context?): LayoutInflater { return PerformanceInflater(this, newContext!!) } override fun inflate(resource: Int, root: ViewGroup?, attachToRoot: Boolean): View { InflationCounter.inflationCount.getAndIncrementNoOverflow() - return super.inflate(resource, root, attachToRoot) + + val profilerStartTime = profiler?.getProfilerTime() + val layout = super.inflate(resource, root, attachToRoot) + + // I'm not sure how expensive fetching a resource name is so only do it if the profiler is active. + if (profiler?.isProfilerActive() == true) { + val layoutName = context.resources.getResourceEntryName(resource) + profiler.addMarker("LayoutInflater.inflate", profilerStartTime, layoutName) + } + return layout } /**