blob: 24a4861c63a296a9a229da65ea5034199181f715 [file] [log] [blame] [view]
Adam Pardylfab9ad62019-08-27 02:07:16 +02001# ProtoLogTool
2
3Code transformation tool and viewer for ProtoLog.
4
5## What does it do?
6
7ProtoLogTool incorporates three different modes of operation:
8
9### Code transformation
10
Pablo Gamito329813a2024-02-13 14:27:15 +000011Command: `protologtool transform-protolog-calls
12 --protolog-class <protolog class name>
Adam Pardyl95509992019-09-27 10:09:40 +020013 --loggroups-class <protolog groups class name>
14 --loggroups-jar <config jar path>
Pablo Gamito329813a2024-02-13 14:27:15 +000015 --viewer-config-file-path <protobuf viewer config file path>
16 --legacy-viewer-config-file-path <legacy json.gz viewer config file path>
17 --legacy-output-file-path <.winscope file path to write the legacy trace to>
Adam Pardyl95509992019-09-27 10:09:40 +020018 --output-srcjar <output.srcjar>
19 [<input.java>]`
Adam Pardylfab9ad62019-08-27 02:07:16 +020020
21In this mode ProtoLogTool transforms every ProtoLog logging call in form of:
22```java
23ProtoLog.x(ProtoLogGroup.GROUP_NAME, "Format string %d %s", value1, value2);
24```
25into:
26```java
Adam Pardyl95509992019-09-27 10:09:40 +020027if (ProtoLogImpl.isEnabled(GROUP_NAME)) {
28 int protoLogParam0 = value1;
29 String protoLogParam1 = String.valueOf(value2);
30 ProtoLogImpl.x(ProtoLogGroup.GROUP_NAME, 123456, 0b0100, "Format string %d %s or null", protoLogParam0, protoLogParam1);
Adam Pardylfab9ad62019-08-27 02:07:16 +020031}
32```
33where `ProtoLog`, `ProtoLogImpl` and `ProtoLogGroup` are the classes provided as arguments
34 (can be imported, static imported or full path, wildcard imports are not allowed) and, `x` is the
35 logging method. The transformation is done on the source level. A hash is generated from the format
Adam Pardyl95509992019-09-27 10:09:40 +020036 string, log level and log group name and inserted after the `ProtoLogGroup` argument. After the hash
37 we insert a bitmask specifying the types of logged parameters. The format string is replaced
Adam Pardylfab9ad62019-08-27 02:07:16 +020038 by `null` if `ProtoLogGroup.GROUP_NAME.isLogToLogcat()` returns false. If `ProtoLogGroup.GROUP_NAME.isEnabled()`
Adam Pardyl95509992019-09-27 10:09:40 +020039 returns false the log statement is removed entirely from the resultant code. The real generated code is inlined
40 and a number of new line characters is added as to preserve line numbering in file.
Adam Pardylfab9ad62019-08-27 02:07:16 +020041
42Input is provided as a list of java source file names. Transformed source is saved to a single
43source jar file. The ProtoLogGroup class with all dependencies should be provided as a compiled
44jar file (config.jar).
45
46### Viewer config generation
47
Adam Pardyl95509992019-09-27 10:09:40 +020048Command: `generate-viewer-config
Pablo Gamito329813a2024-02-13 14:27:15 +000049 --protolog-class <protolog class name>
Adam Pardyl95509992019-09-27 10:09:40 +020050 --loggroups-class <protolog groups class name>
51 --loggroups-jar <config jar path>
Pablo Gamito329813a2024-02-13 14:27:15 +000052 --viewer-config-type <proto|json>
53 --viewer-config <viewer.json>
Adam Pardyl95509992019-09-27 10:09:40 +020054 [<input.java>]`
Adam Pardylfab9ad62019-08-27 02:07:16 +020055
56This command is similar in it's syntax to the previous one, only instead of creating a processed source jar
57it writes a viewer configuration file with following schema:
58```json
59{
60 "version": "1.0.0",
61 "messages": {
62 "123456": {
63 "message": "Format string %d %s",
64 "level": "ERROR",
Adam Pardyl95509992019-09-27 10:09:40 +020065 "group": "GROUP_NAME",
66 "at": "com\/android\/server\/example\/Class.java"
67 }
Adam Pardylfab9ad62019-08-27 02:07:16 +020068 },
69 "groups": {
70 "GROUP_NAME": {
71 "tag": "TestLog"
72 }
73 }
74}
75
76```
77
78### Binary log viewing
79
Pablo Gamito329813a2024-02-13 14:27:15 +000080Command: `read-log --viewer-config <viewer.json> <wm_log.pb>`
Adam Pardylfab9ad62019-08-27 02:07:16 +020081
82Reads the binary ProtoLog log file and outputs a human-readable LogCat-like text log.
83
84## What is ProtoLog?
85
Adam Pardyl95509992019-09-27 10:09:40 +020086ProtoLog is a generic logging system created for the WindowManager project. It allows both binary and text logging
Adam Pardylfab9ad62019-08-27 02:07:16 +020087and is tunable in runtime. It consists of 3 different submodules:
88* logging system built-in the Android app,
89* log viewer for reading binary logs,
90* a code processing tool.
91
92ProtoLog is designed to reduce both application size (and by that memory usage) and amount of resources needed
93for logging. This is achieved by replacing log message strings with their hashes and only loading to memory/writing
94full log messages when necessary.
95
96### Text logging
97
98For text-based logs Android LogCat is used as a backend. Message strings are loaded from a viewer config
99located on the device when needed.
100
101### Binary logging
102
103Binary logs are saved as Protocol Buffers file. They can be read using the ProtoLog tool or specialised
104viewer like Winscope.
105
106## How to use ProtoLog?
107
108### Adding a new logging group or log statement
109
110To add a new ProtoLogGroup simple create a new enum ProtoLogGroup member with desired parameters.
111
112To add a new logging statement just add a new call to ProtoLog.x where x is a log level.
113
Adam Pardyl95509992019-09-27 10:09:40 +0200114After doing any changes to logging groups or statements you should build the project and follow instructions printed by the tool.
Adam Pardylfab9ad62019-08-27 02:07:16 +0200115
116## How to change settings on device in runtime?
117Use the `adb shell su root cmd window logging` command. To get help just type
118`adb shell su root cmd window logging help`.
119
120
121
122