Debian Codegraph @

libs/WindowManager/Shell/src/com/android/wm/shell/docs/debugging.md

raw symbols SCIP
1 # Debugging in the Shell
2
3 ---
4
5 ## Logging & ProtoLogs
6
7 The interactions in the Shell can be pretty complicated, so having good logging is crucial to
8 debugging problems that arise (especially in dogfood). The Shell uses the same efficient Protolog
9 mechanism as WM Core, which can be enabled at runtime on debug devices.
10
11 **TLDR**  Don’t use Logs or Slogs except for error cases, Protologs are much more flexible,
12 easy to add and easy to use
13
14 ### Adding a new ProtoLog
15 Update `ShellProtoLogGroup` to include a new log group (ie. NEW_FEATURE) for the content you want to
16 log. ProtoLog log calls mirror Log.v/d/e(), and take a format message and arguments:
17 ```java
18 ProtoLog.v(NEW_FEATURE, "Test log w/ params: %d %s", 1, “a”)
19 ```
20 This code itself will not compile by itself, but the `protologtool` will preprocess the file when
21 building to check the log state (is enabled) before printing the print format style log.
22
23 **Notes**
24 - ProtoLogs currently only work from soong builds (ie. via make/mp). We need to reimplement the
25 tool for use with SysUI-studio
26 - Non-text ProtoLogs are not currently supported with the Shell library (you can't view them with
27 traces in Winscope)
28
29 ### Enabling ProtoLog command line logging
30 Run these commands to enable protologs for both WM Core and WM Shell to print to logcat.
31 ```shell
32 adb shell wm logging enable-text NEW_FEATURE
33 adb shell wm logging disable-text NEW_FEATURE
34 ```
35
36 ## Winscope Tracing
37
38 The Winscope tool is extremely useful in determining what is happening on-screen in both
39 WindowManager and SurfaceFlinger. Follow [go/winscope](http://go/winscope-help) to learn how to
40 use the tool.
41
42 In addition, there is limited preliminary support for Winscope tracing componetns in the Shell,
43 which involves adding trace fields to [wm_shell_trace.proto](frameworks/base/libs/WindowManager/Shell/proto/wm_shell_trace.proto)
44 file and ensure it is updated as a part of `WMShell#writeToProto`.
45
46 Tracing can be started via the shell command (to be added to the Winscope tool as needed):
47 ```shell
48 adb shell cmd statusbar tracing start
49 adb shell cmd statusbar tracing stop
50 ```
51
52 ## Dumps
53
54 Because the Shell library is built as a part of SystemUI, dumping the state is currently done as a
55 part of dumping the SystemUI service. Dumping the Shell specific data can be done by specifying the
56 WMShell SysUI service:
57
58 ```shell
59 adb shell dumpsys activity service SystemUIService WMShell
60 ```
61
62 If information should be added to the dump, either:
63 - Update `WMShell` if you are dumping SysUI state
64 - Inject `ShellCommandHandler` into your Shell class, and add a dump callback
65
66 ## Debugging in Android Studio
67
68 If you are using the [go/sysui-studio](http://go/sysui-studio) project, then you can debug Shell
69 code directly from Android Studio like any other app.