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

Commit 87f0e837 authored by Nicolò Mazzucato's avatar Nicolò Mazzucato
Browse files

Introduce ShadeTraceLogger

This class unifies trace events related to the trace in a new track in perfetto.

This makes understanding what's going on much easier, as events are not lost in the middle of the main thread, but immediately visible and easy to parse.

This will be particurlarly helpful to debug cases of slow shade move between display from field traces.

Bug: 362719719
Bug: 378688537
Test: perfetto trace
Flag: com.android.systemui.shade_window_goes_around
Change-Id: I16f037945388e810fa21b5436cffab26e87a8f40
parent 5f4a8c13
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -169,6 +169,7 @@ public class NotificationShadeWindowView extends WindowRootView {
    public void onMovedToDisplay(int displayId, Configuration config) {
        super.onMovedToDisplay(displayId, config);
        ShadeWindowGoesAround.isUnexpectedlyInLegacyMode();
        ShadeTraceLogger.INSTANCE.logOnMovedToDisplay(displayId, config);
        if (mConfigurationForwarder != null) {
            mConfigurationForwarder.dispatchOnMovedToDisplay(displayId, config);
        }
@@ -180,6 +181,7 @@ public class NotificationShadeWindowView extends WindowRootView {
    @Override
    protected void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        ShadeTraceLogger.INSTANCE.logOnConfigChanged(newConfig);
        if (mConfigurationForwarder != null) {
            ShadeWindowGoesAround.isUnexpectedlyInLegacyMode();
            mConfigurationForwarder.onConfigurationChanged(newConfig);
+59 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.shade

import android.content.res.Configuration
import android.os.Trace
import com.android.app.tracing.TraceUtils.traceAsync

/**
 * Centralized logging for shade-related events to a dedicated Perfetto track.
 *
 * Used by shade components to log events to a track named [TAG]. This consolidates shade-specific
 * events into a single track for easier analysis in Perfetto, rather than scattering them across
 * various threads' logs.
 */
object ShadeTraceLogger {
    private const val TAG = "ShadeTraceLogger"

    fun logOnMovedToDisplay(displayId: Int, config: Configuration) {
        if (!Trace.isEnabled()) return
        Trace.instantForTrack(
            Trace.TRACE_TAG_APP,
            TAG,
            "onMovedToDisplay(displayId=$displayId, dpi=" + config.densityDpi + ")",
        )
    }

    fun logOnConfigChanged(config: Configuration) {
        if (!Trace.isEnabled()) return
        Trace.instantForTrack(
            Trace.TRACE_TAG_APP,
            TAG,
            "onConfigurationChanged(dpi=" + config.densityDpi + ")",
        )
    }

    fun logMoveShadeWindowTo(displayId: Int) {
        if (!Trace.isEnabled()) return
        Trace.instantForTrack(Trace.TRACE_TAG_APP, TAG, "moveShadeWindowTo(displayId=$displayId)")
    }

    fun traceReparenting(r: () -> Unit) {
        traceAsync(TAG, { "reparenting" }) { r() }
    }
}
+6 −1
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.scene.ui.view.WindowRootView
import com.android.systemui.shade.ShadeDisplayAware
import com.android.systemui.shade.ShadeTraceLogger.logMoveShadeWindowTo
import com.android.systemui.shade.ShadeTraceLogger.traceReparenting
import com.android.systemui.shade.data.repository.ShadeDisplaysRepository
import com.android.systemui.shade.shared.flag.ShadeWindowGoesAround
import com.android.systemui.util.kotlin.getOrNull
@@ -68,6 +70,7 @@ constructor(
    /** Tries to move the shade. If anything wrong happens, fails gracefully without crashing. */
    private suspend fun moveShadeWindowTo(destinationId: Int) {
        Log.d(TAG, "Trying to move shade window to display with id $destinationId")
        logMoveShadeWindowTo(destinationId)
        // Why using the shade context here instead of the view's Display?
        // The context's display is updated before the view one, so it is a better indicator of
        // which display the shade is supposed to be at. The View display is updated after the first
@@ -83,7 +86,9 @@ constructor(
            return
        }
        try {
            withContext(mainThreadContext) { reparentToDisplayId(id = destinationId) }
            withContext(mainThreadContext) {
                traceReparenting { reparentToDisplayId(id = destinationId) }
            }
        } catch (e: IllegalStateException) {
            Log.e(
                TAG,