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

Commit 4eb502d7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I06006335,I581c8784

* changes:
  ProtoLog: Fix bug in ProtoLogImpl.isEnabled and re-enable
  ProtoLog: Cache the result of ProtoLogImpl.isEnabled(ProtoLogGroup)
parents 8b6739ce 1148054e
Loading
Loading
Loading
Loading
+1743 −0

File changed.

Preview size limit exceeded, changes collapsed.

+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ genrule {
    cmd: "$(location protologtool) transform-protolog-calls " +
      "--protolog-class com.android.server.protolog.common.ProtoLog " +
      "--protolog-impl-class com.android.server.protolog.ProtoLogImpl " +
      "--protolog-cache-class 'com.android.server.protolog.ProtoLog$$Cache' " +
      "--loggroups-class com.android.server.wm.ProtoLogGroup " +
      "--loggroups-jar $(location :services.core.wm.protologgroups) " +
      "--output-srcjar $(out) " +
+15 −3
Original line number Diff line number Diff line
@@ -45,7 +45,6 @@ import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.IllegalFormatConversionException;
import java.util.TreeMap;
import java.util.stream.Collectors;
@@ -57,8 +56,18 @@ import java.util.stream.Collectors;
public class ProtoLogImpl {
    private static final TreeMap<String, IProtoLogGroup> LOG_GROUPS = new TreeMap<>();

    /**
     * A runnable to update the cached output of {@link #isEnabled}.
     *
     * Must be invoked after every action that could change the result of {@link #isEnabled}, eg.
     * starting / stopping proto log, or enabling / disabling log groups.
     */
    static Runnable sCacheUpdater = () -> { };

    private static void addLogGroupEnum(IProtoLogGroup[] config) {
        Arrays.stream(config).forEach(group -> LOG_GROUPS.put(group.name(), group));
        for (IProtoLogGroup group : config) {
            LOG_GROUPS.put(group.name(), group);
        }
    }

    static {
@@ -112,7 +121,7 @@ public class ProtoLogImpl {

    /** Returns true iff logging is enabled for the given {@code IProtoLogGroup}. */
    public static boolean isEnabled(IProtoLogGroup group) {
        return group.isLogToProto()
        return group.isLogToLogcat()
                || (group.isLogToProto() && getSingleInstance().isProtoEnabled());
    }

@@ -303,6 +312,7 @@ public class ProtoLogImpl {
            mProtoLogEnabled = true;
            mProtoLogEnabledLockFree = true;
        }
        sCacheUpdater.run();
    }

    /**
@@ -327,6 +337,7 @@ public class ProtoLogImpl {
                throw new IllegalStateException("logging enabled while waiting for flush.");
            }
        }
        sCacheUpdater.run();
    }

    /**
@@ -351,6 +362,7 @@ public class ProtoLogImpl {
                return -1;
            }
        }
        sCacheUpdater.run();
        return 0;
    }

+1 −1
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ public enum ProtoLogGroup implements IProtoLogGroup {
    private static class Consts {
        private static final String TAG_WM = "WindowManager";

        private static final boolean ENABLE_DEBUG = false;
        private static final boolean ENABLE_DEBUG = true;
        private static final boolean ENABLE_LOG_TO_PROTO_DEBUG = true;
    }
}
+22 −4
Original line number Diff line number Diff line
@@ -44,14 +44,32 @@ public class ProtoLogIntegrationTest {
    @Test
    public void testProtoLogToolIntegration() {
        ProtoLogImpl mockedProtoLog = mock(ProtoLogImpl.class);
        ProtoLogImpl.setSingleInstance(mockedProtoLog);
        runWith(mockedProtoLog, () -> {
            ProtoLogGroup.testProtoLog();
        verify(mockedProtoLog).log(eq(ProtoLogImpl.LogLevel.ERROR), eq(
                ProtoLogGroup.TEST_GROUP),
        });
        verify(mockedProtoLog).log(eq(ProtoLogImpl.LogLevel.ERROR), eq(ProtoLogGroup.TEST_GROUP),
                anyInt(), eq(0b0010101001010111),
                eq(ProtoLogGroup.TEST_GROUP.isLogToLogcat()
                        ? "Test completed successfully: %b %d %o %x %e %g %f %% %s"
                        : null),
                eq(new Object[]{true, 1L, 2L, 3L, 0.4, 0.5, 0.6, "ok"}));
    }

    /**
     * Starts protolog for the duration of {@code runnable}, with a ProtoLogImpl instance installed.
     */
    private void runWith(ProtoLogImpl mockInstance, Runnable runnable) {
        ProtoLogImpl original = ProtoLogImpl.getSingleInstance();
        original.startProtoLog(null);
        try {
            ProtoLogImpl.setSingleInstance(mockInstance);
            try {
                runnable.run();
            } finally {
                ProtoLogImpl.setSingleInstance(original);
            }
        } finally {
            original.stopProtoLog(null, false);
        }
    }
}
Loading