For #21299: add markers for all activity lifecycle callbacks.

We implement these all in the same track because between it'd create a
lot noise between this and fragment lifecycle callbacks.
upstream-sync
Michael Comella 3 years ago committed by mergify[bot]
parent 872263cf2d
commit f8a4113271

@ -76,6 +76,7 @@ import org.mozilla.fenix.components.Core
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MozillaProductDetector
import org.mozilla.fenix.components.toolbar.ToolbarPosition
import org.mozilla.fenix.perf.MarkersLifecycleCallbacks
import org.mozilla.fenix.utils.Settings
/**
@ -192,6 +193,7 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
visibilityLifecycleCallback = VisibilityLifecycleCallback(getSystemService())
registerActivityLifecycleCallbacks(visibilityLifecycleCallback)
registerActivityLifecycleCallbacks(MarkersLifecycleCallbacks(components.core.engine))
// Storage maintenance disabled, for now, as it was interfering with background migrations.
// See https://github.com/mozilla-mobile/fenix/issues/7227 for context.

@ -179,9 +179,6 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
private lateinit var startupTypeTelemetry: StartupTypeTelemetry
final override fun onCreate(savedInstanceState: Bundle?) {
// DO NOT MOVE ANYTHING ABOVE THIS addMarker CALL.
components.core.engine.profiler?.addMarker("Activity.onCreate", "HomeActivity")
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()) {

@ -30,9 +30,6 @@ class IntentReceiverActivity : Activity() {
@VisibleForTesting
override fun onCreate(savedInstanceState: Bundle?) {
// DO NOT MOVE ANYTHING ABOVE THIS addMarker CALL.
components.core.engine.profiler?.addMarker("Activity.onCreate", "IntentReceiverActivity")
// StrictMode violation on certain devices such as Samsung
components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
super.onCreate(savedInstanceState)

@ -0,0 +1,59 @@
/* 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.app.Activity
import android.os.Bundle
import mozilla.components.concept.engine.Engine
import org.mozilla.fenix.android.DefaultActivityLifecycleCallbacks
/**
* Adds a profiler marker for each activity lifecycle callbacks. The callbacks are called by the
* super method (e.g. [Activity.onCreate] so the markers occur sometime during the execution of
* our implementation (e.g. [org.mozilla.fenix.HomeActivity.onCreate]) rather than at the beginning
* or end of that method.
*/
class MarkersLifecycleCallbacks(
private val engine: Engine,
) : DefaultActivityLifecycleCallbacks {
private fun shouldSkip(): Boolean {
return engine.profiler?.isProfilerActive() != true
}
override fun onActivityCreated(activity: Activity, bundle: Bundle?) {
if (shouldSkip()) { return }
engine.profiler?.addMarker(MARKER_NAME, "${activity::class.simpleName}.onCreate (via callbacks)")
}
override fun onActivityStarted(activity: Activity) {
if (shouldSkip()) { return }
engine.profiler?.addMarker(MARKER_NAME, "${activity::class.simpleName}.onStart (via callbacks)")
}
override fun onActivityResumed(activity: Activity) {
if (shouldSkip()) { return }
engine.profiler?.addMarker(MARKER_NAME, "${activity::class.simpleName}.onResume (via callbacks)")
}
override fun onActivityPaused(activity: Activity) {
if (shouldSkip()) { return }
engine.profiler?.addMarker(MARKER_NAME, "${activity::class.simpleName}.onPause (via callbacks)")
}
override fun onActivityStopped(activity: Activity) {
if (shouldSkip()) { return }
engine.profiler?.addMarker(MARKER_NAME, "${activity::class.simpleName}.onStop (via callbacks)")
}
override fun onActivityDestroyed(activity: Activity) {
if (shouldSkip()) { return }
engine.profiler?.addMarker(MARKER_NAME, "${activity::class.simpleName}.onDestroy (via callbacks)")
}
companion object {
private const val MARKER_NAME = "Activity Lifecycle"
}
}
Loading…
Cancel
Save