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

Commit 46917e53 authored by Peter Kalauskas's avatar Peter Kalauskas
Browse files

TraceUtils updates, new helper for runnables

Modify TraceUtils' traceSection to use traceBegin instead of
beginSection because beginSection will crash at run-time if the string
is longer than 127 chars.

Also, guard against StringBuilder GC garbage while tracing.

Test: manual
Bug: 257075630
Change-Id: I74cb5687a206f5d7ab8eb570cf24715d7e671df1
parent 8c526510
Loading
Loading
Loading
Loading
+18 −7
Original line number Diff line number Diff line
@@ -22,11 +22,22 @@ import android.os.Trace
 * Run a block within a [Trace] section.
 * Calls [Trace.beginSection] before and [Trace.endSection] after the passed block.
 */
inline fun <T> traceSection(tag: String, block: () -> T): T {
    Trace.beginSection(tag)
inline fun <T> traceSection(tag: String, block: () -> T): T =
        if (Trace.isTagEnabled(Trace.TRACE_TAG_APP)) {
            Trace.traceBegin(Trace.TRACE_TAG_APP, tag)
            try {
        return block()
                block()
            } finally {
        Trace.endSection()
                Trace.traceEnd(Trace.TRACE_TAG_APP)
            }
        } else {
            block()
        }

class TraceUtils {
    companion object {
        inline fun traceRunnable(tag: String, crossinline block: () -> Unit): Runnable {
            return Runnable { traceSection(tag) { block() } }
        }
    }
}