arthas-trace
Trace method execution details and timings
TLDR
Trace method invoke chain
Trace method invoke chains and only display invoke information longer than 10 ms
Trace the invoke chain of multiple classes or multiple methods
Track method invoke chains, only display invoke information that exceeds 10 ms, and exit after 5 times
SYNOPSIS
trace [-E] [-n
PARAMETERS
-E
Enable regular expression matching for class and method names.
-n
Limit the number of trace results to display.
-f
Force output even if no results match the condition.
class_pattern
Java class name pattern. Supports wildcard matching.
method_pattern
Method name pattern. Supports wildcard matching.
'#cost > time'
OGNL expression to filter trace results based on execution time.
DESCRIPTION
The `arthas-trace` command in Arthas (Alibaba Arthas) is a powerful diagnostic tool used to trace the execution path of a specific method within a Java application. It allows developers to observe the flow of execution, including the parameters passed to the method and the values returned, providing detailed insights into method behavior. This is invaluable for debugging performance issues, understanding complex logic, and identifying the root cause of errors.
The command can filter out insignificant execution paths by specifying condition expression with OGNL. This helps users focus on specific scenarios. It provides rich information during method execution, including execution time, parameters, return value, and exceptions. It uses bytecode instrumentation techniques to dynamically collect this information without requiring code modifications. It makes real-time diagnosis of production environment issues simple.
CAVEATS
Requires Arthas to be attached to a running Java process. Bytecode instrumentation may have a slight performance impact, but Arthas is designed to minimize this impact. Ensure the user running Arthas has sufficient permissions to access the target Java process.
OGNL EXPRESSION EXAMPLES
#cost > 100: Trace method calls that take longer than 100 milliseconds.
params[0].length > 10: Trace method calls where the first parameter is a string with a length greater than 10.
TIPS AND TRICKS
Use the `-n` option to limit the output and avoid overwhelming the console. Start with a simple class and method pattern, and then refine the pattern as needed.
SEE ALSO
arthas-watch(1), arthas-monitor(1), arthas-stack(1), arthas-tt(1)