btrace - Linux


btrace is a powerful, Java-based, dynamic tracing tool for the JVM. It enables real-time monitoring, profiling, and debugging of live Java applications without the need for source code modifications.


btrace [-o <output_file>] [-p <port>] [-v] [-h] <script_or_class_name> [args...]


  • -o <output_file>: Specify the output file for the generated code. Default: btrace.log
  • -p : Set the port for the btrace server. Default: 5100
  • -v: Enable verbose output
  • -h: Display help information


Simple Profiling:

btrace -p 5234 "profile.Profile.main(int,String[])"

Real-time Method Invocation Tracking:

btrace -p 5321 "trace.MethodTracer.main(int,String[])"

JDBC Statement Tracing:

btrace -o jdbc.log -p 5410 "jdbc.JDBC.main(int,String[])"

Common Issues

  • Permission Denied: Ensure you have sufficient permissions to attach to the JVM process.
  • Cannot Attach: Check if the JVM is running and accessible.
  • OutOfMemoryError: Increase the heap size of the btrace server using the -Xmx option.


  • jstack: Use btrace to capture a thread dump and pass it to jstack.
  • jvisualvm: Integrate btrace profiles with jvisualvm for graphical analysis.
  • Scripting: Create custom btrace scripts to automate specific tracing tasks.

Related Commands

  • jcmd: Manage Java processes
  • jmap: Display memory usage of Java processes
  • jprofiler: Provides advanced profiling and performance analysis
  • Btrace Documentation