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

Commit 6c984cc9 authored by Kean Mariotti's avatar Kean Mariotti
Browse files

wm tracing: add support for dump

Flag: android.tracing.perfetto_wm_tracing
Bug: 323165543
Test: presubmit
Change-Id: Ib4cbe667930b696c043e52ae269ad21458c867e7
parent f52bea98
Loading
Loading
Loading
Loading
+43 −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.server.wm;

import android.annotation.IntDef;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@IntDef({
        WindowTraceLogFrequency.FRAME,
        WindowTraceLogFrequency.TRANSACTION,
        WindowTraceLogFrequency.SINGLE_DUMP,
})
@Retention(RetentionPolicy.SOURCE)
@interface WindowTraceLogFrequency {
    /**
     * Trace state snapshots when a frame is committed.
     */
    int FRAME = 0;
    /**
     * Trace state snapshots when a transaction is committed.
     */
    int TRANSACTION = 1;
    /**
     * Trace single state snapshots when the Perfetto data source is started.
     */
    int SINGLE_DUMP = 2;
}
+18 −12
Original line number Diff line number Diff line
@@ -51,11 +51,13 @@ public final class WindowTracingDataSource extends DataSource<WindowTracingDataS

    public static class Config {
        public final @WindowTraceLogLevel int mLogLevel;
        public final boolean mLogOnFrame;
        public final @WindowTraceLogFrequency int mLogFrequency;

        private Config(@WindowTraceLogLevel int logLevel, boolean logOnFrame) {
        private Config(
                @WindowTraceLogLevel int logLevel,
                @WindowTraceLogFrequency int logFrequency) {
            mLogLevel = logLevel;
            mLogOnFrame = logOnFrame;
            mLogFrequency = logFrequency;
        }
    }

@@ -68,7 +70,8 @@ public final class WindowTracingDataSource extends DataSource<WindowTracingDataS
        }
    }

    private static final Config CONFIG_DEFAULT = new Config(WindowTraceLogLevel.TRIM, true);
    private static final Config CONFIG_DEFAULT =
            new Config(WindowTraceLogLevel.TRIM, WindowTraceLogFrequency.FRAME);
    private static final int CONFIG_VALUE_UNSPECIFIED = 0;
    private static final String TAG = "WindowTracingDataSource";

@@ -181,24 +184,27 @@ public final class WindowTracingDataSource extends DataSource<WindowTracingDataS
                break;
        }

        boolean logOnFrame;
        @WindowTraceLogFrequency int logFrequency;
        switch(parsedLogFrequency) {
            case CONFIG_VALUE_UNSPECIFIED:
                Log.w(TAG, "Unspecified log frequency. Defaulting to 'log on frame'");
                logOnFrame = true;
                Log.w(TAG, "Unspecified log frequency. Defaulting to 'frame'");
                logFrequency = WindowTraceLogFrequency.FRAME;
                break;
            case WindowManagerConfig.LOG_FREQUENCY_FRAME:
                logOnFrame = true;
                logFrequency = WindowTraceLogFrequency.FRAME;
                break;
            case WindowManagerConfig.LOG_FREQUENCY_TRANSACTION:
                logOnFrame = false;
                logFrequency = WindowTraceLogFrequency.TRANSACTION;
                break;
            case WindowManagerConfig.LOG_FREQUENCY_SINGLE_DUMP:
                logFrequency = WindowTraceLogFrequency.SINGLE_DUMP;
                break;
            default:
                Log.w(TAG, "Unrecognized log frequency. Defaulting to 'log on frame'");
                logOnFrame = true;
                Log.w(TAG, "Unrecognized log frequency. Defaulting to 'frame'");
                logFrequency = WindowTraceLogFrequency.FRAME;
                break;
        }

        return new Config(logLevel, logOnFrame);
        return new Config(logLevel, logFrequency);
    }
}
+13 −6
Original line number Diff line number Diff line
@@ -110,7 +110,14 @@ class WindowTracingPerfetto extends WindowTracing {
                    if (!isDataSourceStarting) {
                        return;
                    }
                } else if (isOnFrameLogEvent != dataSourceConfig.mLogOnFrame) {
                } else if (isOnFrameLogEvent) {
                    boolean isDataSourceLoggingOnFrame =
                            dataSourceConfig.mLogFrequency == WindowTraceLogFrequency.FRAME;
                    if (!isDataSourceLoggingOnFrame) {
                        return;
                    }
                } else if (dataSourceConfig.mLogFrequency == WindowTraceLogFrequency.SINGLE_DUMP) {
                    // In it is a dump, write only the start log event and skip the following ones
                    return;
                }

@@ -141,21 +148,21 @@ class WindowTracingPerfetto extends WindowTracing {
    }

    private void onStart(WindowTracingDataSource.Config config) {
        if (config.mLogOnFrame) {
        if (config.mLogFrequency == WindowTraceLogFrequency.FRAME) {
            mCountSessionsOnFrame.incrementAndGet();
        } else {
        } else if (config.mLogFrequency == WindowTraceLogFrequency.TRANSACTION) {
            mCountSessionsOnTransaction.incrementAndGet();
        }

        Log.i(TAG, "Started with logLevel: " + config.mLogLevel
                + " logOnFrame: " + config.mLogOnFrame);
                + " logFrequency: " + config.mLogFrequency);
        log(WHERE_START_TRACING);
    }

    private void onStop(WindowTracingDataSource.Config config) {
        if (config.mLogOnFrame) {
        if (config.mLogFrequency == WindowTraceLogFrequency.FRAME) {
            mCountSessionsOnFrame.decrementAndGet();
        } else {
        } else if (config.mLogFrequency == WindowTraceLogFrequency.TRANSACTION) {
            mCountSessionsOnTransaction.decrementAndGet();
        }
        Log.i(TAG, "Stopped");