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

Commit 329813a9 authored by Pablo Gamito's avatar Pablo Gamito
Browse files

Update ProtoLogTool commands args

We need these new parameters to inject those values into the generated classes so we don't have to manually create an impl of these class and passing those values manually.

Flag: ACONFIG android.tracing.Flags.perfettoProtolog DEVELOPMENT
Bug: 276432490
Test: atest FrameworksServicesTests
Change-Id: I32906cbe37c7c3899d7c487d5ed341381a05fdf1
parent 01e08016
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -42,5 +42,6 @@ java_test_host {
        "junit",
        "mockito",
        "objenesis",
        "truth",
    ],
}
+9 −6
Original line number Diff line number Diff line
@@ -10,9 +10,11 @@ ProtoLogTool incorporates three different modes of operation:

Command: `protologtool transform-protolog-calls
    --protolog-class <protolog class name>
    --protolog-impl-class <protolog implementation class name>
    --loggroups-class <protolog groups class name>
    --loggroups-jar <config jar path>
    --viewer-config-file-path <protobuf viewer config file path>
    --legacy-viewer-config-file-path <legacy json.gz viewer config file path>
    --legacy-output-file-path <.winscope file path to write the legacy trace to>
    --output-srcjar <output.srcjar>
    [<input.java>]`

@@ -47,7 +49,8 @@ Command: `generate-viewer-config
    --protolog-class <protolog class name>
    --loggroups-class <protolog groups class name>
    --loggroups-jar <config jar path>
    --viewer-conf <viewer.json>
    --viewer-config-type <proto|json>
    --viewer-config <viewer.json>
    [<input.java>]`

This command is similar in it's syntax to the previous one, only instead of creating a processed source jar
@@ -74,7 +77,7 @@ it writes a viewer configuration file with following schema:

### Binary log viewing

Command: `read-log --viewer-conf <viewer.json> <wm_log.pb>`
Command: `read-log --viewer-config <viewer.json> <wm_log.pb>`

Reads the binary ProtoLog log file and outputs a human-readable LogCat-like text log.

+100 −37
Original line number Diff line number Diff line
@@ -26,32 +26,35 @@ class CommandOptions(args: Array<String>) {
        private val commands = setOf(TRANSFORM_CALLS_CMD, GENERATE_CONFIG_CMD, READ_LOG_CMD)

        private const val PROTOLOG_CLASS_PARAM = "--protolog-class"
        private const val PROTOLOGIMPL_CLASS_PARAM = "--protolog-impl-class"
        private const val PROTOLOGCACHE_CLASS_PARAM = "--protolog-cache-class"
        private const val PROTOLOGGROUP_CLASS_PARAM = "--loggroups-class"
        private const val PROTOLOGGROUP_JAR_PARAM = "--loggroups-jar"
        private const val VIEWER_CONFIG_JSON_PARAM = "--viewer-conf"
        private const val VIEWER_CONFIG_PARAM = "--viewer-config"
        private const val VIEWER_CONFIG_TYPE_PARAM = "--viewer-config-type"
        private const val OUTPUT_SOURCE_JAR_PARAM = "--output-srcjar"
        private val parameters = setOf(PROTOLOG_CLASS_PARAM, PROTOLOGIMPL_CLASS_PARAM,
                PROTOLOGCACHE_CLASS_PARAM, PROTOLOGGROUP_CLASS_PARAM, PROTOLOGGROUP_JAR_PARAM,
                VIEWER_CONFIG_JSON_PARAM, OUTPUT_SOURCE_JAR_PARAM)
        private const val VIEWER_CONFIG_FILE_PATH_PARAM = "--viewer-config-file-path"
        // TODO(b/324128613): Remove these legacy options once we fully flip the Perfetto protolog flag
        private const val LEGACY_VIEWER_CONFIG_FILE_PATH_PARAM = "--legacy-viewer-config-file-path"
        private const val LEGACY_OUTPUT_FILE_PATH = "--legacy-output-file-path"
        private val parameters = setOf(PROTOLOG_CLASS_PARAM, PROTOLOGGROUP_CLASS_PARAM,
            PROTOLOGGROUP_JAR_PARAM, VIEWER_CONFIG_PARAM, VIEWER_CONFIG_TYPE_PARAM,
            OUTPUT_SOURCE_JAR_PARAM, VIEWER_CONFIG_FILE_PATH_PARAM,
            LEGACY_VIEWER_CONFIG_FILE_PATH_PARAM, LEGACY_OUTPUT_FILE_PATH)

        val USAGE = """
            Usage: ${Constants.NAME} <command> [<args>]
            Available commands:

            $TRANSFORM_CALLS_CMD $PROTOLOG_CLASS_PARAM <class name> $PROTOLOGIMPL_CLASS_PARAM
                <class name> $PROTOLOGCACHE_CLASS_PARAM
                <class name> $PROTOLOGGROUP_CLASS_PARAM <class name> $PROTOLOGGROUP_JAR_PARAM
                <config.jar> $OUTPUT_SOURCE_JAR_PARAM <output.srcjar> [<input.java>]
            $TRANSFORM_CALLS_CMD $PROTOLOG_CLASS_PARAM <class name>
                $PROTOLOGGROUP_CLASS_PARAM <class name> $PROTOLOGGROUP_JAR_PARAM <config.jar>
                $OUTPUT_SOURCE_JAR_PARAM <output.srcjar> [<input.java>]
            - processes java files replacing stub calls with logging code.

            $GENERATE_CONFIG_CMD $PROTOLOG_CLASS_PARAM <class name> $PROTOLOGGROUP_CLASS_PARAM
                <class name> $PROTOLOGGROUP_JAR_PARAM <config.jar> $VIEWER_CONFIG_JSON_PARAM
                <viewer.json> [<input.java>]
            $GENERATE_CONFIG_CMD $PROTOLOG_CLASS_PARAM <class name>
                $PROTOLOGGROUP_CLASS_PARAM <class name> $PROTOLOGGROUP_JAR_PARAM <config.jar>
                $VIEWER_CONFIG_PARAM <viewer.json|viewer.pb> [<input.java>]
            - creates viewer config file from given java files.

            $READ_LOG_CMD $VIEWER_CONFIG_JSON_PARAM <viewer.json> <wm_log.pb>
            $READ_LOG_CMD $VIEWER_CONFIG_PARAM <viewer.json|viewer.pb> <wm_log.pb>
            - translates a binary log to a readable format.
        """.trimIndent()

@@ -69,6 +72,13 @@ class CommandOptions(args: Array<String>) {
            return params.getValue(paramName)
        }

        private fun getOptionalParam(paramName: String, params: Map<String, String>): String? {
            if (!params.containsKey(paramName)) {
                return null
            }
            return params.getValue(paramName)
        }

        private fun validateNotSpecified(paramName: String, params: Map<String, String>): String {
            if (params.containsKey(paramName)) {
                throw InvalidCommandException("Unsupported param $paramName")
@@ -90,9 +100,43 @@ class CommandOptions(args: Array<String>) {
            return name
        }

        private fun validateJSONName(name: String): String {
            if (!name.endsWith(".json")) {
                throw InvalidCommandException("Json file required, got $name instead")
        private fun validateViewerConfigFilePath(name: String): String {
            if (!name.endsWith(".pb")) {
                throw InvalidCommandException("Proto file (ending with .pb) required, " +
                        "got $name instead")
            }
            return name
        }

        private fun validateLegacyViewerConfigFilePath(name: String): String {
            if (!name.endsWith(".json.gz")) {
                throw InvalidCommandException("GZiped Json file (ending with .json.gz) required, " +
                        "got $name instead")
            }
            return name
        }

        private fun validateOutputFilePath(name: String): String {
            if (!name.endsWith(".winscope")) {
                throw InvalidCommandException("Winscope file (ending with .winscope) required, " +
                        "got $name instead")
            }
            return name
        }

        private fun validateConfigFileName(name: String): String {
            if (!name.endsWith(".json") && !name.endsWith(".pb")) {
                throw InvalidCommandException("Json file (ending with .json) or proto file " +
                        "(ending with .pb) required, got $name instead")
            }
            return name
        }

        private fun validateConfigType(name: String): String {
            val validType = listOf("json", "proto")
            if (!validType.contains(name)) {
                throw InvalidCommandException("Unexpected config file type. " +
                        "Expected on of [${validType.joinToString()}], but got $name")
            }
            return name
        }
@@ -102,8 +146,8 @@ class CommandOptions(args: Array<String>) {
                throw InvalidCommandException("No java source input files")
            }
            list.forEach { name ->
                if (!name.endsWith(".java")) {
                    throw InvalidCommandException("Not a java source file $name")
                if (!name.endsWith(".java") && !name.endsWith(".kt")) {
                    throw InvalidCommandException("Not a java or kotlin source file $name")
                }
            }
            return list
@@ -122,12 +166,14 @@ class CommandOptions(args: Array<String>) {

    val protoLogClassNameArg: String
    val protoLogGroupsClassNameArg: String
    val protoLogImplClassNameArg: String
    val protoLogCacheClassNameArg: String
    val protoLogGroupsJarArg: String
    val viewerConfigJsonArg: String
    val viewerConfigFileNameArg: String
    val viewerConfigTypeArg: String
    val outputSourceJarArg: String
    val logProtofileArg: String
    val viewerConfigFilePathArg: String
    val legacyViewerConfigFilePathArg: String?
    val legacyOutputFilePath: String?
    val javaSourceArgs: List<String>
    val command: String

@@ -169,38 +215,55 @@ class CommandOptions(args: Array<String>) {
        when (command) {
            TRANSFORM_CALLS_CMD -> {
                protoLogClassNameArg = validateClassName(getParam(PROTOLOG_CLASS_PARAM, params))
                protoLogGroupsClassNameArg = validateClassName(getParam(PROTOLOGGROUP_CLASS_PARAM,
                        params))
                protoLogImplClassNameArg = validateClassName(getParam(PROTOLOGIMPL_CLASS_PARAM,
                        params))
                protoLogCacheClassNameArg = validateClassName(getParam(PROTOLOGCACHE_CLASS_PARAM,
                        params))
                protoLogGroupsClassNameArg =
                    validateClassName(getParam(PROTOLOGGROUP_CLASS_PARAM, params))
                protoLogGroupsJarArg = validateJarName(getParam(PROTOLOGGROUP_JAR_PARAM, params))
                viewerConfigJsonArg = validateNotSpecified(VIEWER_CONFIG_JSON_PARAM, params)
                viewerConfigFileNameArg = validateNotSpecified(VIEWER_CONFIG_PARAM, params)
                viewerConfigTypeArg = validateNotSpecified(VIEWER_CONFIG_TYPE_PARAM, params)
                outputSourceJarArg = validateSrcJarName(getParam(OUTPUT_SOURCE_JAR_PARAM, params))
                viewerConfigFilePathArg = validateViewerConfigFilePath(
                    getParam(VIEWER_CONFIG_FILE_PATH_PARAM, params))
                legacyViewerConfigFilePathArg =
                    getOptionalParam(LEGACY_VIEWER_CONFIG_FILE_PATH_PARAM, params)?.let {
                        validateLegacyViewerConfigFilePath(it)
                    }
                legacyOutputFilePath =
                    getOptionalParam(LEGACY_OUTPUT_FILE_PATH, params)?.let {
                        validateOutputFilePath(it)
                    }
                javaSourceArgs = validateJavaInputList(inputFiles)
                logProtofileArg = ""
            }
            GENERATE_CONFIG_CMD -> {
                protoLogClassNameArg = validateClassName(getParam(PROTOLOG_CLASS_PARAM, params))
                protoLogGroupsClassNameArg = validateClassName(getParam(PROTOLOGGROUP_CLASS_PARAM,
                        params))
                protoLogImplClassNameArg = validateNotSpecified(PROTOLOGIMPL_CLASS_PARAM, params)
                protoLogCacheClassNameArg = validateNotSpecified(PROTOLOGCACHE_CLASS_PARAM, params)
                protoLogGroupsClassNameArg =
                    validateClassName(getParam(PROTOLOGGROUP_CLASS_PARAM, params))
                protoLogGroupsJarArg = validateJarName(getParam(PROTOLOGGROUP_JAR_PARAM, params))
                viewerConfigJsonArg = validateJSONName(getParam(VIEWER_CONFIG_JSON_PARAM, params))
                viewerConfigFileNameArg =
                    validateConfigFileName(getParam(VIEWER_CONFIG_PARAM, params))
                viewerConfigTypeArg = validateConfigType(getParam(VIEWER_CONFIG_TYPE_PARAM, params))
                outputSourceJarArg = validateNotSpecified(OUTPUT_SOURCE_JAR_PARAM, params)
                viewerConfigFilePathArg =
                    validateNotSpecified(VIEWER_CONFIG_FILE_PATH_PARAM, params)
                legacyViewerConfigFilePathArg =
                    validateNotSpecified(LEGACY_VIEWER_CONFIG_FILE_PATH_PARAM, params)
                legacyOutputFilePath = validateNotSpecified(LEGACY_OUTPUT_FILE_PATH, params)
                javaSourceArgs = validateJavaInputList(inputFiles)
                logProtofileArg = ""
            }
            READ_LOG_CMD -> {
                protoLogClassNameArg = validateNotSpecified(PROTOLOG_CLASS_PARAM, params)
                protoLogGroupsClassNameArg = validateNotSpecified(PROTOLOGGROUP_CLASS_PARAM, params)
                protoLogImplClassNameArg = validateNotSpecified(PROTOLOGIMPL_CLASS_PARAM, params)
                protoLogCacheClassNameArg = validateNotSpecified(PROTOLOGCACHE_CLASS_PARAM, params)
                protoLogGroupsJarArg = validateNotSpecified(PROTOLOGGROUP_JAR_PARAM, params)
                viewerConfigJsonArg = validateJSONName(getParam(VIEWER_CONFIG_JSON_PARAM, params))
                viewerConfigFileNameArg =
                    validateConfigFileName(getParam(VIEWER_CONFIG_PARAM, params))
                viewerConfigTypeArg = validateNotSpecified(VIEWER_CONFIG_TYPE_PARAM, params)
                outputSourceJarArg = validateNotSpecified(OUTPUT_SOURCE_JAR_PARAM, params)
                viewerConfigFilePathArg =
                    validateNotSpecified(VIEWER_CONFIG_FILE_PATH_PARAM, params)
                legacyViewerConfigFilePathArg =
                    validateNotSpecified(LEGACY_VIEWER_CONFIG_FILE_PATH_PARAM, params)
                legacyOutputFilePath = validateNotSpecified(LEGACY_OUTPUT_FILE_PATH, params)
                javaSourceArgs = listOf()
                logProtofileArg = validateLogInputList(inputFiles)
            }
+225 −113

File changed.

Preview size limit exceeded, changes collapsed.

+6 −7
Original line number Diff line number Diff line
@@ -16,15 +16,15 @@

package com.android.protolog.tool

import org.junit.Assert
import org.junit.Assert.assertTrue
import org.junit.Test
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.FileNotFoundException
import java.io.OutputStream
import java.util.jar.JarInputStream
import org.junit.Assert
import org.junit.Assert.assertTrue
import org.junit.Test

class EndToEndTest {

@@ -47,11 +47,9 @@ class EndToEndTest {
                logGroup = LogGroup("GROUP", true, false, "TAG_GROUP"),
                commandOptions = CommandOptions(arrayOf("transform-protolog-calls",
                        "--protolog-class", "com.android.internal.protolog.common.ProtoLog",
                        "--protolog-impl-class", "com.android.internal.protolog.ProtoLogImpl",
                        "--protolog-cache-class",
                        "com.android.server.wm.ProtoLogCache",
                        "--loggroups-class", "com.android.internal.protolog.ProtoLogGroup",
                        "--loggroups-jar", "not_required.jar",
                        "--viewer-config-file-path", "not_required.pb",
                        "--output-srcjar", "out.srcjar",
                        "frameworks/base/org/example/Example.java"))
        )
@@ -80,7 +78,8 @@ class EndToEndTest {
                        "--protolog-class", "com.android.internal.protolog.common.ProtoLog",
                        "--loggroups-class", "com.android.internal.protolog.ProtoLogGroup",
                        "--loggroups-jar", "not_required.jar",
                        "--viewer-conf", "out.json",
                        "--viewer-config-type", "json",
                        "--viewer-config", "out.json",
                        "frameworks/base/org/example/Example.java"))
        )
        val viewerConfigJson = assertLoadText(output, "out.json")