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

Commit 49a37555 authored by Pablo Gamito's avatar Pablo Gamito
Browse files

Update ProtoLog cache updater to take an ProtoLog instance object

Instead to querying the static variable directly, we pass the instance to use to query the state of tracing.

This makes testing easier, but also addressed the issue of having to
call the cacheUpdate method while enabling the PerfettoProtoLogImpl
which has to happen before we set the instance as the static singleton
this means the update cache method cannot rely on this static variable
on the first call since it won't be set yet as the ProtoLogImpl will not
be fully initialized at that point.

Flag: android.tracing.perfetto_protolog_tracing
Bug: 369560789
Test: atest TracingTests
Change-Id: Ib2befa74bf3f4a89dcf093bdbb0b9cf37c3ac456
parent f85fa9da
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -117,7 +117,7 @@ public class ProtoLogPerfTest {
                sTestDataSource,
                sTestDataSource,
                MOCK_TEST_FILE_PATH,
                MOCK_TEST_FILE_PATH,
                () -> new AutoClosableProtoInputStream(VIEWER_CONFIG.toByteArray()),
                () -> new AutoClosableProtoInputStream(VIEWER_CONFIG.toByteArray()),
                () -> {},
                (instance) -> {},
                TestProtoLogGroup.values()
                TestProtoLogGroup.values()
        );
        );
    }
    }
+4 −4
Original line number Original line Diff line number Diff line
@@ -70,7 +70,7 @@ public class LegacyProtoLogImpl implements IProtoLog {
    private final TraceBuffer mBuffer;
    private final TraceBuffer mBuffer;
    private final LegacyProtoLogViewerConfigReader mViewerConfig;
    private final LegacyProtoLogViewerConfigReader mViewerConfig;
    private final Map<String, IProtoLogGroup> mLogGroups = new TreeMap<>();
    private final Map<String, IProtoLogGroup> mLogGroups = new TreeMap<>();
    private final Runnable mCacheUpdater;
    private final ProtoLogCacheUpdater mCacheUpdater;
    private final int mPerChunkSize;
    private final int mPerChunkSize;


    private boolean mProtoLogEnabled;
    private boolean mProtoLogEnabled;
@@ -78,14 +78,14 @@ public class LegacyProtoLogImpl implements IProtoLog {
    private final Object mProtoLogEnabledLock = new Object();
    private final Object mProtoLogEnabledLock = new Object();


    public LegacyProtoLogImpl(String outputFile, String viewerConfigFilename,
    public LegacyProtoLogImpl(String outputFile, String viewerConfigFilename,
            Runnable cacheUpdater) {
            ProtoLogCacheUpdater cacheUpdater) {
        this(new File(outputFile), viewerConfigFilename, BUFFER_CAPACITY,
        this(new File(outputFile), viewerConfigFilename, BUFFER_CAPACITY,
                new LegacyProtoLogViewerConfigReader(), PER_CHUNK_SIZE, cacheUpdater);
                new LegacyProtoLogViewerConfigReader(), PER_CHUNK_SIZE, cacheUpdater);
    }
    }


    public LegacyProtoLogImpl(File file, String viewerConfigFilename, int bufferCapacity,
    public LegacyProtoLogImpl(File file, String viewerConfigFilename, int bufferCapacity,
            LegacyProtoLogViewerConfigReader viewerConfig, int perChunkSize,
            LegacyProtoLogViewerConfigReader viewerConfig, int perChunkSize,
            Runnable cacheUpdater) {
            ProtoLogCacheUpdater cacheUpdater) {
        mLogFile = file;
        mLogFile = file;
        mBuffer = new TraceBuffer(bufferCapacity);
        mBuffer = new TraceBuffer(bufferCapacity);
        mLegacyViewerConfigFilename = viewerConfigFilename;
        mLegacyViewerConfigFilename = viewerConfigFilename;
@@ -298,7 +298,7 @@ public class LegacyProtoLogImpl implements IProtoLog {
            }
            }
        }
        }


        mCacheUpdater.run();
        mCacheUpdater.update(this);
        return 0;
        return 0;
    }
    }


+6 −6
Original line number Original line Diff line number Diff line
@@ -101,7 +101,7 @@ public abstract class PerfettoProtoLogImpl extends IProtoLogClient.Stub implemen
    @NonNull
    @NonNull
    protected final TreeMap<String, IProtoLogGroup> mLogGroups = new TreeMap<>();
    protected final TreeMap<String, IProtoLogGroup> mLogGroups = new TreeMap<>();
    @NonNull
    @NonNull
    private final Runnable mCacheUpdater;
    private final ProtoLogCacheUpdater mCacheUpdater;


    @NonNull
    @NonNull
    private final int[] mDefaultLogLevelCounts = new int[LogLevel.values().length];
    private final int[] mDefaultLogLevelCounts = new int[LogLevel.values().length];
@@ -118,7 +118,7 @@ public abstract class PerfettoProtoLogImpl extends IProtoLogClient.Stub implemen


    protected PerfettoProtoLogImpl(
    protected PerfettoProtoLogImpl(
            @NonNull ProtoLogDataSource dataSource,
            @NonNull ProtoLogDataSource dataSource,
            @NonNull Runnable cacheUpdater,
            @NonNull ProtoLogCacheUpdater cacheUpdater,
            @NonNull IProtoLogGroup[] groups) throws ServiceManager.ServiceNotFoundException {
            @NonNull IProtoLogGroup[] groups) throws ServiceManager.ServiceNotFoundException {
        this(dataSource, cacheUpdater, groups,
        this(dataSource, cacheUpdater, groups,
                android.tracing.Flags.clientSideProtoLogging() ?
                android.tracing.Flags.clientSideProtoLogging() ?
@@ -130,7 +130,7 @@ public abstract class PerfettoProtoLogImpl extends IProtoLogClient.Stub implemen


    protected PerfettoProtoLogImpl(
    protected PerfettoProtoLogImpl(
            @NonNull ProtoLogDataSource dataSource,
            @NonNull ProtoLogDataSource dataSource,
            @NonNull Runnable cacheUpdater,
            @NonNull ProtoLogCacheUpdater cacheUpdater,
            @NonNull IProtoLogGroup[] groups,
            @NonNull IProtoLogGroup[] groups,
            @Nullable IProtoLogConfigurationService configurationService) {
            @Nullable IProtoLogConfigurationService configurationService) {
        mDataSource = dataSource;
        mDataSource = dataSource;
@@ -716,7 +716,7 @@ public abstract class PerfettoProtoLogImpl extends IProtoLogClient.Stub implemen
            }
            }
        }
        }


        mCacheUpdater.run();
        mCacheUpdater.update(this);
        return 0;
        return 0;
    }
    }


@@ -759,7 +759,7 @@ public abstract class PerfettoProtoLogImpl extends IProtoLogClient.Stub implemen
            }
            }
        }
        }


        mCacheUpdater.run();
        mCacheUpdater.update(this);


        this.mTracingInstances.incrementAndGet();
        this.mTracingInstances.incrementAndGet();


@@ -799,7 +799,7 @@ public abstract class PerfettoProtoLogImpl extends IProtoLogClient.Stub implemen
            }
            }
        }
        }


        mCacheUpdater.run();
        mCacheUpdater.update(this);
        Log.d(LOG_TAG, "Finished onTracingInstanceStop");
        Log.d(LOG_TAG, "Finished onTracingInstanceStop");
    }
    }


+3 −3
Original line number Original line Diff line number Diff line
@@ -44,7 +44,7 @@ public class ProcessedPerfettoProtoLogImpl extends PerfettoProtoLogImpl {
    public ProcessedPerfettoProtoLogImpl(
    public ProcessedPerfettoProtoLogImpl(
            @NonNull ProtoLogDataSource datasource,
            @NonNull ProtoLogDataSource datasource,
            @NonNull String viewerConfigFilePath,
            @NonNull String viewerConfigFilePath,
            @NonNull Runnable cacheUpdater,
            @NonNull ProtoLogCacheUpdater cacheUpdater,
            @NonNull IProtoLogGroup[] groups) throws ServiceManager.ServiceNotFoundException {
            @NonNull IProtoLogGroup[] groups) throws ServiceManager.ServiceNotFoundException {
        this(datasource, viewerConfigFilePath, new ViewerConfigInputStreamProvider() {
        this(datasource, viewerConfigFilePath, new ViewerConfigInputStreamProvider() {
                    @NonNull
                    @NonNull
@@ -68,7 +68,7 @@ public class ProcessedPerfettoProtoLogImpl extends PerfettoProtoLogImpl {
            @NonNull ProtoLogDataSource datasource,
            @NonNull ProtoLogDataSource datasource,
            @NonNull String viewerConfigFilePath,
            @NonNull String viewerConfigFilePath,
            @NonNull ViewerConfigInputStreamProvider viewerConfigInputStreamProvider,
            @NonNull ViewerConfigInputStreamProvider viewerConfigInputStreamProvider,
            @NonNull Runnable cacheUpdater,
            @NonNull ProtoLogCacheUpdater cacheUpdater,
            @NonNull IProtoLogGroup[] groups) throws ServiceManager.ServiceNotFoundException {
            @NonNull IProtoLogGroup[] groups) throws ServiceManager.ServiceNotFoundException {
        super(datasource, cacheUpdater, groups);
        super(datasource, cacheUpdater, groups);


@@ -86,7 +86,7 @@ public class ProcessedPerfettoProtoLogImpl extends PerfettoProtoLogImpl {
            @NonNull String viewerConfigFilePath,
            @NonNull String viewerConfigFilePath,
            @NonNull ViewerConfigInputStreamProvider viewerConfigInputStreamProvider,
            @NonNull ViewerConfigInputStreamProvider viewerConfigInputStreamProvider,
            @NonNull ProtoLogViewerConfigReader viewerConfigReader,
            @NonNull ProtoLogViewerConfigReader viewerConfigReader,
            @NonNull Runnable cacheUpdater,
            @NonNull ProtoLogCacheUpdater cacheUpdater,
            @NonNull IProtoLogGroup[] groups,
            @NonNull IProtoLogGroup[] groups,
            @Nullable IProtoLogConfigurationService configurationService)
            @Nullable IProtoLogConfigurationService configurationService)
            throws ServiceManager.ServiceNotFoundException {
            throws ServiceManager.ServiceNotFoundException {
+28 −0
Original line number Original line 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.internal.protolog;

import com.android.internal.protolog.common.IProtoLog;

public interface ProtoLogCacheUpdater {
    /**
     * Update the cache based on the latest state of the active tracing configurations.
     *
     * @param protoLogInstance the instance to use to query the latest state of tracing.
     */
    void update(IProtoLog protoLogInstance);
}
Loading