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

Commit ffece038 authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato
Browse files

Allow to specify custom track name in LogBuffer

This allows to use custom track names for each logbuffer.

As part of this cl, also NotifiactionsLog Logbuffers are all grouped under a "Notification pipeline" track group in perfetto traces (only for the ones that were already in systrace)

+ add a check for Trace.isEnabled before generating the concatenated string in LogBuffer.echoToSystrace

Bug: 362719719
Bug: 337016334
Test: Perfetto trace
Flag: NONE - tracing change
Change-Id: I2d0375ac275c980b63fd02c6ec0df3ba9847b849
parent f71aa0da
Loading
Loading
Loading
Loading
+8 −2
Original line number Original line Diff line number Diff line
@@ -75,6 +75,7 @@ constructor(
    private val maxSize: Int,
    private val maxSize: Int,
    private val logcatEchoTracker: LogcatEchoTracker,
    private val logcatEchoTracker: LogcatEchoTracker,
    private val systrace: Boolean = true,
    private val systrace: Boolean = true,
    private val systraceTrackName: String = DEFAULT_LOGBUFFER_TRACK_NAME,
) : MessageBuffer {
) : MessageBuffer {
    private val buffer = RingBuffer(maxSize) { LogMessageImpl.create() }
    private val buffer = RingBuffer(maxSize) { LogMessageImpl.create() }


@@ -244,10 +245,11 @@ constructor(
    }
    }


    private fun echoToSystrace(level: LogLevel, tag: String, strMessage: String) {
    private fun echoToSystrace(level: LogLevel, tag: String, strMessage: String) {
        if (!Trace.isEnabled()) return
        Trace.instantForTrack(
        Trace.instantForTrack(
            Trace.TRACE_TAG_APP,
            Trace.TRACE_TAG_APP,
            "UI Events",
            systraceTrackName,
            "$name - ${level.shortString} $tag: $strMessage"
            "$name - ${level.shortString} $tag: $strMessage",
        )
        )
    }
    }


@@ -261,6 +263,10 @@ constructor(
            LogLevel.WTF -> Log.wtf(message.tag, strMessage, message.exception)
            LogLevel.WTF -> Log.wtf(message.tag, strMessage, message.exception)
        }
        }
    }
    }

    companion object {
        const val DEFAULT_LOGBUFFER_TRACK_NAME = "UI Events"
    }
}
}


private const val TAG = "LogBuffer"
private const val TAG = "LogBuffer"
+1 −1
Original line number Original line Diff line number Diff line
@@ -54,7 +54,7 @@ class QSTileLoggerTest : SysuiTestCase() {
    @Before
    @Before
    fun setup() {
    fun setup() {
        MockitoAnnotations.initMocks(this)
        MockitoAnnotations.initMocks(this)
        whenever(logBufferFactory.create(any(), any(), any(), any())).thenReturn(logBuffer)
        whenever(logBufferFactory.create(any(), any(), any(), any(), any())).thenReturn(logBuffer)
        val tileSpec: TileSpec = TileSpec.create("chatty_tile")
        val tileSpec: TileSpec = TileSpec.create("chatty_tile")
        underTest =
        underTest =
            QSTileLogger(mapOf(tileSpec to chattyLogBuffer), logBufferFactory, statusBarController)
            QSTileLogger(mapOf(tileSpec to chattyLogBuffer), logBufferFactory, statusBarController)
+5 −2
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.log


import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dump.DumpManager
import com.android.systemui.dump.DumpManager
import com.android.systemui.log.LogBuffer.Companion.DEFAULT_LOGBUFFER_TRACK_NAME
import com.android.systemui.log.LogBufferHelper.Companion.adjustMaxSize
import com.android.systemui.log.LogBufferHelper.Companion.adjustMaxSize
import com.android.systemui.log.echo.LogcatEchoTrackerAlways
import com.android.systemui.log.echo.LogcatEchoTrackerAlways
import javax.inject.Inject
import javax.inject.Inject
@@ -27,7 +28,7 @@ class LogBufferFactory
@Inject
@Inject
constructor(
constructor(
    private val dumpManager: DumpManager,
    private val dumpManager: DumpManager,
    private val logcatEchoTracker: LogcatEchoTracker
    private val logcatEchoTracker: LogcatEchoTracker,
) {
) {
    @JvmOverloads
    @JvmOverloads
    fun create(
    fun create(
@@ -35,9 +36,11 @@ constructor(
        maxSize: Int,
        maxSize: Int,
        systrace: Boolean = true,
        systrace: Boolean = true,
        alwaysLogToLogcat: Boolean = false,
        alwaysLogToLogcat: Boolean = false,
        systraceTrackName: String = DEFAULT_LOGBUFFER_TRACK_NAME,
    ): LogBuffer {
    ): LogBuffer {
        val echoTracker = if (alwaysLogToLogcat) LogcatEchoTrackerAlways else logcatEchoTracker
        val echoTracker = if (alwaysLogToLogcat) LogcatEchoTrackerAlways else logcatEchoTracker
        val buffer = LogBuffer(name, adjustMaxSize(maxSize), echoTracker, systrace)
        val buffer =
            LogBuffer(name, adjustMaxSize(maxSize), echoTracker, systrace, systraceTrackName)
        dumpManager.registerBuffer(name, buffer)
        dumpManager.registerBuffer(name, buffer)
        return buffer
        return buffer
    }
    }
+42 −6
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.systemui.statusbar.notification.logging.dagger
package com.android.systemui.statusbar.notification.logging.dagger


import com.android.app.tracing.TrackGroupUtils.trackGroup
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogBufferFactory
import com.android.systemui.log.LogBufferFactory
@@ -44,7 +45,11 @@ object NotificationsLogModule {
    @SysUISingleton
    @SysUISingleton
    @NotificationHeadsUpLog
    @NotificationHeadsUpLog
    fun provideNotificationHeadsUpLogBuffer(factory: LogBufferFactory): LogBuffer {
    fun provideNotificationHeadsUpLogBuffer(factory: LogBufferFactory): LogBuffer {
        return factory.create("NotifHeadsUpLog", 1000)
        return factory.create(
            "NotifHeadsUpLog",
            1000,
            systraceTrackName = notifPipelineTrack("NotifHeadsUpLog"),
        )
    }
    }


    /** Provides a logging buffer for logs related to inflation of notifications. */
    /** Provides a logging buffer for logs related to inflation of notifications. */
@@ -52,7 +57,11 @@ object NotificationsLogModule {
    @SysUISingleton
    @SysUISingleton
    @NotifInflationLog
    @NotifInflationLog
    fun provideNotifInflationLogBuffer(factory: LogBufferFactory): LogBuffer {
    fun provideNotifInflationLogBuffer(factory: LogBufferFactory): LogBuffer {
        return factory.create("NotifInflationLog", 250)
        return factory.create(
            "NotifInflationLog",
            250,
            systraceTrackName = notifPipelineTrack("NotifInflationLog"),
        )
    }
    }


    /** Provides a logging buffer for all logs related to the data layer of notifications. */
    /** Provides a logging buffer for all logs related to the data layer of notifications. */
@@ -60,7 +69,11 @@ object NotificationsLogModule {
    @SysUISingleton
    @SysUISingleton
    @NotifInteractionLog
    @NotifInteractionLog
    fun provideNotifInteractionLogBuffer(factory: LogBufferFactory): LogBuffer {
    fun provideNotifInteractionLogBuffer(factory: LogBufferFactory): LogBuffer {
        return factory.create("NotifInteractionLog", 50)
        return factory.create(
            "NotifInteractionLog",
            50,
            systraceTrackName = notifPipelineTrack("NotifInteractionLog"),
        )
    }
    }


    /** Provides a logging buffer for notification interruption calculations. */
    /** Provides a logging buffer for notification interruption calculations. */
@@ -68,7 +81,11 @@ object NotificationsLogModule {
    @SysUISingleton
    @SysUISingleton
    @NotificationInterruptLog
    @NotificationInterruptLog
    fun provideNotificationInterruptLogBuffer(factory: LogBufferFactory): LogBuffer {
    fun provideNotificationInterruptLogBuffer(factory: LogBufferFactory): LogBuffer {
        return factory.create("NotifInterruptLog", 100)
        return factory.create(
            "NotifInterruptLog",
            100,
            systraceTrackName = notifPipelineTrack("NotifInterruptLog"),
        )
    }
    }


    /** Provides a logging buffer for all logs related to notifications on the lockscreen. */
    /** Provides a logging buffer for all logs related to notifications on the lockscreen. */
@@ -91,7 +108,12 @@ object NotificationsLogModule {
        if (Compile.IS_DEBUG && notifPipelineFlags.isDevLoggingEnabled()) {
        if (Compile.IS_DEBUG && notifPipelineFlags.isDevLoggingEnabled()) {
            maxSize *= 10
            maxSize *= 10
        }
        }
        return factory.create("NotifLog", maxSize, Compile.IS_DEBUG /* systrace */)
        return factory.create(
            "NotifLog",
            maxSize,
            /* systrace= */ Compile.IS_DEBUG,
            systraceTrackName = notifPipelineTrack("NotifLog"),
        )
    }
    }


    /** Provides a logging buffer for all logs related to remote input controller. */
    /** Provides a logging buffer for all logs related to remote input controller. */
@@ -107,7 +129,11 @@ object NotificationsLogModule {
    @SysUISingleton
    @SysUISingleton
    @NotificationRenderLog
    @NotificationRenderLog
    fun provideNotificationRenderLogBuffer(factory: LogBufferFactory): LogBuffer {
    fun provideNotificationRenderLogBuffer(factory: LogBufferFactory): LogBuffer {
        return factory.create("NotifRenderLog", 100)
        return factory.create(
            "NotifRenderLog",
            100,
            systraceTrackName = notifPipelineTrack("NotifRenderLog"),
        )
    }
    }


    /** Provides a logging buffer for all logs related to managing notification sections. */
    /** Provides a logging buffer for all logs related to managing notification sections. */
@@ -150,3 +176,13 @@ object NotificationsLogModule {
        return factory.create("VisualStabilityLog", 50, /* maxSize */ false /* systrace */)
        return factory.create("VisualStabilityLog", 50, /* maxSize */ false /* systrace */)
    }
    }
}
}

private const val NOTIF_PIPELINE_TRACK_GROUP_NAME = "Notification pipeline"

/**
 * This generates a track name that is hierarcically collapsed inside
 * [NOTIF_PIPELINE_TRACK_GROUP_NAME] in perfetto traces.
 */
private fun notifPipelineTrack(trackName: String): String {
    return trackGroup(NOTIF_PIPELINE_TRACK_GROUP_NAME, trackName)
}