diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index de29c0e95..b1c21508b 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -53,6 +53,7 @@ import org.mozilla.fenix.library.bookmarks.BookmarkFragmentDirections import org.mozilla.fenix.library.history.HistoryFragmentDirections import org.mozilla.fenix.onboarding.FenixOnboarding import org.mozilla.fenix.perf.HotStartPerformanceMonitor +import org.mozilla.fenix.perf.Performance import org.mozilla.fenix.search.SearchFragmentDirections import org.mozilla.fenix.settings.DefaultBrowserSettingsFragmentDirections import org.mozilla.fenix.settings.SettingsFragmentDirections @@ -92,6 +93,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity() { setupThemeAndBrowsingMode(getModeFromIntentOrLastKnown(intent)) setContentView(R.layout.activity_home) + Performance.instrumentColdStartupToHomescreenTime(this) setupToolbarAndNavigation() if (intent.getBooleanExtra(EXTRA_FINISH_ONBOARDING, false)) { diff --git a/app/src/main/java/org/mozilla/fenix/perf/Performance.kt b/app/src/main/java/org/mozilla/fenix/perf/Performance.kt index ea4bd81f9..d148e1fe2 100644 --- a/app/src/main/java/org/mozilla/fenix/perf/Performance.kt +++ b/app/src/main/java/org/mozilla/fenix/perf/Performance.kt @@ -4,9 +4,37 @@ package org.mozilla.fenix.perf +import androidx.core.view.doOnPreDraw +import kotlinx.android.synthetic.main.activity_home.* +import org.mozilla.fenix.HomeActivity + /** * A collection of objects related to app performance. */ object Performance { const val TAG = "FenixPerf" + + /** + * Instruments cold startup time for use with our internal measuring system, FNPRMS. This may + * also appear in Google Play Vitals dashboards. + * + * This will need to be rewritten if any parts of the UI are changed to be displayed + * asynchronously. + * + * In the current implementation, we only intend to instrument cold startup to the homescreen. + * To save implementation time, we ignore the fact that the RecyclerView draws twice if the user + * has tabs, collections, etc. open: the "No tabs" placeholder and a tab list. This + * instrumentation will only capture the "No tabs" draw. + */ + fun instrumentColdStartupToHomescreenTime(activity: HomeActivity) { + // For greater accuracy, we could add an onDrawListener instead of a preDrawListener but: + // - single use onDrawListeners are not built-in and it's non-trivial to write one + // - the difference is timing is minimal (< 7ms on Pixel 2) + // - if we compare against another app using a preDrawListener, it should be comparable + // + // Unfortunately, this is tightly coupled to the root view of HomeActivity's view hierarchy + activity.rootContainer.doOnPreDraw { + activity.reportFullyDrawn() + } + } } diff --git a/app/src/main/res/layout/activity_home.xml b/app/src/main/res/layout/activity_home.xml index 0dac2d9e8..f37e7e902 100644 --- a/app/src/main/res/layout/activity_home.xml +++ b/app/src/main/res/layout/activity_home.xml @@ -7,6 +7,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" + android:id="@+id/rootContainer" tools:context=".HomeActivity">