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

Commit 93399529 authored by Pablo Gamito's avatar Pablo Gamito
Browse files

Remove IOException from trace callback function signature

This is not something that is inherant to the tracing function so shouldn't be part of the method signature

Change-Id: If2908486b07ab016a5ec355ccdea29c8bda0b0ac
parent 102daa4f
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package android.tracing.perfetto;

import java.io.IOException;

/**
 * The interface for the trace function called from native on a trace call with a context.
 *
@@ -36,6 +34,5 @@ public interface TraceFunction<TlsStateType, IncrementalStateType> {
     *
     * @param ctx the tracing context to trace for in the trace function.
     */
    void trace(TracingContext<TlsStateType, IncrementalStateType> ctx)
            throws IOException;
    void trace(TracingContext<TlsStateType, IncrementalStateType> ctx);
}
+74 −58
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import android.tracing.perfetto.InitArguments;
import android.tracing.perfetto.Producer;
import android.tracing.perfetto.TracingContext;
import android.util.ArrayMap;
import android.util.Log;
import android.util.LongArray;
import android.util.Slog;
import android.util.proto.ProtoInputStream;
@@ -67,6 +68,7 @@ import com.android.internal.protolog.common.LogLevel;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
@@ -166,6 +168,7 @@ public class PerfettoProtoLogImpl implements IProtoLog {
        }

        mDataSource.trace(ctx -> {
            try {
                final ProtoOutputStream os = ctx.newTracePacket();

                os.write(TIMESTAMP, SystemClock.elapsedRealtimeNanos());
@@ -173,35 +176,27 @@ public class PerfettoProtoLogImpl implements IProtoLog {
                final long outProtologViewerConfigToken = os.start(PROTOLOG_VIEWER_CONFIG);
                while (pis.nextField() != ProtoInputStream.NO_MORE_FIELDS) {
                    if (pis.getFieldNumber() == (int) MESSAGES) {
                    final long inMessageToken = pis.start(MESSAGES);
                    final long outMessagesToken = os.start(MESSAGES);
                        writeViewerConfigMessage(pis, os);
                    }

                    while (pis.nextField() != ProtoInputStream.NO_MORE_FIELDS) {
                        switch (pis.getFieldNumber()) {
                            case (int) MessageData.MESSAGE_ID:
                                os.write(MessageData.MESSAGE_ID,
                                        pis.readLong(MessageData.MESSAGE_ID));
                                break;
                            case (int) MESSAGE:
                                os.write(MESSAGE, pis.readString(MESSAGE));
                                break;
                            case (int) LEVEL:
                                os.write(LEVEL, pis.readInt(LEVEL));
                                break;
                            case (int) GROUP_ID:
                                os.write(GROUP_ID, pis.readInt(GROUP_ID));
                                break;
                            default:
                                throw new RuntimeException(
                                        "Unexpected field id " + pis.getFieldNumber());
                    if (pis.getFieldNumber() == (int) GROUPS) {
                        writeViewerConfigGroup(pis, os);
                    }
                }

                    pis.end(inMessageToken);
                    os.end(outMessagesToken);
                os.end(outProtologViewerConfigToken);

                ctx.flush();
            } catch (IOException e) {
                Log.e(LOG_TAG, "Failed to read ProtoLog viewer config to dump on tracing end", e);
            }
        });

                if (pis.getFieldNumber() == (int) GROUPS) {
        mDataSource.flush();
    }

    private static void writeViewerConfigGroup(
            ProtoInputStream pis, ProtoOutputStream os) throws IOException {
        final long inGroupToken = pis.start(GROUPS);
        final long outGroupToken = os.start(GROUPS);

@@ -228,14 +223,35 @@ public class PerfettoProtoLogImpl implements IProtoLog {
        pis.end(inGroupToken);
        os.end(outGroupToken);
    }
            }

            os.end(outProtologViewerConfigToken);
    private static void writeViewerConfigMessage(
            ProtoInputStream pis, ProtoOutputStream os) throws IOException {
        final long inMessageToken = pis.start(MESSAGES);
        final long outMessagesToken = os.start(MESSAGES);

            ctx.flush();
        });
        while (pis.nextField() != ProtoInputStream.NO_MORE_FIELDS) {
            switch (pis.getFieldNumber()) {
                case (int) MessageData.MESSAGE_ID:
                    os.write(MessageData.MESSAGE_ID,
                            pis.readLong(MessageData.MESSAGE_ID));
                    break;
                case (int) MESSAGE:
                    os.write(MESSAGE, pis.readString(MESSAGE));
                    break;
                case (int) LEVEL:
                    os.write(LEVEL, pis.readInt(LEVEL));
                    break;
                case (int) GROUP_ID:
                    os.write(GROUP_ID, pis.readInt(GROUP_ID));
                    break;
                default:
                    throw new RuntimeException(
                            "Unexpected field id " + pis.getFieldNumber());
            }
        }

        mDataSource.flush();
        pis.end(inMessageToken);
        os.end(outMessagesToken);
    }

    private void logToLogcat(String tag, LogLevel level, long messageHash,