summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJernej Virag <jernej@google.com>2023-11-28 15:59:17 +0100
committerJernej Virag <jernej@google.com>2023-11-30 09:23:53 +0000
commit2f671d2fdf99480a9fb5730e5c43aa31af29762a (patch)
treeb1e6a3d7ef8c01b31319e684170dab82099b51f4
parentbd52ce79eee5b66d70b79bfcfe226339bbb17796 (diff)
downloadsystemui-2f671d2fdf99480a9fb5730e5c43aa31af29762a.tar.gz
Mark tracing companion methods as @JvmStatic
This makes them nicely and directly callable even from Java and avoids duplication in our codebase. Bug: 313630049 Flag: NONE Test: recorded perfetto trace Change-Id: I7131c3780638256a5120ce67a5b4334de8cb5125
-rw-r--r--tracinglib/src/com/android/app/tracing/TraceUtils.kt19
1 files changed, 19 insertions, 0 deletions
diff --git a/tracinglib/src/com/android/app/tracing/TraceUtils.kt b/tracinglib/src/com/android/app/tracing/TraceUtils.kt
index 6bd3858..ec75bd2 100644
--- a/tracinglib/src/com/android/app/tracing/TraceUtils.kt
+++ b/tracinglib/src/com/android/app/tracing/TraceUtils.kt
@@ -71,15 +71,32 @@ class TraceUtils {
private const val DEBUG_COROUTINE_TRACING = false
const val DEFAULT_TRACK_NAME = "AsyncTraces"
+ @JvmStatic
+ inline fun <T> trace(crossinline tag: () -> String, crossinline block: () -> T): T {
+ return traceSection(tag) { block() }
+ }
+
+ @JvmStatic
+ inline fun <T> trace(tag: String, crossinline block: () -> T): T {
+ return traceSection(tag) { block() }
+ }
+
+ @JvmStatic
inline fun traceRunnable(tag: String, crossinline block: () -> Unit): Runnable {
return Runnable { traceSection(tag) { block() } }
}
+ @JvmStatic
+ inline fun traceRunnable(crossinline tag: () -> String, crossinline block: () -> Unit): Runnable {
+ return Runnable { traceSection(tag) { block() } }
+ }
+
/**
* Helper function for creating a Runnable object that implements TraceNameSupplier.
*
* This is useful for posting Runnables to Handlers with meaningful names.
*/
+ @JvmStatic
inline fun namedRunnable(tag: String, crossinline block: () -> Unit): Runnable {
return object : Runnable, TraceNameSupplier {
override fun getTraceName(): String = tag
@@ -100,6 +117,7 @@ class TraceUtils {
* This can be used to trace coroutine code. Note that all usages of this method will appear
* under a single track.
*/
+ @JvmStatic
inline fun <T> traceAsync(method: String, block: () -> T): T =
traceAsync(DEFAULT_TRACK_NAME, method, block)
@@ -110,6 +128,7 @@ class TraceUtils {
* [trackName] of the track. The track is one of the rows visible in a perfetto trace inside
* the app process.
*/
+ @JvmStatic
inline fun <T> traceAsync(trackName: String, method: String, block: () -> T): T {
val cookie = lastCookie.incrementAndGet()
Trace.asyncTraceForTrackBegin(Trace.TRACE_TAG_APP, trackName, method, cookie)