Skip to main content
The tree command displays a call tree starting from a method and descending to its callees. Use it to understand what a method calls and where time is spent downstream.

Usage

ap-query tree <file> [flags]

What It Shows

A hierarchical, indented tree showing:
  • The root method (or all roots if no method specified)
  • What it calls (children)
  • What those call (grandchildren)
  • Continuing to specified depth
Each node shows:
  • Total percentage (samples containing this node)
  • Self percentage (samples where this is the leaf)
  • Method name

Flags

-m, --method
string
Substring match on method name. If specified, tree starts from matching method(s). If omitted, shows full profile tree from all roots.
--depth
int
default:"4"
Maximum depth of the tree. Controls how many levels of callees to show.
--min-pct
float
default:"1.0"
Hide nodes below this percentage threshold. Reduces noise from uncommon paths.
--hide
regex
Remove frames matching this regex before analysis. Useful for collapsing uninteresting intermediate frames.Example: --hide "java\.util\..*" removes all java.util frames.

Shared Flags

-e, --event
string
default:"cpu"
Event type: cpu, wall, alloc, lock, or hardware counter name.
-t, --thread
string
Filter to threads containing this substring.
--from
duration
Start of time window (JFR only).
--to
duration
End of time window (JFR only).
--no-idle
boolean
Remove idle leaf frames from analysis.

Examples

Basic Tree from Method

ap-query tree profile.jfr -m HashMap.put
HashMap.put (total=18.4%, self=1.8%)
  HashMap.putVal (16.2%, self=3.4%)
    HashMap.resize (8.9%, self=3.1%)
      Arrays.copyOf (4.2%, self=2.3%)
      HashMap.newNode (1.4%, self=1.2%)
    HashMap.hash (3.2%, self=3.2%)
    HashMap.afterNodeInsertion (1.1%, self=1.1%)
total=X% means X% of all samples pass through this method. self=Y% means Y% of samples have this as the leaf frame.

Full Profile Tree

ap-query tree profile.jfr
Shows the complete call tree starting from all entry points (main, thread start methods, etc.).

Deeper Tree

ap-query tree profile.jfr -m HashMap.put --depth 8
Show 8 levels of callees instead of the default 4.

Hide Low-Percentage Nodes

ap-query tree profile.jfr -m processRequest --min-pct 2.0
Only show nodes consuming ≥ 2% of samples.

Remove Framework Frames

ap-query tree profile.jfr -m UserService --hide "org\.springframework\..*"
Collapse all Spring framework frames to focus on application code.

Combined Filters

ap-query tree profile.jfr -m processRequest --depth 6 --min-pct 1.5 --thread worker
Show 6 levels, hide nodes < 1.5%, only analyze worker threads.

Reading the Output

Indentation shows call hierarchy:
A (40%, self=5%)
  B (25%, self=10%)
    C (12%, self=12%)
    D (3%, self=3%)
  E (10%, self=10%)
  • A calls B and E
  • B calls C and D
  • 40% of samples contain A
  • 5% of samples have A as the leaf (A doing work)
  • 25% of samples pass through B (called by A)
  • 10% of samples have B as the leaf
When total% is much higher than self%, the method delegates most work to callees. When they’re similar, the method does the work itself.

Multiple Matches

If -m matches multiple methods, the tree shows all matches:
ap-query tree profile.jfr -m hash
# matched 3 methods: HashMap.hash, String.hashCode, HashSet.hash

HashMap.hash (total=12.1%, self=8.3%)
  ...

String.hashCode (total=8.9%, self=5.1%)
  ...

HashSet.hash (total=2.3%, self=1.8%)
  ...

When to Use

Understanding Hot Methods

After finding a hot method with hot, use tree to see what it calls

Identifying Expensive Callees

Discover which downstream methods consume the most time

Algorithm Analysis

Understand the execution flow and call patterns

Finding Hidden Costs

Spot expensive operations buried in call chains

Tree vs Trace vs Callers

CommandDirectionShowsUse Case
treeDescendingAll calleesWhat does this call?
traceDescendingHottest path onlyCritical path analysis
callersAscendingWho calls thisWhy is this called?

See Also

  • trace - Follow the single hottest path from method to leaf
  • callers - See who calls a method
  • hot - Find methods to investigate with tree

Build docs developers (and LLMs) love