Loading core/java/com/android/internal/protolog/LegacyProtoLogImpl.java +0 −1 Original line number Diff line number Diff line Loading @@ -419,7 +419,6 @@ public class LegacyProtoLogImpl implements IProtoLog { return group.isLogToLogcat() || (group.isLogToProto() && isProtoEnabled()); } @Override public void registerGroups(IProtoLogGroup... protoLogGroups) { for (IProtoLogGroup group : protoLogGroups) { mLogGroups.put(group.name(), group); Loading core/java/com/android/internal/protolog/LogcatOnlyProtoLogImpl.java +0 −5 Original line number Diff line number Diff line Loading @@ -79,9 +79,4 @@ public class LogcatOnlyProtoLogImpl implements IProtoLog { public boolean isEnabled(IProtoLogGroup group, LogLevel level) { return true; } @Override public void registerGroups(IProtoLogGroup... protoLogGroups) { // Does nothing } } core/java/com/android/internal/protolog/PerfettoProtoLogImpl.java +28 −17 Original line number Diff line number Diff line Loading @@ -89,6 +89,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.stream.Stream; /** * A service for the ProtoLog logging system. Loading Loading @@ -125,17 +126,18 @@ public class PerfettoProtoLogImpl extends IProtoLogClient.Stub implements IProto private final Lock mBackgroundServiceLock = new ReentrantLock(); private ExecutorService mBackgroundLoggingService = Executors.newSingleThreadExecutor(); public PerfettoProtoLogImpl() { this(null, null, null, () -> {}); public PerfettoProtoLogImpl(@NonNull IProtoLogGroup[] groups) { this(null, null, null, () -> {}, groups); } public PerfettoProtoLogImpl(@NonNull Runnable cacheUpdater) { this(null, null, null, cacheUpdater); public PerfettoProtoLogImpl(@NonNull Runnable cacheUpdater, @NonNull IProtoLogGroup[] groups) { this(null, null, null, cacheUpdater, groups); } public PerfettoProtoLogImpl( @NonNull String viewerConfigFilePath, @NonNull Runnable cacheUpdater) { @NonNull Runnable cacheUpdater, @NonNull IProtoLogGroup[] groups) { this(viewerConfigFilePath, null, new ProtoLogViewerConfigReader(() -> { Loading @@ -146,22 +148,24 @@ public class PerfettoProtoLogImpl extends IProtoLogClient.Stub implements IProto "Failed to load viewer config file " + viewerConfigFilePath, e); } }), cacheUpdater); cacheUpdater, groups); } @VisibleForTesting public PerfettoProtoLogImpl( @Nullable ViewerConfigInputStreamProvider viewerConfigInputStreamProvider, @Nullable ProtoLogViewerConfigReader viewerConfigReader, @NonNull Runnable cacheUpdater) { this(null, viewerConfigInputStreamProvider, viewerConfigReader, cacheUpdater); @NonNull Runnable cacheUpdater, @NonNull IProtoLogGroup[] groups) { this(null, viewerConfigInputStreamProvider, viewerConfigReader, cacheUpdater, groups); } private PerfettoProtoLogImpl( @Nullable String viewerConfigFilePath, @Nullable ViewerConfigInputStreamProvider viewerConfigInputStreamProvider, @Nullable ProtoLogViewerConfigReader viewerConfigReader, @NonNull Runnable cacheUpdater) { @NonNull Runnable cacheUpdater, @NonNull IProtoLogGroup[] groups) { if (viewerConfigFilePath != null && viewerConfigInputStreamProvider != null) { throw new RuntimeException("Only one of viewerConfigFilePath and " + "viewerConfigInputStreamProvider can be set"); Loading @@ -179,6 +183,8 @@ public class PerfettoProtoLogImpl extends IProtoLogClient.Stub implements IProto this.mViewerConfigReader = viewerConfigReader; this.mCacheUpdater = cacheUpdater; registerGroupsLocally(groups); if (android.tracing.Flags.clientSideProtoLogging()) { mProtoLogService = IProtoLogService.Stub.asInterface(ServiceManager.getService(PROTOLOG_SERVICE)); Loading @@ -192,6 +198,12 @@ public class PerfettoProtoLogImpl extends IProtoLogClient.Stub implements IProto args.setViewerConfigFile(viewerConfigFilePath); } final var groupArgs = Stream.of(groups) .map(group -> new ProtoLogService.RegisterClientArgs.GroupConfig( group.name(), group.isLogToLogcat())) .toArray(ProtoLogService.RegisterClientArgs.GroupConfig[]::new); args.setGroups(groupArgs); mProtoLogService.registerClient(this, args); } catch (RemoteException e) { throw new RuntimeException("Failed to register ProtoLog client"); Loading Loading @@ -294,19 +306,18 @@ public class PerfettoProtoLogImpl extends IProtoLogClient.Stub implements IProto || group.isLogToLogcat(); } @Override public void registerGroups(IProtoLogGroup... protoLogGroups) { private void registerGroupsLocally(@NonNull IProtoLogGroup[] protoLogGroups) { final var groupsLoggingToLogcat = new ArrayList<String>(); 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 (protoLogGroup.isLogToLogcat()) { groupsLoggingToLogcat.add(protoLogGroup.name()); } } if (mViewerConfigReader != null) { mViewerConfigReader.loadViewerConfig(groupsLoggingToLogcat); mViewerConfigReader.loadViewerConfig(groupsLoggingToLogcat.toArray(new String[0])); } } Loading core/java/com/android/internal/protolog/ProtoLog.java +18 −18 Original line number Diff line number Diff line Loading @@ -49,6 +49,24 @@ public class ProtoLog { private static IProtoLog sProtoLogInstance; /** * Initialize ProtoLog in this process. * <p> * This method MUST be called before any protologging is performed in this process. * Ensure that all groups that will be used for protologging are registered. * * @param groups The ProtoLog groups that will be used in the process. */ public static void init(IProtoLogGroup... groups) { if (android.tracing.Flags.perfettoProtologTracing()) { sProtoLogInstance = new PerfettoProtoLogImpl(groups); } else { // The first call to ProtoLog is likely to flip REQUIRE_PROTOLOGTOOL, which is when this // static block will be executed before REQUIRE_PROTOLOGTOOL is actually set. sProtoLogInstance = new LogcatOnlyProtoLogImpl(); } } /** * DEBUG level log. * Loading Loading @@ -150,14 +168,6 @@ public class ProtoLog { return sProtoLogInstance; } /** * Registers available protolog groups. A group must be registered before it can be used. * @param protoLogGroups The groups to register for use in protolog. */ public static void registerGroups(IProtoLogGroup... protoLogGroups) { sProtoLogInstance.registerGroups(protoLogGroups); } private static void logStringMessage(LogLevel logLevel, IProtoLogGroup group, String stringMessage, Object... args) { if (sProtoLogInstance == null) { Loading @@ -169,14 +179,4 @@ public class ProtoLog { sProtoLogInstance.log(logLevel, group, stringMessage, args); } } static { if (android.tracing.Flags.perfettoProtologTracing()) { sProtoLogInstance = new PerfettoProtoLogImpl(); } else { // The first call to ProtoLog is likely to flip REQUIRE_PROTOLOGTOOL, which is when this // static block will be executed before REQUIRE_PROTOLOGTOOL is actually set. sProtoLogInstance = new LogcatOnlyProtoLogImpl(); } } } core/java/com/android/internal/protolog/ProtoLogImpl.java +9 −14 Original line number Diff line number Diff line Loading @@ -92,36 +92,31 @@ public class ProtoLogImpl { return getSingleInstance().isEnabled(group, level); } /** * Registers available protolog groups. A group must be registered before it can be used. * @param protoLogGroups The groups to register for use in protolog. */ public static void registerGroups(IProtoLogGroup... protoLogGroups) { getSingleInstance().registerGroups(protoLogGroups); } /** * Returns the single instance of the ProtoLogImpl singleton class. */ public static synchronized IProtoLog getSingleInstance() { if (sServiceInstance == null) { final var groups = sLogGroups.values().toArray(new IProtoLogGroup[0]); 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 // In some tests the viewer config file might not exist in which we don't // want to provide config path to the user sServiceInstance = new PerfettoProtoLogImpl(sCacheUpdater); sServiceInstance = new PerfettoProtoLogImpl(sCacheUpdater, groups); } else { sServiceInstance = new PerfettoProtoLogImpl(sViewerConfigPath, sCacheUpdater); sServiceInstance = new PerfettoProtoLogImpl(sViewerConfigPath, sCacheUpdater, groups); } } else { sServiceInstance = new LegacyProtoLogImpl( var protologImpl = new LegacyProtoLogImpl( sLegacyOutputFilePath, sLegacyViewerConfigPath, sCacheUpdater); protologImpl.registerGroups(groups); sServiceInstance = protologImpl; } IProtoLogGroup[] groups = sLogGroups.values().toArray(new IProtoLogGroup[0]); sServiceInstance.registerGroups(groups); sCacheUpdater.run(); } return sServiceInstance; Loading Loading
core/java/com/android/internal/protolog/LegacyProtoLogImpl.java +0 −1 Original line number Diff line number Diff line Loading @@ -419,7 +419,6 @@ public class LegacyProtoLogImpl implements IProtoLog { return group.isLogToLogcat() || (group.isLogToProto() && isProtoEnabled()); } @Override public void registerGroups(IProtoLogGroup... protoLogGroups) { for (IProtoLogGroup group : protoLogGroups) { mLogGroups.put(group.name(), group); Loading
core/java/com/android/internal/protolog/LogcatOnlyProtoLogImpl.java +0 −5 Original line number Diff line number Diff line Loading @@ -79,9 +79,4 @@ public class LogcatOnlyProtoLogImpl implements IProtoLog { public boolean isEnabled(IProtoLogGroup group, LogLevel level) { return true; } @Override public void registerGroups(IProtoLogGroup... protoLogGroups) { // Does nothing } }
core/java/com/android/internal/protolog/PerfettoProtoLogImpl.java +28 −17 Original line number Diff line number Diff line Loading @@ -89,6 +89,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.stream.Stream; /** * A service for the ProtoLog logging system. Loading Loading @@ -125,17 +126,18 @@ public class PerfettoProtoLogImpl extends IProtoLogClient.Stub implements IProto private final Lock mBackgroundServiceLock = new ReentrantLock(); private ExecutorService mBackgroundLoggingService = Executors.newSingleThreadExecutor(); public PerfettoProtoLogImpl() { this(null, null, null, () -> {}); public PerfettoProtoLogImpl(@NonNull IProtoLogGroup[] groups) { this(null, null, null, () -> {}, groups); } public PerfettoProtoLogImpl(@NonNull Runnable cacheUpdater) { this(null, null, null, cacheUpdater); public PerfettoProtoLogImpl(@NonNull Runnable cacheUpdater, @NonNull IProtoLogGroup[] groups) { this(null, null, null, cacheUpdater, groups); } public PerfettoProtoLogImpl( @NonNull String viewerConfigFilePath, @NonNull Runnable cacheUpdater) { @NonNull Runnable cacheUpdater, @NonNull IProtoLogGroup[] groups) { this(viewerConfigFilePath, null, new ProtoLogViewerConfigReader(() -> { Loading @@ -146,22 +148,24 @@ public class PerfettoProtoLogImpl extends IProtoLogClient.Stub implements IProto "Failed to load viewer config file " + viewerConfigFilePath, e); } }), cacheUpdater); cacheUpdater, groups); } @VisibleForTesting public PerfettoProtoLogImpl( @Nullable ViewerConfigInputStreamProvider viewerConfigInputStreamProvider, @Nullable ProtoLogViewerConfigReader viewerConfigReader, @NonNull Runnable cacheUpdater) { this(null, viewerConfigInputStreamProvider, viewerConfigReader, cacheUpdater); @NonNull Runnable cacheUpdater, @NonNull IProtoLogGroup[] groups) { this(null, viewerConfigInputStreamProvider, viewerConfigReader, cacheUpdater, groups); } private PerfettoProtoLogImpl( @Nullable String viewerConfigFilePath, @Nullable ViewerConfigInputStreamProvider viewerConfigInputStreamProvider, @Nullable ProtoLogViewerConfigReader viewerConfigReader, @NonNull Runnable cacheUpdater) { @NonNull Runnable cacheUpdater, @NonNull IProtoLogGroup[] groups) { if (viewerConfigFilePath != null && viewerConfigInputStreamProvider != null) { throw new RuntimeException("Only one of viewerConfigFilePath and " + "viewerConfigInputStreamProvider can be set"); Loading @@ -179,6 +183,8 @@ public class PerfettoProtoLogImpl extends IProtoLogClient.Stub implements IProto this.mViewerConfigReader = viewerConfigReader; this.mCacheUpdater = cacheUpdater; registerGroupsLocally(groups); if (android.tracing.Flags.clientSideProtoLogging()) { mProtoLogService = IProtoLogService.Stub.asInterface(ServiceManager.getService(PROTOLOG_SERVICE)); Loading @@ -192,6 +198,12 @@ public class PerfettoProtoLogImpl extends IProtoLogClient.Stub implements IProto args.setViewerConfigFile(viewerConfigFilePath); } final var groupArgs = Stream.of(groups) .map(group -> new ProtoLogService.RegisterClientArgs.GroupConfig( group.name(), group.isLogToLogcat())) .toArray(ProtoLogService.RegisterClientArgs.GroupConfig[]::new); args.setGroups(groupArgs); mProtoLogService.registerClient(this, args); } catch (RemoteException e) { throw new RuntimeException("Failed to register ProtoLog client"); Loading Loading @@ -294,19 +306,18 @@ public class PerfettoProtoLogImpl extends IProtoLogClient.Stub implements IProto || group.isLogToLogcat(); } @Override public void registerGroups(IProtoLogGroup... protoLogGroups) { private void registerGroupsLocally(@NonNull IProtoLogGroup[] protoLogGroups) { final var groupsLoggingToLogcat = new ArrayList<String>(); 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 (protoLogGroup.isLogToLogcat()) { groupsLoggingToLogcat.add(protoLogGroup.name()); } } if (mViewerConfigReader != null) { mViewerConfigReader.loadViewerConfig(groupsLoggingToLogcat); mViewerConfigReader.loadViewerConfig(groupsLoggingToLogcat.toArray(new String[0])); } } Loading
core/java/com/android/internal/protolog/ProtoLog.java +18 −18 Original line number Diff line number Diff line Loading @@ -49,6 +49,24 @@ public class ProtoLog { private static IProtoLog sProtoLogInstance; /** * Initialize ProtoLog in this process. * <p> * This method MUST be called before any protologging is performed in this process. * Ensure that all groups that will be used for protologging are registered. * * @param groups The ProtoLog groups that will be used in the process. */ public static void init(IProtoLogGroup... groups) { if (android.tracing.Flags.perfettoProtologTracing()) { sProtoLogInstance = new PerfettoProtoLogImpl(groups); } else { // The first call to ProtoLog is likely to flip REQUIRE_PROTOLOGTOOL, which is when this // static block will be executed before REQUIRE_PROTOLOGTOOL is actually set. sProtoLogInstance = new LogcatOnlyProtoLogImpl(); } } /** * DEBUG level log. * Loading Loading @@ -150,14 +168,6 @@ public class ProtoLog { return sProtoLogInstance; } /** * Registers available protolog groups. A group must be registered before it can be used. * @param protoLogGroups The groups to register for use in protolog. */ public static void registerGroups(IProtoLogGroup... protoLogGroups) { sProtoLogInstance.registerGroups(protoLogGroups); } private static void logStringMessage(LogLevel logLevel, IProtoLogGroup group, String stringMessage, Object... args) { if (sProtoLogInstance == null) { Loading @@ -169,14 +179,4 @@ public class ProtoLog { sProtoLogInstance.log(logLevel, group, stringMessage, args); } } static { if (android.tracing.Flags.perfettoProtologTracing()) { sProtoLogInstance = new PerfettoProtoLogImpl(); } else { // The first call to ProtoLog is likely to flip REQUIRE_PROTOLOGTOOL, which is when this // static block will be executed before REQUIRE_PROTOLOGTOOL is actually set. sProtoLogInstance = new LogcatOnlyProtoLogImpl(); } } }
core/java/com/android/internal/protolog/ProtoLogImpl.java +9 −14 Original line number Diff line number Diff line Loading @@ -92,36 +92,31 @@ public class ProtoLogImpl { return getSingleInstance().isEnabled(group, level); } /** * Registers available protolog groups. A group must be registered before it can be used. * @param protoLogGroups The groups to register for use in protolog. */ public static void registerGroups(IProtoLogGroup... protoLogGroups) { getSingleInstance().registerGroups(protoLogGroups); } /** * Returns the single instance of the ProtoLogImpl singleton class. */ public static synchronized IProtoLog getSingleInstance() { if (sServiceInstance == null) { final var groups = sLogGroups.values().toArray(new IProtoLogGroup[0]); 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 // In some tests the viewer config file might not exist in which we don't // want to provide config path to the user sServiceInstance = new PerfettoProtoLogImpl(sCacheUpdater); sServiceInstance = new PerfettoProtoLogImpl(sCacheUpdater, groups); } else { sServiceInstance = new PerfettoProtoLogImpl(sViewerConfigPath, sCacheUpdater); sServiceInstance = new PerfettoProtoLogImpl(sViewerConfigPath, sCacheUpdater, groups); } } else { sServiceInstance = new LegacyProtoLogImpl( var protologImpl = new LegacyProtoLogImpl( sLegacyOutputFilePath, sLegacyViewerConfigPath, sCacheUpdater); protologImpl.registerGroups(groups); sServiceInstance = protologImpl; } IProtoLogGroup[] groups = sLogGroups.values().toArray(new IProtoLogGroup[0]); sServiceInstance.registerGroups(groups); sCacheUpdater.run(); } return sServiceInstance; Loading