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

Commit 554eab73 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Allow to specify custom track name in LogBuffer" into main

parents cdd20d98 ffece038
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ constructor(
    private val maxSize: Int,
    private val logcatEchoTracker: LogcatEchoTracker,
    private val systrace: Boolean = true,
    private val systraceTrackName: String = DEFAULT_LOGBUFFER_TRACK_NAME,
) : MessageBuffer {
    private val buffer = RingBuffer(maxSize) { LogMessageImpl.create() }

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

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

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

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

private const val TAG = "LogBuffer"
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ class QSTileLoggerTest : SysuiTestCase() {
    @Before
    fun setup() {
        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")
        underTest =
            QSTileLogger(mapOf(tileSpec to chattyLogBuffer), logBufferFactory, statusBarController)
+5 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.log

import com.android.systemui.dagger.SysUISingleton
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.echo.LogcatEchoTrackerAlways
import javax.inject.Inject
@@ -27,7 +28,7 @@ class LogBufferFactory
@Inject
constructor(
    private val dumpManager: DumpManager,
    private val logcatEchoTracker: LogcatEchoTracker
    private val logcatEchoTracker: LogcatEchoTracker,
) {
    @JvmOverloads
    fun create(
@@ -35,9 +36,11 @@ constructor(
        maxSize: Int,
        systrace: Boolean = true,
        alwaysLogToLogcat: Boolean = false,
        systraceTrackName: String = DEFAULT_LOGBUFFER_TRACK_NAME,
    ): LogBuffer {
        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)
        return buffer
    }
+42 −6
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

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.log.LogBuffer
import com.android.systemui.log.LogBufferFactory
@@ -44,7 +45,11 @@ object NotificationsLogModule {
    @SysUISingleton
    @NotificationHeadsUpLog
    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. */
@@ -52,7 +57,11 @@ object NotificationsLogModule {
    @SysUISingleton
    @NotifInflationLog
    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. */
@@ -60,7 +69,11 @@ object NotificationsLogModule {
    @SysUISingleton
    @NotifInteractionLog
    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. */
@@ -68,7 +81,11 @@ object NotificationsLogModule {
    @SysUISingleton
    @NotificationInterruptLog
    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. */
@@ -91,7 +108,12 @@ object NotificationsLogModule {
        if (Compile.IS_DEBUG && notifPipelineFlags.isDevLoggingEnabled()) {
            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. */
@@ -107,7 +129,11 @@ object NotificationsLogModule {
    @SysUISingleton
    @NotificationRenderLog
    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. */
@@ -150,3 +176,13 @@ object NotificationsLogModule {
        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)
}