Skip to content

Commit

Permalink
For mozilla-mobile#21299: add duration markers for HomeActivity Creat…
Browse files Browse the repository at this point in the history
…e/Start.

We only instrument these methods because they're the only ones that
noticeably long running in the current implementation.
  • Loading branch information
mcomella authored and mergify[bot] committed Sep 17, 2021
1 parent d67bd65 commit bb632c7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
13 changes: 13 additions & 0 deletions app/src/main/java/org/mozilla/fenix/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ import org.mozilla.fenix.library.bookmarks.DesktopFolders
import org.mozilla.fenix.library.history.HistoryFragmentDirections
import org.mozilla.fenix.library.recentlyclosed.RecentlyClosedFragmentDirections
import org.mozilla.fenix.onboarding.DefaultBrowserNotificationWorker
import org.mozilla.fenix.perf.MarkersLifecycleCallbacks
import org.mozilla.fenix.perf.Performance
import org.mozilla.fenix.perf.PerformanceInflater
import org.mozilla.fenix.perf.ProfilerMarkers
Expand Down Expand Up @@ -179,6 +180,9 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
private lateinit var startupTypeTelemetry: StartupTypeTelemetry

final override fun onCreate(savedInstanceState: Bundle?) {
// DO NOT MOVE ANYTHING ABOVE THIS getProfilerTime CALL.
val startTimeProfiler = components.core.engine.profiler?.getProfilerTime()

components.strictMode.attachListenerToDisablePenaltyDeath(supportFragmentManager)
// There is disk read violations on some devices such as samsung and pixel for android 9/10
components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
Expand Down Expand Up @@ -266,6 +270,9 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
components.core.pocketStoriesService.startPeriodicStoriesRefresh()
}

components.core.engine.profiler?.addMarker(
MarkersLifecycleCallbacks.MARKER_NAME, startTimeProfiler, "HomeActivity.onCreate"
)
StartupTimeline.onActivityCreateEndHome(this) // DO NOT MOVE ANYTHING BELOW HERE.
}

Expand Down Expand Up @@ -316,6 +323,9 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
}

override fun onStart() {
// DO NOT MOVE ANYTHING ABOVE THIS getProfilerTime CALL.
val startProfilerTime = components.core.engine.profiler?.getProfilerTime()

super.onStart()

// Diagnostic breadcrumb for "Display already aquired" crash:
Expand All @@ -325,6 +335,9 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
)

ProfilerMarkers.homeActivityOnStart(binding.rootContainer, components.core.engine.profiler)
components.core.engine.profiler?.addMarker(
MarkersLifecycleCallbacks.MARKER_NAME, startProfilerTime, "HomeActivity.onStart"
) // DO NOT MOVE ANYTHING BELOW THIS addMarker CALL.
}

override fun onStop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package org.mozilla.fenix.perf
import android.app.Activity
import android.os.Bundle
import mozilla.components.concept.engine.Engine
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.IntentReceiverActivity
import org.mozilla.fenix.android.DefaultActivityLifecycleCallbacks

Expand All @@ -26,7 +27,8 @@ class MarkersLifecycleCallbacks(

override fun onActivityCreated(activity: Activity, bundle: Bundle?) {
if (shouldSkip() ||
// This method is manually instrumented with duration.
// These methods are manually instrumented with duration.
activity is HomeActivity ||
activity is IntentReceiverActivity
) {
return
Expand All @@ -35,7 +37,12 @@ class MarkersLifecycleCallbacks(
}

override fun onActivityStarted(activity: Activity) {
if (shouldSkip()) { return }
if (shouldSkip() ||
// These methods are manually instrumented with duration.
activity is HomeActivity
) {
return
}
engine.profiler?.addMarker(MARKER_NAME, "${activity::class.simpleName}.onStart (via callbacks)")
}

Expand Down

0 comments on commit bb632c7

Please sign in to comment.