Loading tracinglib/benchmark/src/TraceContextMicroBenchmark.kt +4 −5 Original line number Diff line number Diff line Loading @@ -24,11 +24,10 @@ import android.platform.test.rule.EnsureDeviceSettingsRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.app.tracing.coroutines.createCoroutineTracingContext import com.android.app.tracing.coroutines.nameCoroutine import com.android.app.tracing.coroutines.launchTraced import com.android.app.tracing.coroutines.traceCoroutine import com.android.systemui.Flags.FLAG_COROUTINE_TRACING import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import kotlinx.coroutines.yield Loading Loading @@ -81,7 +80,7 @@ class TraceContextMicroBenchmark { val state = perfStatusReporter.benchmarkState val context1 = createCoroutineTracingContext("scope1") val context2 = nameCoroutine("scope2") val context2 = createCoroutineTracingContext("scope2") runBlocking { while (state.keepRunning()) { withContext(context1) { Loading @@ -108,7 +107,7 @@ class TraceContextMicroBenchmark { runBlocking(createCoroutineTracingContext("root")) { val job1 = launch(nameCoroutine("scope1")) { launchTraced("scope1") { while (true) { traceCoroutine("hello") { traceCoroutine("world") { yield() } Loading @@ -117,7 +116,7 @@ class TraceContextMicroBenchmark { } } val job2 = launch(nameCoroutine("scope2")) { launchTraced("scope2") { while (true) { traceCoroutine("hallo") { traceCoroutine("welt") { yield() } Loading tracinglib/core/src/coroutines/TraceContextElement.kt +0 −30 Original line number Diff line number Diff line Loading @@ -138,36 +138,6 @@ public fun createCoroutineTracingContext( } } /** * Returns a new [CoroutineTraceName] (or [EmptyCoroutineContext] if `coroutine_tracing` feature is * flagged off). When the current [CoroutineScope] has a [TraceContextElement] installed, * [CoroutineTraceName] can be used to name the child scope under construction. * * [TraceContextElement] should be installed on the root, and [CoroutineTraceName] on the children. */ @Deprecated("Use .launchInTraced, .launchTraced, .shareInTraced, etc.") public fun nameCoroutine(name: String): CoroutineContext = nameCoroutine { name } /** * Returns a new [CoroutineTraceName] (or [EmptyCoroutineContext] if `coroutine_tracing` feature is * flagged off). When the current [CoroutineScope] has a [TraceContextElement] installed, * [CoroutineTraceName] can be used to name the child scope under construction. * * [TraceContextElement] should be installed on the root, and [CoroutineTraceName] on the children. * * @param name lazy string to only be called if feature is enabled */ @OptIn(ExperimentalContracts::class) @Deprecated("Use .launchInTraced, .launchTraced, .shareInTraced, etc.") public inline fun nameCoroutine(name: () -> String): CoroutineContext { contract { callsInPlace(name, InvocationKind.AT_MOST_ONCE) } return if (com.android.systemui.Flags.coroutineTracing()) { CoroutineTraceName(name()) } else { EmptyCoroutineContext } } private object PerfettoTraceConfig { // cc = coroutine continuations @JvmField val COROUTINE_CATEGORY: PerfettoTrace.Category = PerfettoTrace.Category("cc") Loading tracinglib/demo/src/experiments/CombineDeferred.kt +2 −2 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ */ package com.example.tracing.demo.experiments import com.android.app.tracing.coroutines.nameCoroutine import com.android.app.tracing.coroutines.asyncTraced import com.android.app.tracing.coroutines.traceCoroutine import com.android.app.tracing.traceSection import com.example.tracing.demo.FixedThread1 Loading Loading @@ -76,7 +76,7 @@ constructor( // no dispatcher specified, so will inherit dispatcher from whoever called // run(), meaning the main thread val deferredE = async(nameCoroutine("overridden-scope-name-for-deferredE")) { asyncTraced("overridden-scope-name-for-deferredE") { traceCoroutine("async#E") { forceSuspend("deferredE", 25) } } Loading tracinglib/demo/src/experiments/FlowTracingTutorial.kt +1 −1 Original line number Diff line number Diff line Loading @@ -128,7 +128,7 @@ constructor( // // Alternatively, call `.flowName("hello-cold")` before or after `flowOn` // changes // // the dispatcher. // .flowOn(nameCoroutine("hello-cold") + dispatcherA) // .flowOn(CoroutineTraceName("hello-cold") + dispatcherA) // .map { it * 2 } // .collectTraced("my-collector") { forceSuspend("A:$it", 1) } // } Loading tracinglib/robolectric/src/CoroutineTracingTest.kt +3 −4 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ import com.android.app.tracing.coroutines.CoroutineTraceName import com.android.app.tracing.coroutines.TraceContextElement import com.android.app.tracing.coroutines.coroutineScopeTraced import com.android.app.tracing.coroutines.launchTraced import com.android.app.tracing.coroutines.nameCoroutine import com.android.app.tracing.coroutines.traceCoroutine import com.android.app.tracing.coroutines.withContextTraced import com.android.systemui.Flags.FLAG_COROUTINE_TRACING Loading Loading @@ -172,8 +171,8 @@ class CoroutineTracingTest : TestBase() { runTest(finalEvent = 4) { assertTrue(coroutineContext[CoroutineTraceName] is TraceContextElement) expect(1, "1^main") withContext(nameCoroutine("inside-withContext")) { // <-- BAD, DON'T DO THIS // This is why nameCoroutine() should not be used this way, it overwrites the withContext(CoroutineTraceName("inside-withContext")) { // <-- BAD, DON'T DO THIS // This is why CoroutineTraceName() should not be used this way, it overwrites the // TraceContextElement. Because it is not a CopyableThreadContextElement, it is // not given opportunity to merge with the parent trace context. // While we could make CoroutineTraceName a CopyableThreadContextElement, it would Loading Loading @@ -305,7 +304,7 @@ class CoroutineTracingTest : TestBase() { expect(1, "1^main") delay(1) expect(2, "1^main") val reusedNameContext = nameCoroutine("my-coroutine") val reusedNameContext = CoroutineTraceName("my-coroutine") launch(reusedNameContext) { expect(3, "1^main:1^my-coroutine") delay(1) Loading Loading
tracinglib/benchmark/src/TraceContextMicroBenchmark.kt +4 −5 Original line number Diff line number Diff line Loading @@ -24,11 +24,10 @@ import android.platform.test.rule.EnsureDeviceSettingsRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.app.tracing.coroutines.createCoroutineTracingContext import com.android.app.tracing.coroutines.nameCoroutine import com.android.app.tracing.coroutines.launchTraced import com.android.app.tracing.coroutines.traceCoroutine import com.android.systemui.Flags.FLAG_COROUTINE_TRACING import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import kotlinx.coroutines.yield Loading Loading @@ -81,7 +80,7 @@ class TraceContextMicroBenchmark { val state = perfStatusReporter.benchmarkState val context1 = createCoroutineTracingContext("scope1") val context2 = nameCoroutine("scope2") val context2 = createCoroutineTracingContext("scope2") runBlocking { while (state.keepRunning()) { withContext(context1) { Loading @@ -108,7 +107,7 @@ class TraceContextMicroBenchmark { runBlocking(createCoroutineTracingContext("root")) { val job1 = launch(nameCoroutine("scope1")) { launchTraced("scope1") { while (true) { traceCoroutine("hello") { traceCoroutine("world") { yield() } Loading @@ -117,7 +116,7 @@ class TraceContextMicroBenchmark { } } val job2 = launch(nameCoroutine("scope2")) { launchTraced("scope2") { while (true) { traceCoroutine("hallo") { traceCoroutine("welt") { yield() } Loading
tracinglib/core/src/coroutines/TraceContextElement.kt +0 −30 Original line number Diff line number Diff line Loading @@ -138,36 +138,6 @@ public fun createCoroutineTracingContext( } } /** * Returns a new [CoroutineTraceName] (or [EmptyCoroutineContext] if `coroutine_tracing` feature is * flagged off). When the current [CoroutineScope] has a [TraceContextElement] installed, * [CoroutineTraceName] can be used to name the child scope under construction. * * [TraceContextElement] should be installed on the root, and [CoroutineTraceName] on the children. */ @Deprecated("Use .launchInTraced, .launchTraced, .shareInTraced, etc.") public fun nameCoroutine(name: String): CoroutineContext = nameCoroutine { name } /** * Returns a new [CoroutineTraceName] (or [EmptyCoroutineContext] if `coroutine_tracing` feature is * flagged off). When the current [CoroutineScope] has a [TraceContextElement] installed, * [CoroutineTraceName] can be used to name the child scope under construction. * * [TraceContextElement] should be installed on the root, and [CoroutineTraceName] on the children. * * @param name lazy string to only be called if feature is enabled */ @OptIn(ExperimentalContracts::class) @Deprecated("Use .launchInTraced, .launchTraced, .shareInTraced, etc.") public inline fun nameCoroutine(name: () -> String): CoroutineContext { contract { callsInPlace(name, InvocationKind.AT_MOST_ONCE) } return if (com.android.systemui.Flags.coroutineTracing()) { CoroutineTraceName(name()) } else { EmptyCoroutineContext } } private object PerfettoTraceConfig { // cc = coroutine continuations @JvmField val COROUTINE_CATEGORY: PerfettoTrace.Category = PerfettoTrace.Category("cc") Loading
tracinglib/demo/src/experiments/CombineDeferred.kt +2 −2 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ */ package com.example.tracing.demo.experiments import com.android.app.tracing.coroutines.nameCoroutine import com.android.app.tracing.coroutines.asyncTraced import com.android.app.tracing.coroutines.traceCoroutine import com.android.app.tracing.traceSection import com.example.tracing.demo.FixedThread1 Loading Loading @@ -76,7 +76,7 @@ constructor( // no dispatcher specified, so will inherit dispatcher from whoever called // run(), meaning the main thread val deferredE = async(nameCoroutine("overridden-scope-name-for-deferredE")) { asyncTraced("overridden-scope-name-for-deferredE") { traceCoroutine("async#E") { forceSuspend("deferredE", 25) } } Loading
tracinglib/demo/src/experiments/FlowTracingTutorial.kt +1 −1 Original line number Diff line number Diff line Loading @@ -128,7 +128,7 @@ constructor( // // Alternatively, call `.flowName("hello-cold")` before or after `flowOn` // changes // // the dispatcher. // .flowOn(nameCoroutine("hello-cold") + dispatcherA) // .flowOn(CoroutineTraceName("hello-cold") + dispatcherA) // .map { it * 2 } // .collectTraced("my-collector") { forceSuspend("A:$it", 1) } // } Loading
tracinglib/robolectric/src/CoroutineTracingTest.kt +3 −4 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ import com.android.app.tracing.coroutines.CoroutineTraceName import com.android.app.tracing.coroutines.TraceContextElement import com.android.app.tracing.coroutines.coroutineScopeTraced import com.android.app.tracing.coroutines.launchTraced import com.android.app.tracing.coroutines.nameCoroutine import com.android.app.tracing.coroutines.traceCoroutine import com.android.app.tracing.coroutines.withContextTraced import com.android.systemui.Flags.FLAG_COROUTINE_TRACING Loading Loading @@ -172,8 +171,8 @@ class CoroutineTracingTest : TestBase() { runTest(finalEvent = 4) { assertTrue(coroutineContext[CoroutineTraceName] is TraceContextElement) expect(1, "1^main") withContext(nameCoroutine("inside-withContext")) { // <-- BAD, DON'T DO THIS // This is why nameCoroutine() should not be used this way, it overwrites the withContext(CoroutineTraceName("inside-withContext")) { // <-- BAD, DON'T DO THIS // This is why CoroutineTraceName() should not be used this way, it overwrites the // TraceContextElement. Because it is not a CopyableThreadContextElement, it is // not given opportunity to merge with the parent trace context. // While we could make CoroutineTraceName a CopyableThreadContextElement, it would Loading Loading @@ -305,7 +304,7 @@ class CoroutineTracingTest : TestBase() { expect(1, "1^main") delay(1) expect(2, "1^main") val reusedNameContext = nameCoroutine("my-coroutine") val reusedNameContext = CoroutineTraceName("my-coroutine") launch(reusedNameContext) { expect(3, "1^main:1^my-coroutine") delay(1) Loading