LinuxCommandLibrary

arthas-trace

Trace Java method execution paths and timing.

TLDR

Trace method execution
$ trace [com.example.MyClass] [myMethod]
copy
Trace with condition
$ trace [com.example.MyClass] [myMethod] '#cost > 100'
copy
Trace all methods in class
$ trace [com.example.MyClass] *
copy
Trace with invocation count
$ trace -n [5] [com.example.MyClass] [myMethod]
copy

SYNOPSIS

trace [-n count] [--skipJDKMethod] class-pattern method-pattern [condition-express]

DESCRIPTION

trace is an Arthas command that traces method execution paths and timing. It shows the call hierarchy within a method invocation, highlighting which sub-methods consume the most time.
This is invaluable for identifying performance bottlenecks without adding logging or profiling instrumentation.

PARAMETERS

class-pattern

Class name (supports wildcards)
method-pattern
Method name (supports wildcards)
-n count
Stop after count invocations
--skipJDKMethod
Skip tracing JDK methods
condition-express
OGNL condition (e.g., '#cost > 100')

OUTPUT

Shows call tree with:
- Method names
- Execution time
- Nested call structure

CAVEATS

Deep traces may produce verbose output. Performance overhead increases with trace depth. Use conditions to limit output.

HISTORY

trace is a core diagnostic command in Arthas, essential for performance troubleshooting in production Java applications.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard