2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] Move startup perf measurements to a background thread

This is required to avoid loading the Glean core library (provided by libxul) early on.
Fenix needs to do the time measurement itself for now.
This commit is contained in:
Jan-Erik Rediger 2022-07-22 13:14:17 +02:00 committed by mergify[bot]
parent c089186e14
commit b03ec61ff5
2 changed files with 22 additions and 6 deletions

View File

@ -8,6 +8,7 @@ import android.annotation.SuppressLint
import android.os.Build import android.os.Build
import android.os.Build.VERSION.SDK_INT import android.os.Build.VERSION.SDK_INT
import android.os.StrictMode import android.os.StrictMode
import android.os.SystemClock
import android.util.Log.INFO import android.util.Log.INFO
import androidx.annotation.CallSuper import androidx.annotation.CallSuper
import androidx.annotation.VisibleForTesting import androidx.annotation.VisibleForTesting
@ -113,8 +114,8 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
private set private set
override fun onCreate() { override fun onCreate() {
// We use start/stop instead of measure so we don't measure outside the main process. // We measure ourselves to avoid a call into Glean before its loaded.
val completeMethodDurationTimerId = PerfStartup.applicationOnCreate.start() // DO NOT MOVE ANYTHING ABOVE HERE. val start = SystemClock.elapsedRealtimeNanos()
super.onCreate() super.onCreate()
@ -134,8 +135,16 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
setupInMainProcessOnly() setupInMainProcessOnly()
downloadWallpapers() downloadWallpapers()
// DO NOT MOVE ANYTHING BELOW THIS stop CALL.
PerfStartup.applicationOnCreate.stopAndAccumulate(completeMethodDurationTimerId) // DO NOT MOVE ANYTHING BELOW THIS elapsedRealtimeNanos CALL.
val stop = SystemClock.elapsedRealtimeNanos()
val durationMillis = TimeUnit.NANOSECONDS.toMillis(stop - start)
// We avoid blocking the main thread on startup by calling into Glean on the background thread.
@OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch(Dispatchers.IO) {
PerfStartup.applicationOnCreate.accumulateSamples(listOf(durationMillis))
}
} }
@OptIn(DelicateCoroutinesApi::class) // GlobalScope usage @OptIn(DelicateCoroutinesApi::class) // GlobalScope usage

View File

@ -10,6 +10,10 @@ import androidx.annotation.VisibleForTesting.PRIVATE
import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import mozilla.components.support.base.log.logger.Logger import mozilla.components.support.base.log.logger.Logger
import org.mozilla.fenix.GleanMetrics.PerfStartup import org.mozilla.fenix.GleanMetrics.PerfStartup
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
@ -69,8 +73,11 @@ class StartupTypeTelemetry(
val startupPath = startupPathProvider.startupPathForActivity val startupPath = startupPathProvider.startupPathForActivity
val label = getTelemetryLabel(startupState, startupPath) val label = getTelemetryLabel(startupState, startupPath)
PerfStartup.startupType[label].add(1) @OptIn(DelicateCoroutinesApi::class)
logger.info("Recorded start up: $label") GlobalScope.launch(Dispatchers.IO) {
PerfStartup.startupType[label].add(1)
logger.info("Recorded start up: $label")
}
} }
@VisibleForTesting(otherwise = PRIVATE) @VisibleForTesting(otherwise = PRIVATE)