Loading tracinglib/benchmark/Android.bp +6 −3 Original line number Diff line number Diff line Loading @@ -20,7 +20,10 @@ package { android_test { name: "tracinglib-benchmark", srcs: ["src/**/*.kt"], srcs: [ "src/**/*.kt", ":tracinglib-core-srcs", ], static_libs: [ "androidx.annotation_annotation", Loading @@ -35,12 +38,12 @@ android_test { "flag-junit", "kotlinx_coroutines_android", "platform-test-rules", "tracinglib-platform", "com_android_systemui_flags_lib", ], data: [":perfetto_artifacts"], sdk_version: "current", platform_apis: true, certificate: "platform", use_resource_processor: true, Loading tracinglib/core/Android.bp +9 −4 Original line number Diff line number Diff line Loading @@ -16,20 +16,25 @@ package { default_applicable_licenses: ["Android-Apache-2.0"], } // TODO(b/240432457): Replace with library once `-Xfriend-paths` is supported by Soong filegroup { name: "tracinglib-core-srcs", srcs: ["src/**/*.kt"], visibility: ["//frameworks/libs/systemui/tracinglib:__subpackages__"], } java_library { name: "tracinglib-platform", static_libs: [ "kotlinx_coroutines_android", "com_android_systemui_flags_lib", ], libs: [ "androidx.annotation_annotation", ], kotlincflags: [ "-Xjvm-default=all", "-opt-in=kotlin.ExperimentalStdlibApi", "-opt-in=kotlinx.coroutines.DelicateCoroutinesApi", "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi", "-Xexplicit-api=strict", ], srcs: ["src/**/*.kt"], srcs: [":tracinglib-core-srcs"], } tracinglib/core/src/FlowTracing.kt +10 −7 Original line number Diff line number Diff line Loading @@ -29,14 +29,14 @@ import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.onEach /** Utilities to trace Flows */ object FlowTracing { public object FlowTracing { private const val TAG = "FlowTracing" private const val DEFAULT_ASYNC_TRACK_NAME = TAG private val counter = AtomicInteger(0) /** Logs each flow element to a trace. */ inline fun <T> Flow<T>.traceEach( public inline fun <T> Flow<T>.traceEach( flowName: String, logcat: Boolean = false, traceEmissionCount: Boolean = false, Loading @@ -48,7 +48,7 @@ object FlowTracing { } /** Records value of a given numeric flow as a counter track in traces. */ fun <T : Number> Flow<T>.traceAsCounter( public fun <T : Number> Flow<T>.traceAsCounter( counterName: String, traceEmissionCount: Boolean = false, valueToInt: (T) -> Int = { it.toInt() }, Loading @@ -62,7 +62,10 @@ object FlowTracing { } /** Adds a counter track to monitor emissions from a specific flow.] */ fun <T> Flow<T>.traceEmissionCount(flowName: String, uniqueSuffix: Boolean = false): Flow<T> { public fun <T> Flow<T>.traceEmissionCount( flowName: String, uniqueSuffix: Boolean = false, ): Flow<T> { val trackName by lazy { "$flowName#emissionCount" + if (uniqueSuffix) "\$${counter.addAndGet(1)}" else "" } Loading @@ -78,7 +81,7 @@ object FlowTracing { * * [flowName] is lazy: it would be computed only if tracing is enabled and only the first time. */ fun <T> Flow<T>.traceEmissionCount( public fun <T> Flow<T>.traceEmissionCount( flowName: () -> String, uniqueSuffix: Boolean = false, ): Flow<T> { Loading @@ -103,7 +106,7 @@ object FlowTracing { * * This allows to easily have visibility into what's happening in awaitClose. */ suspend fun ProducerScope<*>.tracedAwaitClose(name: String, block: () -> Unit = {}) { public suspend fun ProducerScope<*>.tracedAwaitClose(name: String, block: () -> Unit = {}) { awaitClose { val traceName = { "$name#TracedAwaitClose" } traceAsync(DEFAULT_ASYNC_TRACK_NAME, traceName) { traceSection(traceName) { block() } } Loading @@ -119,7 +122,7 @@ object FlowTracing { * * Should be used with [tracedAwaitClose] (when needed). */ fun <T> tracedConflatedCallbackFlow( public fun <T> tracedConflatedCallbackFlow( name: String, @BuilderInference block: suspend ProducerScope<T>.() -> Unit, ): Flow<T> { Loading tracinglib/core/src/ListenersTracing.kt +2 −2 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ package com.android.app.tracing /** Utilities to trace automatically computations happening for each element of a list. */ object ListenersTracing { public object ListenersTracing { /** * Like [forEach], but outputs a trace for each element. Loading @@ -33,7 +33,7 @@ object ListenersTracing { * listeners.forEachTraced(TAG) { it.dispatch(state) } * ``` */ inline fun <T : Any> List<T>.forEachTraced(tag: String = "", f: (T) -> Unit) { public inline fun <T : Any> List<T>.forEachTraced(tag: String = "", f: (T) -> Unit) { forEach { traceSection({ "$tag#${it::javaClass.get().name}" }) { f(it) } } } } tracinglib/core/src/TraceStateLogger.kt +2 −2 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ import android.util.Log * This creates a new slice in a perfetto trace only if the state is different than the previous * one. */ class TraceStateLogger public class TraceStateLogger @JvmOverloads constructor( private val trackName: String, Loading @@ -47,7 +47,7 @@ constructor( private var previousValue: String? = null /** If needed, logs the value to a track with name [trackName]. */ fun log(newValue: String) { public fun log(newValue: String) { if (instantEvent) { Trace.instantForTrack(Trace.TRACE_TAG_APP, trackName, newValue) } Loading Loading
tracinglib/benchmark/Android.bp +6 −3 Original line number Diff line number Diff line Loading @@ -20,7 +20,10 @@ package { android_test { name: "tracinglib-benchmark", srcs: ["src/**/*.kt"], srcs: [ "src/**/*.kt", ":tracinglib-core-srcs", ], static_libs: [ "androidx.annotation_annotation", Loading @@ -35,12 +38,12 @@ android_test { "flag-junit", "kotlinx_coroutines_android", "platform-test-rules", "tracinglib-platform", "com_android_systemui_flags_lib", ], data: [":perfetto_artifacts"], sdk_version: "current", platform_apis: true, certificate: "platform", use_resource_processor: true, Loading
tracinglib/core/Android.bp +9 −4 Original line number Diff line number Diff line Loading @@ -16,20 +16,25 @@ package { default_applicable_licenses: ["Android-Apache-2.0"], } // TODO(b/240432457): Replace with library once `-Xfriend-paths` is supported by Soong filegroup { name: "tracinglib-core-srcs", srcs: ["src/**/*.kt"], visibility: ["//frameworks/libs/systemui/tracinglib:__subpackages__"], } java_library { name: "tracinglib-platform", static_libs: [ "kotlinx_coroutines_android", "com_android_systemui_flags_lib", ], libs: [ "androidx.annotation_annotation", ], kotlincflags: [ "-Xjvm-default=all", "-opt-in=kotlin.ExperimentalStdlibApi", "-opt-in=kotlinx.coroutines.DelicateCoroutinesApi", "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi", "-Xexplicit-api=strict", ], srcs: ["src/**/*.kt"], srcs: [":tracinglib-core-srcs"], }
tracinglib/core/src/FlowTracing.kt +10 −7 Original line number Diff line number Diff line Loading @@ -29,14 +29,14 @@ import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.onEach /** Utilities to trace Flows */ object FlowTracing { public object FlowTracing { private const val TAG = "FlowTracing" private const val DEFAULT_ASYNC_TRACK_NAME = TAG private val counter = AtomicInteger(0) /** Logs each flow element to a trace. */ inline fun <T> Flow<T>.traceEach( public inline fun <T> Flow<T>.traceEach( flowName: String, logcat: Boolean = false, traceEmissionCount: Boolean = false, Loading @@ -48,7 +48,7 @@ object FlowTracing { } /** Records value of a given numeric flow as a counter track in traces. */ fun <T : Number> Flow<T>.traceAsCounter( public fun <T : Number> Flow<T>.traceAsCounter( counterName: String, traceEmissionCount: Boolean = false, valueToInt: (T) -> Int = { it.toInt() }, Loading @@ -62,7 +62,10 @@ object FlowTracing { } /** Adds a counter track to monitor emissions from a specific flow.] */ fun <T> Flow<T>.traceEmissionCount(flowName: String, uniqueSuffix: Boolean = false): Flow<T> { public fun <T> Flow<T>.traceEmissionCount( flowName: String, uniqueSuffix: Boolean = false, ): Flow<T> { val trackName by lazy { "$flowName#emissionCount" + if (uniqueSuffix) "\$${counter.addAndGet(1)}" else "" } Loading @@ -78,7 +81,7 @@ object FlowTracing { * * [flowName] is lazy: it would be computed only if tracing is enabled and only the first time. */ fun <T> Flow<T>.traceEmissionCount( public fun <T> Flow<T>.traceEmissionCount( flowName: () -> String, uniqueSuffix: Boolean = false, ): Flow<T> { Loading @@ -103,7 +106,7 @@ object FlowTracing { * * This allows to easily have visibility into what's happening in awaitClose. */ suspend fun ProducerScope<*>.tracedAwaitClose(name: String, block: () -> Unit = {}) { public suspend fun ProducerScope<*>.tracedAwaitClose(name: String, block: () -> Unit = {}) { awaitClose { val traceName = { "$name#TracedAwaitClose" } traceAsync(DEFAULT_ASYNC_TRACK_NAME, traceName) { traceSection(traceName) { block() } } Loading @@ -119,7 +122,7 @@ object FlowTracing { * * Should be used with [tracedAwaitClose] (when needed). */ fun <T> tracedConflatedCallbackFlow( public fun <T> tracedConflatedCallbackFlow( name: String, @BuilderInference block: suspend ProducerScope<T>.() -> Unit, ): Flow<T> { Loading
tracinglib/core/src/ListenersTracing.kt +2 −2 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ package com.android.app.tracing /** Utilities to trace automatically computations happening for each element of a list. */ object ListenersTracing { public object ListenersTracing { /** * Like [forEach], but outputs a trace for each element. Loading @@ -33,7 +33,7 @@ object ListenersTracing { * listeners.forEachTraced(TAG) { it.dispatch(state) } * ``` */ inline fun <T : Any> List<T>.forEachTraced(tag: String = "", f: (T) -> Unit) { public inline fun <T : Any> List<T>.forEachTraced(tag: String = "", f: (T) -> Unit) { forEach { traceSection({ "$tag#${it::javaClass.get().name}" }) { f(it) } } } }
tracinglib/core/src/TraceStateLogger.kt +2 −2 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ import android.util.Log * This creates a new slice in a perfetto trace only if the state is different than the previous * one. */ class TraceStateLogger public class TraceStateLogger @JvmOverloads constructor( private val trackName: String, Loading @@ -47,7 +47,7 @@ constructor( private var previousValue: String? = null /** If needed, logs the value to a track with name [trackName]. */ fun log(newValue: String) { public fun log(newValue: String) { if (instantEvent) { Trace.instantForTrack(Trace.TRACE_TAG_APP, trackName, newValue) } Loading