Merge "Add traceAsync to TraceUtils" into udc-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
227a03480b
@@ -18,22 +18,23 @@ package com.android.systemui.util
|
|||||||
|
|
||||||
import android.os.Trace
|
import android.os.Trace
|
||||||
import android.os.TraceNameSupplier
|
import android.os.TraceNameSupplier
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run a block within a [Trace] section.
|
* Run a block within a [Trace] section. Calls [Trace.beginSection] before and [Trace.endSection]
|
||||||
* Calls [Trace.beginSection] before and [Trace.endSection] after the passed block.
|
* after the passed block.
|
||||||
*/
|
*/
|
||||||
inline fun <T> traceSection(tag: String, block: () -> T): T =
|
inline fun <T> traceSection(tag: String, block: () -> T): T =
|
||||||
if (Trace.isTagEnabled(Trace.TRACE_TAG_APP)) {
|
if (Trace.isTagEnabled(Trace.TRACE_TAG_APP)) {
|
||||||
Trace.traceBegin(Trace.TRACE_TAG_APP, tag)
|
Trace.traceBegin(Trace.TRACE_TAG_APP, tag)
|
||||||
try {
|
try {
|
||||||
block()
|
|
||||||
} finally {
|
|
||||||
Trace.traceEnd(Trace.TRACE_TAG_APP)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
block()
|
block()
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(Trace.TRACE_TAG_APP)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
block()
|
||||||
|
}
|
||||||
|
|
||||||
class TraceUtils {
|
class TraceUtils {
|
||||||
companion object {
|
companion object {
|
||||||
@@ -43,6 +44,7 @@ class TraceUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function for creating a Runnable object that implements TraceNameSupplier.
|
* Helper function for creating a Runnable object that implements TraceNameSupplier.
|
||||||
|
*
|
||||||
* This is useful for posting Runnables to Handlers with meaningful names.
|
* This is useful for posting Runnables to Handlers with meaningful names.
|
||||||
*/
|
*/
|
||||||
inline fun namedRunnable(tag: String, crossinline block: () -> Unit): Runnable {
|
inline fun namedRunnable(tag: String, crossinline block: () -> Unit): Runnable {
|
||||||
@@ -51,5 +53,37 @@ class TraceUtils {
|
|||||||
override fun run() = block()
|
override fun run() = block()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cookie used for async traces. Shouldn't be public, but to use it inside inline methods
|
||||||
|
* there is no other way around.
|
||||||
|
*/
|
||||||
|
val lastCookie = AtomicInteger(0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an async slice in a track called "AsyncTraces".
|
||||||
|
*
|
||||||
|
* This can be used to trace coroutine code. Note that all usages of this method will appear
|
||||||
|
* under a single track.
|
||||||
|
*/
|
||||||
|
inline fun <T> traceAsync(method: String, block: () -> T): T =
|
||||||
|
traceAsync(method, "AsyncTraces", block)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an async slice in a track with [trackName] while [block] runs.
|
||||||
|
*
|
||||||
|
* This can be used to trace coroutine code. [method] will be the name of the slice,
|
||||||
|
* [trackName] of the track. The track is one of the rows visible in a perfetto trace inside
|
||||||
|
* SystemUI process.
|
||||||
|
*/
|
||||||
|
inline fun <T> traceAsync(method: String, trackName: String, block: () -> T): T {
|
||||||
|
val cookie = lastCookie.incrementAndGet()
|
||||||
|
Trace.asyncTraceForTrackBegin(Trace.TRACE_TAG_APP, trackName, method, cookie)
|
||||||
|
try {
|
||||||
|
return block()
|
||||||
|
} finally {
|
||||||
|
Trace.asyncTraceForTrackEnd(Trace.TRACE_TAG_APP, trackName, cookie)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ import com.android.systemui.settings.UserTracker
|
|||||||
import com.android.systemui.shared.customization.data.content.CustomizationProviderContract as Contract
|
import com.android.systemui.shared.customization.data.content.CustomizationProviderContract as Contract
|
||||||
import com.android.systemui.statusbar.phone.SystemUIDialog
|
import com.android.systemui.statusbar.phone.SystemUIDialog
|
||||||
import com.android.systemui.statusbar.policy.KeyguardStateController
|
import com.android.systemui.statusbar.policy.KeyguardStateController
|
||||||
|
import com.android.systemui.util.TraceUtils.Companion.traceAsync
|
||||||
import dagger.Lazy
|
import dagger.Lazy
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
@@ -442,8 +443,10 @@ constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun isFeatureDisabledByDevicePolicy(): Boolean =
|
private suspend fun isFeatureDisabledByDevicePolicy(): Boolean =
|
||||||
withContext(backgroundDispatcher) {
|
traceAsync("isFeatureDisabledByDevicePolicy", TAG) {
|
||||||
devicePolicyManager.areKeyguardShortcutsDisabled(userId = userTracker.userId)
|
withContext(backgroundDispatcher) {
|
||||||
|
devicePolicyManager.areKeyguardShortcutsDisabled(userId = userTracker.userId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
Reference in New Issue
Block a user