Overview
Thelines command provides a source-line level breakdown of where time is spent within a specific method. This helps identify:
- Which lines in a method are most expensive
- Loop iterations vs initialization overhead
- Specific statements causing bottlenecks
Line information requires debug symbols and profiler support. Not all profiles include line numbers.
Usage
Flags
Required. Substring to match on method name
Limit output rows (0 = unlimited)
Show fully-qualified method names in output
Shared Flags
Common flags supported by most commands:Event type:
cpu, wall, alloc, lock, or hardware counter nameFilter to threads matching substring
Start time of window (JFR only)
End time of window (JFR only)
Output Format
Displays a ranked table:- SOURCE:LINE: Method name and line number
- SAMPLES: Sample count for that line
- PCT: Percentage of total profile samples
Examples
Basic Line Breakdown
Top Lines Only
Show just the top 5 lines:Multiple Methods Matching
When multiple methods match, all are analyzed:UserService.process, OrderService.process).
Fully-Qualified Names
Distinguish methods with identical short names:Thread-Specific Lines
Allocation Hot Lines
Find which lines allocate the most:Time Window Analysis
Requirements
Line Number Availability
Line information requires:- Debug symbols in the profiled binary/JAR
- Profiler support for line numbers:
- async-profiler 2.0+ with
-XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints - JFR with debug info
- async-profiler 2.0+ with
- Compiled code: Interpreted methods may not have line info
Checking for Line Info
If you see:- No debug symbols (
javac -g) - Native or kernel frames
- JVM runtime methods
- Inlined code (line may be attributed to caller)
Use Cases
Loop Optimization
Identify expensive loop iterations:Conditional Branch Cost
Method Refactoring
Before refactoring a large method, see which sections are expensive:Validating Optimizations
Compare line profiles before/after changes:Understanding Inlining
Samples may appear on the call site rather than the inlined method’s original source:Interpretation Tips
Troubleshooting
No Matching Method
If you see:- Method name spelling (case-sensitive)
- Method exists in this event type: try
--event wallor--event alloc - Method was sampled: use
ap-query hotto verify it appears
Method Exists But No Line Info
Error:- Recompile with debug info:
javac -g - Add JVM flags:
-XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints - Check if method is native/kernel code (line info not available)
Unexpected Line Numbers
If line numbers don’t match your source:- Ensure JARs/binaries match the profiled version
- Check for compiler optimizations reordering code
- Verify debug info wasn’t stripped during build