Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ad57cd65 authored by Peter Kalauskas's avatar Peter Kalauskas
Browse files

Trace CoroutineScope usage

Changes to coroutine tracing to better trace parent-child scopes.

Test: Build, install, capture trace
Flag: com.android.systemui.coroutine_tracing
Bug: 289353932
Change-Id: Icbff1c16951bec4157f8553bdca2b79d95e829b5
parent d09a2578
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import com.android.app.tracing.coroutines.createCoroutineTracingContext

class HomeControlsDreamService
@Inject
@@ -53,7 +54,7 @@ constructor(
) : DreamService() {

    private val serviceJob = SupervisorJob()
    private val serviceScope = CoroutineScope(bgDispatcher + serviceJob)
    private val serviceScope = CoroutineScope(bgDispatcher + serviceJob + createCoroutineTracingContext("HomeControlsDreamService"))
    private val logger = DreamLogger(logBuffer, TAG)
    private lateinit var taskFragmentComponent: TaskFragmentComponent
    private val wakeLock: WakeLock by lazy {
+2 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.education.dagger

import com.android.app.tracing.coroutines.createCoroutineTracingContext
import com.android.systemui.CoreStartable
import com.android.systemui.Flags
import com.android.systemui.contextualeducation.GestureType
@@ -56,7 +57,7 @@ interface ContextualEducationModule {
        fun provideEduDataStoreScope(
            @Background bgDispatcher: CoroutineDispatcher
        ): CoroutineScope {
            return CoroutineScope(bgDispatcher + SupervisorJob())
            return CoroutineScope(bgDispatcher + SupervisorJob() + createCoroutineTracingContext("EduDataStoreScope"))
        }

        @EduClock
+2 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@

package com.android.systemui.keyguard.ui.preview

import com.android.app.tracing.coroutines.createCoroutineTracingContext
import android.app.WallpaperColors
import android.content.BroadcastReceiver
import android.content.Context
@@ -187,7 +188,7 @@ constructor(
    private var themeStyle: Style? = null

    init {
        coroutineScope = CoroutineScope(applicationScope.coroutineContext + Job())
        coroutineScope = CoroutineScope(applicationScope.coroutineContext + Job() + createCoroutineTracingContext("KeyguardPreviewRenderer"))
        disposables += DisposableHandle { coroutineScope.cancel() }
        clockController.setFallbackWeatherData(WeatherData.getPlaceholderWeatherData())

+5 −3
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import androidx.lifecycle.lifecycleScope
import com.android.app.tracing.coroutines.createCoroutineTracingContext
import com.android.app.tracing.coroutines.launch
import com.android.app.tracing.coroutines.traceCoroutine
import com.android.systemui.Flags.coroutineTracing
import com.android.systemui.util.Assert
import com.android.systemui.util.Compile
@@ -45,6 +45,7 @@ import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.launch

/**
 * Runs the given [block] every time the [View] becomes attached (or immediately after calling this
@@ -137,7 +138,7 @@ private fun createLifecycleOwnerAndRun(
): ViewLifecycleOwner {
    return ViewLifecycleOwner(view).apply {
        onCreate()
        lifecycleScope.launch(nameForTrace, coroutineContext) { block(view) }
        lifecycleScope.launch(coroutineContext) { traceCoroutine(nameForTrace) { block(view) } }
    }
}

@@ -367,7 +368,8 @@ private val ViewTreeObserver.isWindowVisible
 * an extension function, and plumbing dagger-injected instances for static usage has little
 * benefit.
 */
private val MAIN_DISPATCHER_SINGLETON = Dispatchers.Main + createCoroutineTracingContext()
private val MAIN_DISPATCHER_SINGLETON =
    Dispatchers.Main + createCoroutineTracingContext("RepeatWhenAttached")
private const val DEFAULT_TRACE_NAME = "repeatWhenAttached"
private const val CURRENT_CLASS_NAME = "com.android.systemui.lifecycle.RepeatWhenAttachedKt"
private const val JAVA_ADAPTER_CLASS_NAME = "com.android.systemui.util.kotlin.JavaAdapterKt"
+2 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.mediaprojection.appselector

import com.android.app.tracing.coroutines.createCoroutineTracingContext
import android.app.Activity
import android.content.ComponentName
import android.content.Context
@@ -133,7 +134,7 @@ interface MediaProjectionAppSelectorModule {
        @MediaProjectionAppSelector
        @MediaProjectionAppSelectorScope
        fun provideCoroutineScope(@Application applicationScope: CoroutineScope): CoroutineScope =
            CoroutineScope(applicationScope.coroutineContext + SupervisorJob())
            CoroutineScope(applicationScope.coroutineContext + SupervisorJob() + createCoroutineTracingContext("MediaProjectionAppSelectorScope"))
    }
}

Loading