[fenix] For https://github.com/mozilla-mobile/fenix/issues/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.pull/600/head
parent
21c8f3d1a0
commit
f53adc5b12
@ -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…
Reference in New Issue