Linux command
btrace 命令
网络
复制后可按需替换文件名、目录或参数。
常用示例
Trace method calls
btrace [pid] [script.java]
Trace with classpath
btrace -cp [/path/to/classes] [pid] [script.java]
Trace with unsafe mode
btrace -u [pid] [script.java]
Compile a BTrace script
btracec [script.java]
Run with debug output
btrace -v [pid] [script.java]
说明
BTrace is a safe, dynamic tracing tool for the Java platform. It allows attaching tracing scripts to running Java applications without restarting them. BTrace scripts are written in Java with annotations defining trace points. BTrace works by instrumenting bytecode of the target application. Scripts can intercept method entries, exits, exceptions, and other events. The tracing is designed to be safe, preventing scripts from modifying application state or causing deadlocks. Common use cases include performance profiling, debugging production issues, monitoring method call patterns, and tracking memory allocations without application restarts.
参数
- pid
- Process ID of target Java application.
- script
- BTrace script file (.java).
- -v
- Verbose mode.
- -u
- Unsafe mode (enables more operations).
- -d _path_
- Dump instrumented classes to path.
- -pd _path_
- Probe descriptor search path.
- -cp _classpath_
- Classpath for script compilation.
- -I _path_
- Preprocessor include path.
- -p _port_
- Agent server port.
- -statsd _host:port_
- Send metrics to StatsD server.
FAQ
What is the btrace command used for?
BTrace is a safe, dynamic tracing tool for the Java platform. It allows attaching tracing scripts to running Java applications without restarting them. BTrace scripts are written in Java with annotations defining trace points. BTrace works by instrumenting bytecode of the target application. Scripts can intercept method entries, exits, exceptions, and other events. The tracing is designed to be safe, preventing scripts from modifying application state or causing deadlocks. Common use cases include performance profiling, debugging production issues, monitoring method call patterns, and tracking memory allocations without application restarts.
How do I run a basic btrace example?
Run `btrace [pid] [script.java]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does pid do in btrace?
Process ID of target Java application.