Loading packages/SystemUI/plugin/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ java_library { static_libs: [ "androidx.annotation_annotation", "error_prone_annotations", "PluginCoreLib", "SystemUIAnimationLib", ], Loading packages/SystemUI/src/com/android/systemui/log/LogBuffer.kt→packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogBuffer.kt +42 −35 Original line number Diff line number Diff line Loading @@ -14,12 +14,11 @@ * limitations under the License. */ package com.android.systemui.log package com.android.systemui.plugins.log import android.os.Trace import android.util.Log import com.android.systemui.log.dagger.LogModule import com.android.systemui.util.collection.RingBuffer import com.android.systemui.plugins.util.RingBuffer import com.google.errorprone.annotations.CompileTimeConstant import java.io.PrintWriter import java.util.concurrent.ArrayBlockingQueue Loading Loading @@ -61,15 +60,18 @@ import kotlin.math.max * In either case, `level` can be any of `verbose`, `debug`, `info`, `warn`, `error`, `assert`, or * the first letter of any of the previous. * * Buffers are provided by [LogModule]. Instances should be created using a [LogBufferFactory]. * In SystemUI, buffers are provided by LogModule. Instances should be created using a SysUI * LogBufferFactory. * * @param name The name of this buffer, printed when the buffer is dumped and in some other * situations. * @param maxSize The maximum number of messages to keep in memory at any one time. Buffers start * out empty and grow up to [maxSize] as new messages are logged. Once the buffer's size reaches * the maximum, it behaves like a ring buffer. * out empty and grow up to [maxSize] as new messages are logged. Once the buffer's size reaches the * maximum, it behaves like a ring buffer. */ class LogBuffer @JvmOverloads constructor( class LogBuffer @JvmOverloads constructor( private val name: String, private val maxSize: Int, private val logcatEchoTracker: LogcatEchoTracker, Loading Loading @@ -152,11 +154,10 @@ class LogBuffer @JvmOverloads constructor( * log message is built during runtime, use the [LogBuffer.log] overloaded method that takes in * an initializer and a message printer. * * Log buffers are limited by the number of entries, so logging more frequently * will limit the time window that the LogBuffer covers in a bug report. Richer logs, on the * other hand, make a bug report more actionable, so using the [log] with a messagePrinter to * add more detail to every log may do more to improve overall logging than adding more logs * with this method. * Log buffers are limited by the number of entries, so logging more frequently will limit the * time window that the LogBuffer covers in a bug report. Richer logs, on the other hand, make a * bug report more actionable, so using the [log] with a messagePrinter to add more detail to * every log may do more to improve overall logging than adding more logs with this method. */ fun log(tag: String, level: LogLevel, @CompileTimeConstant message: String) = log(tag, level, { str1 = message }, { str1!! }) Loading Loading @@ -189,8 +190,7 @@ class LogBuffer @JvmOverloads constructor( * You should call [log] instead of this method. * * After acquiring a message via [obtain], call this method to signal to the buffer that you * have finished filling in its data fields. The message will be echoed to logcat if * necessary. * have finished filling in its data fields. The message will be echoed to logcat if necessary. */ @Synchronized fun commit(message: LogMessage) { Loading @@ -213,7 +213,8 @@ class LogBuffer @JvmOverloads constructor( /** Sends message to echo after determining whether to use Logcat and/or systrace. */ private fun echoToDesiredEndpoints(message: LogMessage) { val includeInLogcat = logcatEchoTracker.isBufferLoggable(name, message.level) || val includeInLogcat = logcatEchoTracker.isBufferLoggable(name, message.level) || logcatEchoTracker.isTagLoggable(message.tag, message.level) echo(message, toLogcat = includeInLogcat, toSystrace = systrace) } Loading @@ -221,7 +222,12 @@ class LogBuffer @JvmOverloads constructor( /** Converts the entire buffer to a newline-delimited string */ @Synchronized fun dump(pw: PrintWriter, tailLength: Int) { val iterationStart = if (tailLength <= 0) { 0 } else { max(0, buffer.size - tailLength) } val iterationStart = if (tailLength <= 0) { 0 } else { max(0, buffer.size - tailLength) } for (i in iterationStart until buffer.size) { buffer[i].dump(pw) Loading @@ -229,9 +235,9 @@ class LogBuffer @JvmOverloads constructor( } /** * "Freezes" the contents of the buffer, making it immutable until [unfreeze] is called. * Calls to [log], [obtain], and [commit] will not affect the buffer and will return dummy * values if necessary. * "Freezes" the contents of the buffer, making it immutable until [unfreeze] is called. Calls * to [log], [obtain], and [commit] will not affect the buffer and will return dummy values if * necessary. */ @Synchronized fun freeze() { Loading @@ -241,9 +247,7 @@ class LogBuffer @JvmOverloads constructor( } } /** * Undoes the effects of calling [freeze]. */ /** Undoes the effects of calling [freeze]. */ @Synchronized fun unfreeze() { if (frozen) { Loading @@ -265,8 +269,11 @@ class LogBuffer @JvmOverloads constructor( } private fun echoToSystrace(message: LogMessage, strMessage: String) { Trace.instantForTrack(Trace.TRACE_TAG_APP, "UI Events", "$name - ${message.level.shortString} ${message.tag}: $strMessage") Trace.instantForTrack( Trace.TRACE_TAG_APP, "UI Events", "$name - ${message.level.shortString} ${message.tag}: $strMessage" ) } private fun echoToLogcat(message: LogMessage, strMessage: String) { Loading packages/SystemUI/src/com/android/systemui/log/LogLevel.kt→packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogLevel.kt +3 −8 Original line number Diff line number Diff line Loading @@ -14,17 +14,12 @@ * limitations under the License. */ package com.android.systemui.log package com.android.systemui.plugins.log import android.util.Log /** * Enum version of @Log.Level */ enum class LogLevel( @Log.Level val nativeLevel: Int, val shortString: String ) { /** Enum version of @Log.Level */ enum class LogLevel(@Log.Level val nativeLevel: Int, val shortString: String) { VERBOSE(Log.VERBOSE, "V"), DEBUG(Log.DEBUG, "D"), INFO(Log.INFO, "I"), Loading packages/SystemUI/src/com/android/systemui/log/LogMessage.kt→packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogMessage.kt +12 −13 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ * limitations under the License. */ package com.android.systemui.log package com.android.systemui.plugins.log import java.io.PrintWriter import java.text.SimpleDateFormat Loading @@ -29,9 +29,10 @@ import java.util.Locale * * When a message is logged, the code doing the logging stores data in one or more of the generic * fields ([str1], [int1], etc). When it comes time to dump the message to logcat/bugreport/etc, the * [messagePrinter] function reads the data stored in the generic fields and converts that to a human- * readable string. Thus, for every log type there must be a specialized initializer function that * stores data specific to that log type and a specialized printer function that prints that data. * [messagePrinter] function reads the data stored in the generic fields and converts that to a * human- readable string. Thus, for every log type there must be a specialized initializer function * that stores data specific to that log type and a specialized printer function that prints that * data. * * See [LogBuffer.log] for more information. */ Loading @@ -55,9 +56,7 @@ interface LogMessage { var bool3: Boolean var bool4: Boolean /** * Function that dumps the [LogMessage] to the provided [writer]. */ /** Function that dumps the [LogMessage] to the provided [writer]. */ fun dump(writer: PrintWriter) { val formattedTimestamp = DATE_FORMAT.format(timestamp) val shortLevel = level.shortString Loading @@ -68,12 +67,12 @@ interface LogMessage { } /** * A function that will be called if and when the message needs to be dumped to * logcat or a bug report. It should read the data stored by the initializer and convert it to * a human-readable string. The value of `this` will be the LogMessage to be printed. * **IMPORTANT:** The printer should ONLY ever reference fields on the LogMessage and NEVER any * variables in its enclosing scope. Otherwise, the runtime will need to allocate a new instance * of the printer for each call, thwarting our attempts at avoiding any sort of allocation. * A function that will be called if and when the message needs to be dumped to logcat or a bug * report. It should read the data stored by the initializer and convert it to a human-readable * string. The value of `this` will be the LogMessage to be printed. **IMPORTANT:** The printer * should ONLY ever reference fields on the LogMessage and NEVER any variables in its enclosing * scope. Otherwise, the runtime will need to allocate a new instance of the printer for each call, * thwarting our attempts at avoiding any sort of allocation. */ typealias MessagePrinter = LogMessage.() -> String Loading packages/SystemUI/src/com/android/systemui/log/LogMessageImpl.kt→packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogMessageImpl.kt +20 −21 Original line number Diff line number Diff line Loading @@ -14,11 +14,9 @@ * limitations under the License. */ package com.android.systemui.log package com.android.systemui.plugins.log /** * Recyclable implementation of [LogMessage]. */ /** Recyclable implementation of [LogMessage]. */ data class LogMessageImpl( override var level: LogLevel, override var tag: String, Loading Loading @@ -84,7 +82,8 @@ data class LogMessageImpl( false, false, false, false) false ) } } } Loading Loading
packages/SystemUI/plugin/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ java_library { static_libs: [ "androidx.annotation_annotation", "error_prone_annotations", "PluginCoreLib", "SystemUIAnimationLib", ], Loading
packages/SystemUI/src/com/android/systemui/log/LogBuffer.kt→packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogBuffer.kt +42 −35 Original line number Diff line number Diff line Loading @@ -14,12 +14,11 @@ * limitations under the License. */ package com.android.systemui.log package com.android.systemui.plugins.log import android.os.Trace import android.util.Log import com.android.systemui.log.dagger.LogModule import com.android.systemui.util.collection.RingBuffer import com.android.systemui.plugins.util.RingBuffer import com.google.errorprone.annotations.CompileTimeConstant import java.io.PrintWriter import java.util.concurrent.ArrayBlockingQueue Loading Loading @@ -61,15 +60,18 @@ import kotlin.math.max * In either case, `level` can be any of `verbose`, `debug`, `info`, `warn`, `error`, `assert`, or * the first letter of any of the previous. * * Buffers are provided by [LogModule]. Instances should be created using a [LogBufferFactory]. * In SystemUI, buffers are provided by LogModule. Instances should be created using a SysUI * LogBufferFactory. * * @param name The name of this buffer, printed when the buffer is dumped and in some other * situations. * @param maxSize The maximum number of messages to keep in memory at any one time. Buffers start * out empty and grow up to [maxSize] as new messages are logged. Once the buffer's size reaches * the maximum, it behaves like a ring buffer. * out empty and grow up to [maxSize] as new messages are logged. Once the buffer's size reaches the * maximum, it behaves like a ring buffer. */ class LogBuffer @JvmOverloads constructor( class LogBuffer @JvmOverloads constructor( private val name: String, private val maxSize: Int, private val logcatEchoTracker: LogcatEchoTracker, Loading Loading @@ -152,11 +154,10 @@ class LogBuffer @JvmOverloads constructor( * log message is built during runtime, use the [LogBuffer.log] overloaded method that takes in * an initializer and a message printer. * * Log buffers are limited by the number of entries, so logging more frequently * will limit the time window that the LogBuffer covers in a bug report. Richer logs, on the * other hand, make a bug report more actionable, so using the [log] with a messagePrinter to * add more detail to every log may do more to improve overall logging than adding more logs * with this method. * Log buffers are limited by the number of entries, so logging more frequently will limit the * time window that the LogBuffer covers in a bug report. Richer logs, on the other hand, make a * bug report more actionable, so using the [log] with a messagePrinter to add more detail to * every log may do more to improve overall logging than adding more logs with this method. */ fun log(tag: String, level: LogLevel, @CompileTimeConstant message: String) = log(tag, level, { str1 = message }, { str1!! }) Loading Loading @@ -189,8 +190,7 @@ class LogBuffer @JvmOverloads constructor( * You should call [log] instead of this method. * * After acquiring a message via [obtain], call this method to signal to the buffer that you * have finished filling in its data fields. The message will be echoed to logcat if * necessary. * have finished filling in its data fields. The message will be echoed to logcat if necessary. */ @Synchronized fun commit(message: LogMessage) { Loading @@ -213,7 +213,8 @@ class LogBuffer @JvmOverloads constructor( /** Sends message to echo after determining whether to use Logcat and/or systrace. */ private fun echoToDesiredEndpoints(message: LogMessage) { val includeInLogcat = logcatEchoTracker.isBufferLoggable(name, message.level) || val includeInLogcat = logcatEchoTracker.isBufferLoggable(name, message.level) || logcatEchoTracker.isTagLoggable(message.tag, message.level) echo(message, toLogcat = includeInLogcat, toSystrace = systrace) } Loading @@ -221,7 +222,12 @@ class LogBuffer @JvmOverloads constructor( /** Converts the entire buffer to a newline-delimited string */ @Synchronized fun dump(pw: PrintWriter, tailLength: Int) { val iterationStart = if (tailLength <= 0) { 0 } else { max(0, buffer.size - tailLength) } val iterationStart = if (tailLength <= 0) { 0 } else { max(0, buffer.size - tailLength) } for (i in iterationStart until buffer.size) { buffer[i].dump(pw) Loading @@ -229,9 +235,9 @@ class LogBuffer @JvmOverloads constructor( } /** * "Freezes" the contents of the buffer, making it immutable until [unfreeze] is called. * Calls to [log], [obtain], and [commit] will not affect the buffer and will return dummy * values if necessary. * "Freezes" the contents of the buffer, making it immutable until [unfreeze] is called. Calls * to [log], [obtain], and [commit] will not affect the buffer and will return dummy values if * necessary. */ @Synchronized fun freeze() { Loading @@ -241,9 +247,7 @@ class LogBuffer @JvmOverloads constructor( } } /** * Undoes the effects of calling [freeze]. */ /** Undoes the effects of calling [freeze]. */ @Synchronized fun unfreeze() { if (frozen) { Loading @@ -265,8 +269,11 @@ class LogBuffer @JvmOverloads constructor( } private fun echoToSystrace(message: LogMessage, strMessage: String) { Trace.instantForTrack(Trace.TRACE_TAG_APP, "UI Events", "$name - ${message.level.shortString} ${message.tag}: $strMessage") Trace.instantForTrack( Trace.TRACE_TAG_APP, "UI Events", "$name - ${message.level.shortString} ${message.tag}: $strMessage" ) } private fun echoToLogcat(message: LogMessage, strMessage: String) { Loading
packages/SystemUI/src/com/android/systemui/log/LogLevel.kt→packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogLevel.kt +3 −8 Original line number Diff line number Diff line Loading @@ -14,17 +14,12 @@ * limitations under the License. */ package com.android.systemui.log package com.android.systemui.plugins.log import android.util.Log /** * Enum version of @Log.Level */ enum class LogLevel( @Log.Level val nativeLevel: Int, val shortString: String ) { /** Enum version of @Log.Level */ enum class LogLevel(@Log.Level val nativeLevel: Int, val shortString: String) { VERBOSE(Log.VERBOSE, "V"), DEBUG(Log.DEBUG, "D"), INFO(Log.INFO, "I"), Loading
packages/SystemUI/src/com/android/systemui/log/LogMessage.kt→packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogMessage.kt +12 −13 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ * limitations under the License. */ package com.android.systemui.log package com.android.systemui.plugins.log import java.io.PrintWriter import java.text.SimpleDateFormat Loading @@ -29,9 +29,10 @@ import java.util.Locale * * When a message is logged, the code doing the logging stores data in one or more of the generic * fields ([str1], [int1], etc). When it comes time to dump the message to logcat/bugreport/etc, the * [messagePrinter] function reads the data stored in the generic fields and converts that to a human- * readable string. Thus, for every log type there must be a specialized initializer function that * stores data specific to that log type and a specialized printer function that prints that data. * [messagePrinter] function reads the data stored in the generic fields and converts that to a * human- readable string. Thus, for every log type there must be a specialized initializer function * that stores data specific to that log type and a specialized printer function that prints that * data. * * See [LogBuffer.log] for more information. */ Loading @@ -55,9 +56,7 @@ interface LogMessage { var bool3: Boolean var bool4: Boolean /** * Function that dumps the [LogMessage] to the provided [writer]. */ /** Function that dumps the [LogMessage] to the provided [writer]. */ fun dump(writer: PrintWriter) { val formattedTimestamp = DATE_FORMAT.format(timestamp) val shortLevel = level.shortString Loading @@ -68,12 +67,12 @@ interface LogMessage { } /** * A function that will be called if and when the message needs to be dumped to * logcat or a bug report. It should read the data stored by the initializer and convert it to * a human-readable string. The value of `this` will be the LogMessage to be printed. * **IMPORTANT:** The printer should ONLY ever reference fields on the LogMessage and NEVER any * variables in its enclosing scope. Otherwise, the runtime will need to allocate a new instance * of the printer for each call, thwarting our attempts at avoiding any sort of allocation. * A function that will be called if and when the message needs to be dumped to logcat or a bug * report. It should read the data stored by the initializer and convert it to a human-readable * string. The value of `this` will be the LogMessage to be printed. **IMPORTANT:** The printer * should ONLY ever reference fields on the LogMessage and NEVER any variables in its enclosing * scope. Otherwise, the runtime will need to allocate a new instance of the printer for each call, * thwarting our attempts at avoiding any sort of allocation. */ typealias MessagePrinter = LogMessage.() -> String Loading
packages/SystemUI/src/com/android/systemui/log/LogMessageImpl.kt→packages/SystemUI/plugin/src/com/android/systemui/plugins/log/LogMessageImpl.kt +20 −21 Original line number Diff line number Diff line Loading @@ -14,11 +14,9 @@ * limitations under the License. */ package com.android.systemui.log package com.android.systemui.plugins.log /** * Recyclable implementation of [LogMessage]. */ /** Recyclable implementation of [LogMessage]. */ data class LogMessageImpl( override var level: LogLevel, override var tag: String, Loading Loading @@ -84,7 +82,8 @@ data class LogMessageImpl( false, false, false, false) false ) } } } Loading