Change Logcat to only log in background thread in debug mode
The prod and always log trackers shoud just log syncrhonously, since they do not do any jank-causing work to determine whether a message should be logged. Bug: 221419865 Test: ran 'atest SystemUITests SystemUIGoogleTests' Change-Id: I2e673a480abbd5afda2d6ce3117df47e0415ea8a
This commit is contained in:
@@ -84,16 +84,19 @@ class LogBuffer @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
private val buffer: ArrayDeque<LogMessageImpl> = ArrayDeque()
|
||||
private val echoMessageQueue: BlockingQueue<LogMessageImpl> = ArrayBlockingQueue(poolSize)
|
||||
private val echoMessageQueue: BlockingQueue<LogMessageImpl>? =
|
||||
if (logcatEchoTracker.logInBackgroundThread) ArrayBlockingQueue(poolSize) else null
|
||||
|
||||
init {
|
||||
thread(start = true, priority = Thread.NORM_PRIORITY) {
|
||||
try {
|
||||
while (true) {
|
||||
echoToDesiredEndpoints(echoMessageQueue.take())
|
||||
if (logcatEchoTracker.logInBackgroundThread && echoMessageQueue != null) {
|
||||
thread(start = true, priority = Thread.NORM_PRIORITY) {
|
||||
try {
|
||||
while (true) {
|
||||
echoToDesiredEndpoints(echoMessageQueue.take())
|
||||
}
|
||||
} catch (e: InterruptedException) {
|
||||
Thread.currentThread().interrupt()
|
||||
}
|
||||
} catch (e: InterruptedException) {
|
||||
Thread.currentThread().interrupt()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,9 +195,15 @@ class LogBuffer @JvmOverloads constructor(
|
||||
buffer.removeFirst()
|
||||
}
|
||||
buffer.add(message as LogMessageImpl)
|
||||
// Log in the background thread only if it has capacity to avoid blocking this thread
|
||||
if (echoMessageQueue.remainingCapacity() > 0) {
|
||||
echoMessageQueue.put(message)
|
||||
// Log in the background thread only if echoMessageQueue exists and has capacity (checking
|
||||
// capacity avoids the possibility of blocking this thread)
|
||||
if (echoMessageQueue != null && echoMessageQueue.remainingCapacity() > 0) {
|
||||
try {
|
||||
echoMessageQueue.put(message)
|
||||
} catch (e: InterruptedException) {
|
||||
// the background thread has been shut down, so just log on this one
|
||||
echoToDesiredEndpoints(message)
|
||||
}
|
||||
} else {
|
||||
echoToDesiredEndpoints(message)
|
||||
}
|
||||
|
||||
@@ -29,4 +29,9 @@ interface LogcatEchoTracker {
|
||||
* Whether [tagName] should echo messages of [level] or higher to logcat.
|
||||
*/
|
||||
fun isTagLoggable(tagName: String, level: LogLevel): Boolean
|
||||
|
||||
/**
|
||||
* Whether to log messages in a background thread.
|
||||
*/
|
||||
val logInBackgroundThread: Boolean
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ class LogcatEchoTrackerDebug private constructor(
|
||||
) : LogcatEchoTracker {
|
||||
private val cachedBufferLevels: MutableMap<String, LogLevel> = mutableMapOf()
|
||||
private val cachedTagLevels: MutableMap<String, LogLevel> = mutableMapOf()
|
||||
override val logInBackgroundThread = true
|
||||
|
||||
companion object Factory {
|
||||
@JvmStatic
|
||||
|
||||
@@ -20,6 +20,8 @@ package com.android.systemui.log
|
||||
* Production version of [LogcatEchoTracker] that isn't configurable.
|
||||
*/
|
||||
class LogcatEchoTrackerProd : LogcatEchoTracker {
|
||||
override val logInBackgroundThread = false
|
||||
|
||||
override fun isBufferLoggable(bufferName: String, level: LogLevel): Boolean {
|
||||
return level >= LogLevel.WARNING
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ fun logcatLogBuffer(name: String = "EchoToLogcatLogBuffer") =
|
||||
* A [LogcatEchoTracker] that always allows echoing to the logcat.
|
||||
*/
|
||||
class LogcatEchoTrackerAlways : LogcatEchoTracker {
|
||||
override val logInBackgroundThread = false
|
||||
override fun isBufferLoggable(bufferName: String, level: LogLevel): Boolean = true
|
||||
override fun isTagLoggable(tagName: String, level: LogLevel): Boolean = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user