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

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

Merge "ProtoLog improvements"

parents db41b792 a4e572d9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ option java_multiple_files = true;
/* represents a single log entry */
message ProtoLogMessage {
    /* log statement identifier, created from message string and log level. */
    optional fixed32 message_hash = 1;
    optional sfixed32 message_hash = 1;
    /* log time, relative to the elapsed system time clock. */
    optional fixed64 elapsed_realtime_nanos = 2;
    /* string parameters passed to the log call. */
+3 −2
Original line number Diff line number Diff line
{
  "version": "1.0.0",
  "messages": {
    "485522692": {
    "594230385": {
      "message": "Test completed successfully: %b %d %o %x %e %g %f %% %s.",
      "level": "ERROR",
      "group": "TEST_GROUP"
      "group": "TEST_GROUP",
      "at": "com\/android\/server\/wm\/ProtoLogGroup.java:94"
    }
  },
  "groups": {
+47 −39
Original line number Diff line number Diff line
@@ -110,6 +110,12 @@ public class ProtoLogImpl {
        getSingleInstance().log(LogLevel.WTF, group, messageHash, paramsMask, messageString, args);
    }

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

    private static final int BUFFER_CAPACITY = 1024 * 1024;
    private static final String LOG_FILENAME = "/data/misc/wmtrace/wm_log.pb";
    private static final String VIEWER_CONFIG_FILENAME = "/system/etc/protolog.conf.json.gz";
@@ -222,6 +228,7 @@ public class ProtoLogImpl {
            os.write(MESSAGE_HASH, messageHash);
            os.write(ELAPSED_REALTIME_NANOS, SystemClock.elapsedRealtimeNanos());

            if (args != null) {
                int argIndex = 0;
                ArrayList<Long> longParams = new ArrayList<>();
                ArrayList<Double> doubleParams = new ArrayList<>();
@@ -265,6 +272,7 @@ public class ProtoLogImpl {
                    }
                    os.writePackedBool(BOOLEAN_PARAMS, arr);
                }
            }
            os.end(token);
            mBuffer.add(os);
        } catch (Exception e) {
+2 −2
Original line number Diff line number Diff line
@@ -351,7 +351,7 @@ public class ProtoLogImplTest {
            ProtoLogData data = readProtoLogSingle(ip);
            assertNotNull(data);
            assertEquals(1234, data.mMessageHash.longValue());
            assertTrue(before < data.mElapsedTime && data.mElapsedTime < after);
            assertTrue(before <= data.mElapsedTime && data.mElapsedTime <= after);
            assertArrayEquals(new String[]{"test"}, data.mStrParams.toArray());
            assertArrayEquals(new Long[]{1L, 2L, 3L}, data.mSint64Params.toArray());
            assertArrayEquals(new Double[]{0.4, 0.5, 0.6}, data.mDoubleParams.toArray());
@@ -376,7 +376,7 @@ public class ProtoLogImplTest {
            ProtoLogData data = readProtoLogSingle(ip);
            assertNotNull(data);
            assertEquals(1234, data.mMessageHash.longValue());
            assertTrue(before < data.mElapsedTime && data.mElapsedTime < after);
            assertTrue(before <= data.mElapsedTime && data.mElapsedTime <= after);
            assertArrayEquals(new String[]{"test", "(INVALID PARAMS_MASK) true"},
                    data.mStrParams.toArray());
            assertArrayEquals(new Long[]{1L}, data.mSint64Params.toArray());
+11 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.ImportDeclaration
import com.github.javaparser.ast.expr.BinaryExpr
import com.github.javaparser.ast.expr.Expression
import com.github.javaparser.ast.expr.MethodCallExpr
import com.github.javaparser.ast.expr.StringLiteralExpr

object CodeUtils {
@@ -27,8 +28,9 @@ object CodeUtils {
     * Returns a stable hash of a string.
     * We reimplement String::hashCode() for readability reasons.
     */
    fun hash(str: String, level: LogLevel): Int {
        return (level.name + str).map { c -> c.toInt() }.reduce { h, c -> h * 31 + c }
    fun hash(position: String, messageString: String, logLevel: LogLevel, logGroup: LogGroup): Int {
        return (position + messageString + logLevel.name + logGroup.name)
                .map { c -> c.toInt() }.reduce { h, c -> h * 31 + c }
    }

    fun isWildcardStaticImported(code: CompilationUnit, className: String): Boolean {
@@ -71,4 +73,11 @@ object CodeUtils {
                    "or concatenation of string literals.", expr)
        }
    }

    fun getPositionString(call: MethodCallExpr, fileName: String): String {
        return when {
            call.range.isPresent -> "$fileName:${call.range.get().begin.line}"
            else -> fileName
        }
    }
}
Loading