CLI for exploring Java heap dumps with the VisualVM JFluid heap library.
The preferred way to build and use this tool is as a GraalVM native executable, because heap-dump analysis is often run as a short-lived CLI command and native-image gives much faster startup time.
Build the native executable with the Maven native profile:
mvn -Pnative packageNative artifact:
target/heap-cli
Run it directly:
target/heap-cli helpA regular jar build is still available:
mvn packageJar artifacts:
target/heap-cli-1.0.jartarget/heap-cli-1.0-jar-with-dependencies.jar
Runnable jar:
java -jar target/heap-cli-1.0-jar-with-dependencies.jar helpPreferred executable form:
heap-cli <heap-dump.hprof> types [--filter <text>] [start] [count]
heap-cli <heap-dump.hprof> types-retained [--filter <text>] [start] [count]
heap-cli <heap-dump.hprof> compare <heap-dump2.hprof> [type]
heap-cli <heap-dump.hprof> biggest [start] [count]
heap-cli <heap-dump.hprof> instances <type> [start] [count]
heap-cli <heap-dump.hprof> inspect <instance-id>
heap-cli <heap-dump.hprof> refs-in <instance-id> [start] [count]
heap-cli <heap-dump.hprof> refs-out <instance-id> [start] [count]
heap-cli <heap-dump.hprof> gcroot <instance-id>
heap-cli <heap-dump.hprof> gcroots <instance-id> [count]
Alternative form:
heap-cli --heap <heap-dump.hprof> <command> ...
If you are using the jar build, the same commands can be run via:
java -jar target/heap-cli-1.0-jar-with-dependencies.jar <heap-dump.hprof> <command> ...Defaults:
start = 0count = 20gcroots count = 5
Prints Java types ordered by instance count.
Columns:
NAMECOUNTSIZE(human-readable)TOTAL_SIZE(human-readable)
Prints Java types ordered by retained size.
Columns:
NAMECOUNTSIZETOTAL_SIZERETAINED_SIZE
Compares per-type instance counts in the second heap dump against the first heap dump.
Without type, it prints only changed types: up to the 20 largest increases followed by up to the 20 largest decreases. Positive bars grow to the right of |; negative bars grow to the left.
Example output:
com.example.NewEntry +120 |####################
com.example.OtherGrowth +48 |########
com.example.RemovedEntry -17 ###|
With a fully qualified Java type name, it prints just that type and the signed difference:
heap-cli before.hprof compare after.hprof com.example.CacheEntrycom.example.CacheEntry +42
Prints biggest objects by retained size.
Columns:
INSTANCE_IDCLASSSIZERETAINED_SIZE
Prints instances of a given type.
Columns:
INSTANCE_IDSIZERETAINED_SIZE
Prints detailed information about one instance, including:
- class
- shallow size
- retained size
- nearest GC root pointer
- incoming/outgoing reference counts
- fields or array preview
Prints referrers of an instance.
Columns:
REFERRER_IDREFERRER_CLASSVIASIZERETAINED_SIZE
Prints outgoing object references from an instance.
Columns:
TARGET_IDTARGET_CLASSVIASIZERETAINED_SIZE
Prints the shortest GC root path in the same style as GCUtils.HeapDumpAnalyser.
Prints several shortest GC root paths, useful when one shortest path is not enough to explain retention.
Preferred native executable:
target/heap-cli mydump.hprof types --filter String 0 20
target/heap-cli mydump.hprof types-retained --filter cache 0 20
target/heap-cli before.hprof compare after.hprof
target/heap-cli before.hprof compare after.hprof com.example.CacheEntry
target/heap-cli mydump.hprof biggest 0 20
target/heap-cli mydump.hprof inspect 12345678
target/heap-cli mydump.hprof refs-in 12345678 0 20
target/heap-cli mydump.hprof refs-out 12345678 0 20
target/heap-cli mydump.hprof gcroot 12345678
target/heap-cli mydump.hprof gcroots 12345678 5Jar fallback:
java -jar target/heap-cli-1.0-jar-with-dependencies.jar mydump.hprof types --filter String 0 20A practical manual workflow is usually:
- If you have before/after dumps,
compareto find types whose instance counts changed. types-retainedto find suspicious classes.biggestto find dominating individual objects.instances <type>to drill into a suspect type.inspect <id>to understand object contents.refs-in <id>andrefs-out <id>to explain retention.gcrootorgcrootsto identify the retaining root path.
This repository includes a project-local skill file:
SKILL.md
To install it into your global pi skills directory, copy it to:
~/.pi/agent/skills/pi-skills/heap-cli/SKILL.md
Example:
mkdir -p ~/.pi/agent/skills/pi-skills/heap-cli
cp SKILL.md ~/.pi/agent/skills/pi-skills/heap-cli/SKILL.mdAfter copying it, you can reference the skill from your pi agent setup like any other skill.
Run:
mvn testThe smoke test creates a temporary heap dump and exercises the main analysis commands.