trace command follows the single hottest path from a method down to the leaf frame. It answers “what is the most expensive thing this method does?”
Usage
What It Shows
Starting from your specified method,trace follows the hottest child at each level until reaching a leaf. At each step it shows:
- Percentage of samples passing through this frame
- Method name
- Sibling annotation (showing alternate paths not taken)
- Self-time annotation at the leaf
Flags
Substring match on method name (required). The starting point for the trace.
Hide nodes below this percentage threshold. Stops the trace early if percentage drops too low.
Show fully-qualified names (full package paths) instead of short names.
Remove frames matching this regex before analysis. Useful for collapsing uninteresting intermediate frames.
Shared Flags
Event type:
cpu, wall, alloc, lock, or hardware counter name.Filter to threads containing this substring.
Start of time window (JFR only).
End of time window (JFR only).
Remove idle leaf frames from analysis.
Examples
Basic Trace
- 18.4% of samples contain
HashMap.put - The hottest path goes through
HashMap.putVal(16.2%) - Then through
HashMap.resize(8.9%) - Then
Arrays.copyOf(4.2%) - Finally reaches
System.arraycopy(2.3% self-time) - At each step, shows alternative paths not taken
Show Alternate Paths
The sibling annotations tell you what else happens:- We followed the 16.2% path through
HashMap.putVal - There are 2 other siblings (alternate paths from the parent)
- The next-hottest sibling is
HashMap.hashat 1.8%
Fully-Qualified Names
Lower Percentage Threshold
Remove Framework Frames
Multiple Root Matches
If-m matches multiple methods, traces from each:
Allocation Tracing
processRequest.
Reading the Output
- We’re tracing from
processRequest(45.3% of samples) - The hottest path goes through
validateInput(38.2%) - There’s an alternate path through
fetchDataat 6.5% we didn’t follow - From
validateInput, hottest path ischeckRules(22.1%) - The leaf is
Pattern.matcherwith 15.8% self-time
The percentages decrease as you descend because you’re following one path through a branching tree. The leaf percentage represents actual CPU time spent.
When to Use
Critical Path Analysis
Find the single most expensive thing a method does
Optimization Targeting
Quickly identify the leaf method that consumes the most time
Performance Investigation
Understand why a hot method is slow by following its execution
Comparing Paths
Run multiple times with different
-m values to compare different pathsTrace vs Tree
| Command | Shows | Use When |
|---|---|---|
| trace | Single hottest path | You want the critical path only |
| tree | All paths (full tree) | You want to see all possibilities |
trace is focused and fast. tree is comprehensive but can be overwhelming for complex methods.