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

Commit 15ac2ef9 authored by Pablo Gamito's avatar Pablo Gamito Committed by Android (Google) Code Review
Browse files

Merge changes from topic "load-logcat-groups-viewer-config-on-registration" into main

* changes:
  Handle case where viewer config file is not found
  Register ProtoLog groups on ShellInit instance creation
  Add nullability annotations
  Load viewer configs of groups that have logToLogcat enabled on registration
parents 983f5c5e d73113e9
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import com.android.internal.protolog.common.IProtoLogGroup;
import com.android.internal.protolog.common.LogDataType;
import com.android.internal.protolog.common.LogLevel;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -100,6 +101,7 @@ public class PerfettoProtoLogImpl implements IProtoLog {
    );
    @Nullable
    private final ProtoLogViewerConfigReader mViewerConfigReader;
    @Nullable
    private final ViewerConfigInputStreamProvider mViewerConfigInputStreamProvider;
    private final TreeMap<String, IProtoLogGroup> mLogGroups = new TreeMap<>();
    private final Runnable mCacheUpdater;
@@ -111,13 +113,12 @@ public class PerfettoProtoLogImpl implements IProtoLog {
    private final Lock mBackgroundServiceLock = new ReentrantLock();
    private ExecutorService mBackgroundLoggingService = Executors.newSingleThreadExecutor();

    public PerfettoProtoLogImpl(String viewerConfigFilePath, Runnable cacheUpdater) {
    public PerfettoProtoLogImpl(@NonNull String viewerConfigFilePath, Runnable cacheUpdater) {
        this(() -> {
            try {
                return new ProtoInputStream(new FileInputStream(viewerConfigFilePath));
            } catch (FileNotFoundException e) {
                Slog.w(LOG_TAG, "Failed to load viewer config file " + viewerConfigFilePath, e);
                return null;
                throw new RuntimeException("Failed to load viewer config file " + viewerConfigFilePath, e);
            }
        }, cacheUpdater);
    }
@@ -127,7 +128,7 @@ public class PerfettoProtoLogImpl implements IProtoLog {
    }

    public PerfettoProtoLogImpl(
            @Nullable ViewerConfigInputStreamProvider viewerConfigInputStreamProvider,
            @NonNull ViewerConfigInputStreamProvider viewerConfigInputStreamProvider,
            Runnable cacheUpdater
    ) {
        this(viewerConfigInputStreamProvider,
@@ -242,6 +243,15 @@ public class PerfettoProtoLogImpl implements IProtoLog {
        for (IProtoLogGroup protoLogGroup : protoLogGroups) {
            mLogGroups.put(protoLogGroup.name(), protoLogGroup);
        }

        final String[] groupsLoggingToLogcat = Arrays.stream(protoLogGroups)
                .filter(IProtoLogGroup::isLogToLogcat)
                .map(IProtoLogGroup::name)
                .toArray(String[]::new);

        if (mViewerConfigReader != null) {
            mViewerConfigReader.loadViewerConfig(groupsLoggingToLogcat);
        }
    }

    /**
+10 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.internal.protolog.common.IProtoLogGroup;
import com.android.internal.protolog.common.LogLevel;
import com.android.internal.protolog.common.ProtoLogToolInjected;

import java.io.File;
import java.util.TreeMap;

/**
@@ -105,7 +106,15 @@ public class ProtoLogImpl {
    public static synchronized IProtoLog getSingleInstance() {
        if (sServiceInstance == null) {
            if (android.tracing.Flags.perfettoProtologTracing()) {
                File f = new File(sViewerConfigPath);
                if (!ProtoLog.REQUIRE_PROTOLOGTOOL && !f.exists()) {
                    // TODO(b/353530422): Remove - temporary fix to unblock b/352290057
                    // In so tests the viewer config file might not exist in which we don't
                    // want to provide config path to the user
                    sServiceInstance = new PerfettoProtoLogImpl(null, null, sCacheUpdater);
                } else {
                    sServiceInstance = new PerfettoProtoLogImpl(sViewerConfigPath, sCacheUpdater);
                }
            } else {
                sServiceInstance = new LegacyProtoLogImpl(
                        sLegacyOutputFilePath, sLegacyViewerConfigPath, sCacheUpdater);
+2 −1
Original line number Diff line number Diff line
@@ -24,12 +24,13 @@ import java.util.Set;
import java.util.TreeMap;

public class ProtoLogViewerConfigReader {
    @NonNull
    private final ViewerConfigInputStreamProvider mViewerConfigInputStreamProvider;
    private final Map<String, Set<Long>> mGroupHashes = new TreeMap<>();
    private final LongSparseArray<String> mLogMessageMap = new LongSparseArray<>();

    public ProtoLogViewerConfigReader(
            ViewerConfigInputStreamProvider viewerConfigInputStreamProvider) {
            @NonNull ViewerConfigInputStreamProvider viewerConfigInputStreamProvider) {
        this.mViewerConfigInputStreamProvider = viewerConfigInputStreamProvider;
    }

+2 −0
Original line number Diff line number Diff line
@@ -16,11 +16,13 @@

package com.android.internal.protolog;

import android.annotation.NonNull;
import android.util.proto.ProtoInputStream;

public interface ViewerConfigInputStreamProvider {
    /**
     * @return a ProtoInputStream.
     */
    @NonNull
    ProtoInputStream getInputStream();
}
+1 −1
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ public class ShellInit {

    public ShellInit(ShellExecutor mainExecutor) {
        mMainExecutor = mainExecutor;
        ProtoLog.registerGroups(ShellProtoLogGroup.values());
    }

    /**
@@ -76,7 +77,6 @@ public class ShellInit {
     */
    @VisibleForTesting
    public void init() {
        ProtoLog.registerGroups(ShellProtoLogGroup.values());
        ProtoLog.v(WM_SHELL_INIT, "Initializing Shell Components: %d", mInitCallbacks.size());
        SurfaceControl.setDebugUsageAfterRelease(true);
        // Init in order of registration