|
| 1 | +# MAT CLI Heapdump Command Playbook |
| 2 | + |
| 3 | +## Contents |
| 4 | + |
| 5 | +- Baseline and schemas |
| 6 | +- Biggest objects and dominators |
| 7 | +- Class-focused drilldown |
| 8 | +- Object inspection and value extraction |
| 9 | +- Retention paths and merged paths |
| 10 | +- Threads, finalizers, and reports |
| 11 | +- Comparing two dumps |
| 12 | +- Failure handling |
| 13 | + |
| 14 | +## Baseline and Schemas |
| 15 | + |
| 16 | +If `mat-cli` is missing, install it with: |
| 17 | + |
| 18 | +```bash |
| 19 | +brew install demogorgon314/mat-cli/mat-cli |
| 20 | +``` |
| 21 | + |
| 22 | +If Homebrew is unavailable and you are already inside the MAT source tree, fall back to building the standalone CLI from `parent/`. |
| 23 | + |
| 24 | +Use these first: |
| 25 | + |
| 26 | +```bash |
| 27 | +mat-cli summary <heap> --format json |
| 28 | +mat-cli describe top-consumers --format json |
| 29 | +mat-cli schema threads --format json |
| 30 | +``` |
| 31 | + |
| 32 | +Use `describe` or `schema` when you need to know the stable JSON payload before scripting against a command. The dedicated commands already return stable `mat-cli/v2` envelopes, so prefer them over free-form MAT queries whenever possible. |
| 33 | + |
| 34 | +## Biggest Objects and Dominators |
| 35 | + |
| 36 | +Start with retained heap, not just object count: |
| 37 | + |
| 38 | +```bash |
| 39 | +mat-cli top-consumers <heap> --format json --limit 20 --depth 3 |
| 40 | +mat-cli histogram <heap> --format json --limit 50 |
| 41 | +``` |
| 42 | + |
| 43 | +Interpret the output like this: |
| 44 | + |
| 45 | +- `top-consumers` answers "what dominates retained memory right now?" |
| 46 | +- `histogram` answers "which classes are numerous or large in aggregate?" |
| 47 | +- `top-consumers.biggestObjects[].objectAddress` is the best bridge into `inspect-object`, `path2gc`, and `show_dominator_tree`. |
| 48 | +- `histogram` is a table result. Look for `class_name`, instance count, shallow heap, and retained heap columns. |
| 49 | + |
| 50 | +Use a smaller `--limit` when you only need the top suspects. Increase `--depth` on `top-consumers` when package aggregation matters. |
| 51 | + |
| 52 | +## Class-Focused Drilldown |
| 53 | + |
| 54 | +Use `instances` once a class looks suspicious: |
| 55 | + |
| 56 | +```bash |
| 57 | +mat-cli instances <heap> --class com.example.CacheEntry --format json --limit 20 |
| 58 | +mat-cli instances <heap> --class-regex 'com\\.example\\..*Cache.*' --format json --limit 20 |
| 59 | +mat-cli instances <heap> --class-contains ThreadLocal --include-subclasses --format json --limit 50 |
| 60 | +``` |
| 61 | + |
| 62 | +Choose the selector deliberately: |
| 63 | + |
| 64 | +- Use `--class` for exact FQCN matches. |
| 65 | +- Use `--class-regex` for uncertain package names or multiple related classes. |
| 66 | +- Use `--class-contains` for fast discovery when the class name fragment is all you know. |
| 67 | +- Use `--include-subclasses` only when the leak might live in subtype instances. |
| 68 | + |
| 69 | +## Object Inspection and Value Extraction |
| 70 | + |
| 71 | +Use `inspect-object` for single-object truth: |
| 72 | + |
| 73 | +```bash |
| 74 | +mat-cli inspect-object <heap> --object 0x1234abcd --format json --depth 4 --limit 20 |
| 75 | +mat-cli inspect-object <heap> --object 0x1234abcd --select-field value --format json --limit 20 |
| 76 | +mat-cli inspect-object <heap> --object 0x1234abcd --field-path cleaner.offsetMap --format json |
| 77 | +mat-cli inspect-object <heap> --object 0x1234abcd --format text --field-path count |
| 78 | +``` |
| 79 | + |
| 80 | +Use it this way: |
| 81 | + |
| 82 | +- Reach for `--field-path` when the user asks for one concrete nested value. |
| 83 | +- Reach for `--select-field` when the root object is just a wrapper and one direct field is the real payload. |
| 84 | +- Watch for `_meta.value.kind` previews in JSON. MAT can surface text previews or byte-array previews without walking the whole subtree. |
| 85 | +- Use `--show-nulls` only when null references are part of the bug story. |
| 86 | + |
| 87 | +If a field path fails, fix the path instead of assuming the value is null. MAT reports missing fields explicitly. |
| 88 | + |
| 89 | +## Retention Paths and Merged Paths |
| 90 | + |
| 91 | +Use the simplest retention question first: |
| 92 | + |
| 93 | +```bash |
| 94 | +mat-cli path2gc <heap> --object 0x1234abcd --format json --depth 8 --limit 20 |
| 95 | +mat-cli query <heap> --command "show_dominator_tree 0x1234abcd" --format json --limit 20 --depth 4 |
| 96 | +mat-cli query <heap> --command "merge_shortest_paths -groupby FROM_GC_ROOTS com.example.CacheEntry" --format json --limit 20 --depth 4 |
| 97 | +``` |
| 98 | + |
| 99 | +Pick the command based on the question: |
| 100 | + |
| 101 | +- `path2gc` finds the shortest retention chain for one object. |
| 102 | +- `show_dominator_tree` shows the local dominator neighborhood for one suspect. |
| 103 | +- `merge_shortest_paths` is useful when many instances of the same class appear to leak through the same retaining structure. |
| 104 | + |
| 105 | +If `path2gc` reports that the object is already a GC root, stop searching for an upstream holder and inspect the root object's own fields, thread ownership, or role. |
| 106 | + |
| 107 | +## Threads, Finalizers, and Reports |
| 108 | + |
| 109 | +Use dedicated thread support first: |
| 110 | + |
| 111 | +```bash |
| 112 | +mat-cli threads <heap> --format json --limit 50 |
| 113 | +mat-cli query <heap> --command "thread_overview" --format json |
| 114 | +mat-cli query <heap> --command "finalizer_thread" --format json |
| 115 | +mat-cli query <heap> --command "finalizer_thread_locals" --format json |
| 116 | +``` |
| 117 | + |
| 118 | +Use MAT reports when you need a broader narrative: |
| 119 | + |
| 120 | +```bash |
| 121 | +mat-cli query <heap> --command "default_report org.eclipse.mat.api:overview" --format json |
| 122 | +mat-cli query <heap> --command "default_report org.eclipse.mat.api:suspects" --format json |
| 123 | +mat-cli query <heap> --command "default_report org.eclipse.mat.api:top_components" --format json |
| 124 | +``` |
| 125 | + |
| 126 | +Remember: |
| 127 | + |
| 128 | +- `threads` and `thread_overview` are best-effort views of heap data, not a runtime thread dump. |
| 129 | +- `default_report` commands often return section-style results. Summarize the important sections instead of replaying the full structure. |
| 130 | +- Use `list-queries` and `describe-query` before calling obscure MAT query ids. |
| 131 | + |
| 132 | +## Comparing Two Dumps |
| 133 | + |
| 134 | +When you have a baseline and a current dump from comparable workloads, use MAT's compare reports: |
| 135 | + |
| 136 | +```bash |
| 137 | +mat-cli query <new-heap> --command "default_report org.eclipse.mat.api:overview2 -params baseline=/abs/path/baseline.hprof" --format json |
| 138 | +mat-cli query <new-heap> --command "default_report org.eclipse.mat.api:suspects2 -params baseline=/abs/path/baseline.hprof" --format json |
| 139 | +``` |
| 140 | + |
| 141 | +Prefer `--command-file` if the baseline path contains spaces or the command grows longer. |
| 142 | + |
| 143 | +## Failure Handling |
| 144 | + |
| 145 | +Use these recovery moves: |
| 146 | + |
| 147 | +- `Unknown MAT query`: run `mat-cli list-queries --format json` and `mat-cli describe-query <id> --format json`. |
| 148 | +- OQL syntax problems: move the expression into a UTF-8 file and use `--query-file`. |
| 149 | +- MAT query syntax problems: move the command into a UTF-8 file and use `--command-file`. |
| 150 | +- Invalid `path2gc` address: verify the address with `mat-cli oql <heap> --query "SELECT * FROM OBJECTS 0x1234abcd" --format json`. |
| 151 | +- Too much data: lower `--limit`, lower `--depth`, or pivot from `query` to a dedicated command. |
0 commit comments