Skip to content

Commit 18cdb06

Browse files
docs: rename and refresh mat-cli skill (#9)
Signed-off-by: Kai Wang <kwang@apache.org>
1 parent fab6794 commit 18cdb06

7 files changed

Lines changed: 141 additions & 112 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ brew install Demogorgon314/mat-cli/mat-cli
3434

3535
### Skills
3636

37-
If you use the skills CLI from [`vercel-labs/skills`](https://github.com/vercel-labs/skills), install the MAT heap-dump investigation skill with:
37+
If you use the skills CLI from [`vercel-labs/skills`](https://github.com/vercel-labs/skills), install the MAT CLI skill with:
3838

3939
```bash
40-
npx skills add https://github.com/Demogorgon314/mat-cli --skill mat-cli-heapdump-investigator
40+
npx skills add https://github.com/Demogorgon314/mat-cli --skill mat-cli
4141
```
4242

4343
### Release Zip

skills/mat-cli-heapdump-investigator/SKILL.md

Lines changed: 0 additions & 95 deletions
This file was deleted.

skills/mat-cli-heapdump-investigator/agents/openai.yaml

Lines changed: 0 additions & 4 deletions
This file was deleted.

skills/mat-cli/SKILL.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
name: mat-cli
3+
description: Investigate Java heap dumps with Eclipse MAT CLI. Use when Codex needs to triage `.hprof` or `.phd` dumps, find dominant retainers or exploding classes, inspect object fields or nested values, trace paths to GC roots, review heap-derived thread state, run MAT reports, or escalate to OQL for targeted heap forensics.
4+
---
5+
6+
# Heap Dump Analysis with mat-cli
7+
8+
Use `mat-cli` as the first-line tool for Java heap-dump triage. Prefer the dedicated CLI commands with stable JSON contracts, then escalate to `query` or `oql` only when a direct command cannot answer the question cleanly.
9+
10+
If `mat-cli` is unavailable, install it with `brew install demogorgon314/mat-cli/mat-cli`. Inside the MAT source tree, you can also build it from `parent/` with `mvn clean package -DskipTests -Dmat-product=mat-cli`.
11+
12+
## Quick start
13+
14+
- Confirm `mat-cli` is reachable with `mat-cli --help`.
15+
- Prefer `--format json` while reasoning, then rerun one or two focused commands with `--format text` when you need readable excerpts for the user.
16+
- Use absolute heap paths and keep every suspect object's `0x...` address in your notes.
17+
- Keep companion files beside the heap when possible. For OpenJ9 `.phd` dumps, a nearby `javacore` can improve thread analysis.
18+
- Use `--query-file` or `--command-file` for long expressions, embedded quotes, regexes, baseline paths, or inner class names containing `$`.
19+
20+
```bash
21+
mat-cli summary <heap> --format json
22+
mat-cli biggest-objects <heap> --format json --limit 20 --depth 3
23+
mat-cli objects <heap> --by class --format json --limit 30
24+
mat-cli instances <heap> --class com.example.CacheEntry --format json --limit 20
25+
mat-cli inspect-object <heap> --object 0x1234abcd --field-paths value --format json
26+
mat-cli path2gc <heap> --object 0x1234abcd --format json --depth 8 --limit 20
27+
```
28+
29+
If the leak might be thread-local, blocked, or finalizer-related, insert `mat-cli threads <heap> --format json --limit 20` right after `summary`.
30+
31+
## Command map
32+
33+
### Baseline
34+
35+
```bash
36+
mat-cli summary <heap> --format json
37+
mat-cli threads <heap> --format json --limit 20
38+
```
39+
40+
Use `summary` for heap format, object count, class count, and used heap. Use `threads` early when the leak might be thread-local, blocked, or finalizer-related. Thread output is best-effort heap metadata, not a live `jstack`.
41+
42+
### Dominators
43+
44+
```bash
45+
mat-cli biggest-objects <heap> --format json --limit 20 --depth 3
46+
mat-cli objects <heap> --by class --format json --limit 30
47+
mat-cli objects <heap> --by package --format json --limit 20
48+
mat-cli objects <heap> --by class-loader --format json --limit 20
49+
```
50+
51+
Use `biggest-objects` to find the top retained dominators. Use `objects --by class` for class growth, `objects --by package` for retained package trees, and `objects --by class-loader` for class-loader ownership. Keep `_address` values from `biggest-objects` rows for follow-up inspection.
52+
53+
### Class drilldown
54+
55+
```bash
56+
mat-cli instances <heap> --class com.example.CacheEntry --format json --limit 20
57+
mat-cli instances <heap> --class-regex 'com\\.example\\..*Cache.*' --format json --limit 20
58+
mat-cli instances <heap> --class-contains ThreadLocal --include-subclasses --format json --limit 30
59+
```
60+
61+
Use `instances` when the user names a class or when `objects --by class` points at one. Prefer `--class` for exact matches. Use regex or contains matching only when the package or suffix is uncertain. Add `--include-subclasses` only when inheritance matters.
62+
63+
### Object inspection
64+
65+
```bash
66+
mat-cli inspect-object <heap> --object 0x1234abcd --format json --depth 4 --limit 20
67+
mat-cli inspect-object <heap> --object 0x1234abcd --select-fields value --format json --limit 20
68+
mat-cli inspect-object <heap> --object 0x1234abcd --field-paths cleaner.offsetMap --format json
69+
mat-cli inspect-object <heap> --object 0x1234abcd --format text --field-paths count
70+
```
71+
72+
Use `inspect-object` when you need concrete field values from one object. Reach for `--select-fields` when direct fields are the payload, `--field-paths` for one or more nested values, and `--show-nulls` only when null references are part of the bug story. Increase `--depth` carefully; the default is intentionally conservative.
73+
74+
### Retention
75+
76+
```bash
77+
mat-cli path2gc <heap> --object 0x1234abcd --format json --depth 8 --limit 20
78+
mat-cli query <heap> --command "show_dominator_tree 0x1234abcd" --format json --limit 20 --depth 4
79+
mat-cli query <heap> --command "merge_shortest_paths -groupby FROM_GC_ROOTS com.example.CacheEntry" --format json --limit 20 --depth 4
80+
```
81+
82+
Use `path2gc` for the shortest retaining path to GC roots. Use `show_dominator_tree` when `path2gc` is too narrow and you need local dominator context. Use `merge_shortest_paths` when many leaking instances appear to flow through one shared retaining structure. If `path2gc` says the object is already a GC root, say that explicitly and pivot back to `inspect-object`, `threads`, or a dominator query.
83+
84+
### Advanced MAT queries
85+
86+
```bash
87+
mat-cli query <heap> --command "thread_overview" --format json
88+
mat-cli query <heap> --command "finalizer_thread" --format json
89+
mat-cli query <heap> --command "default_report org.eclipse.mat.api:suspects" --format json
90+
mat-cli query <heap> --command "default_report org.eclipse.mat.api:overview2 -params baseline=/abs/path/baseline.hprof" --format json
91+
mat-cli oql <heap> --query-file suspects.oql --format json --limit 20
92+
```
93+
94+
Use `query` for registered MAT reports and analyses that do not have dedicated CLI wrappers. Use `oql` only after `objects`, `biggest-objects`, `instances`, `inspect-object`, or `path2gc` stop being expressive enough. Prefer `--command-file` or `--query-file` when quoting gets awkward.
95+
96+
## Command discovery
97+
98+
```bash
99+
mat-cli describe summary --format json
100+
mat-cli describe objects --format json
101+
mat-cli schema inspect-object --format json
102+
mat-cli list-queries --format json
103+
mat-cli describe-query histogram --format json
104+
```
105+
106+
Use `describe` and `schema` before scripting against a CLI command's JSON output. Use `list-queries` and `describe-query` before reaching for less familiar MAT query ids or arguments. `histogram` is still useful as a MAT query id, but it is no longer the preferred first-line CLI command for class aggregation.
107+
108+
## Reporting rules
109+
110+
- Separate shallow heap from retained heap.
111+
- Quote exact class names and object addresses.
112+
- Treat `objects --by class` and `objects --by class-loader` retained sizes as approximate unless the command guarantees otherwise.
113+
- Tie each leak suspect to at least two pieces of evidence, such as a `biggest-objects` row, an `objects` view, a `path2gc` chain, a field value, a thread entry, or a MAT report section.
114+
- Call out uncertainty clearly when stack frames are missing or when the dump only offers best-effort thread metadata.
115+
- Prefer a short evidence chain over dumping raw JSON or huge tables back to the user.
116+
117+
## Specific tasks
118+
119+
- Ready-to-run command sequences and advanced MAT query patterns: [references/command-playbook.md](references/command-playbook.md)
120+
- Validated OQL snippets when direct commands are not enough: [references/oql-recipes.md](references/oql-recipes.md)

skills/mat-cli/agents/openai.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
interface:
2+
display_name: "MAT CLI"
3+
short_description: "Triage Java heap dumps with MAT CLI"
4+
default_prompt: "Use $mat-cli to triage this heap dump with mat-cli, isolate leak suspects, inspect retaining paths, and summarize the evidence."

skills/mat-cli-heapdump-investigator/references/command-playbook.md renamed to skills/mat-cli/references/command-playbook.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,33 @@ Use these first:
2525

2626
```bash
2727
mat-cli summary <heap> --format json
28-
mat-cli describe top-consumers --format json
28+
mat-cli describe objects --format json
2929
mat-cli schema threads --format json
3030
```
3131

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.
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/v1` envelopes, so prefer them over free-form MAT queries whenever possible.
3333

3434
## Biggest Objects and Dominators
3535

3636
Start with retained heap, not just object count:
3737

3838
```bash
39-
mat-cli top-consumers <heap> --format json --limit 20 --depth 3
40-
mat-cli histogram <heap> --format json --limit 30
39+
mat-cli biggest-objects <heap> --format json --limit 20 --depth 3
40+
mat-cli objects <heap> --by class --format json --limit 30
41+
mat-cli objects <heap> --by package --format json --limit 20
42+
mat-cli objects <heap> --by class-loader --format json --limit 20
4143
```
4244

4345
Interpret the output like this:
4446

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.
47+
- `biggest-objects` answers "what dominates retained memory right now?"
48+
- `objects --by class` answers "which classes are numerous or large in aggregate?"
49+
- `objects --by package` answers "which package tree dominates retained memory?"
50+
- `objects --by class-loader` answers "which loaders own the most retained memory and classes?"
51+
- `biggest-objects.items[]._address` is the best bridge into `inspect-object`, `path2gc`, and `show_dominator_tree`.
52+
- `objects --by class` is a table result. Look for `class`, instance count, shallow size, and retained size columns.
4953

50-
Use a smaller `--limit` when you only need the top suspects. Keep `histogram` tight enough to stay readable, then rerun with a larger limit only if the tail still looks interesting. Increase `--depth` on `top-consumers` when package aggregation matters.
54+
Use a smaller `--limit` when you only need the top suspects. Keep `objects --by class` tight enough to stay readable, then rerun with a larger limit only if the tail still looks interesting. Increase `--depth` on `biggest-objects` when you need deeper dominator levels.
5155

5256
## Class-Focused Drilldown
5357

skills/mat-cli-heapdump-investigator/references/oql-recipes.md renamed to skills/mat-cli/references/oql-recipes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MAT CLI Heapdump OQL Recipes
22

3-
Use these only after the dedicated commands fail to answer the question cleanly. For one object and one field, `inspect-object` is usually simpler and safer than OQL.
3+
Use these only after `objects`, `biggest-objects`, `instances`, and `inspect-object` fail to answer the question cleanly. For one object and one field, `inspect-object` is usually simpler and safer than OQL.
44

55
## Useful Pseudo Fields
66

@@ -11,7 +11,7 @@ MAT OQL exposes metadata fields that are useful in leak analysis:
1111
- `@retainedHeapSize`
1212
- `@name`
1313

14-
Use them to connect OQL results back to `inspect-object`, `path2gc`, or `top-consumers`.
14+
Use them to connect OQL results back to `inspect-object`, `path2gc`, or `biggest-objects`.
1515

1616
## List Objects with Address and Readable Value
1717

0 commit comments

Comments
 (0)