Today I had to do a live debugging on a java application. I found a nice tool named btrace (no, it’s not that btrace…but THIS btrace ;).
Btrace seems magical:
- is the java version of SystemTap or DTrace;
- doesn’t need java debugging nor has  further requirements;
- doesn’t stop your application.
Once downloaded, you have to:
- create a small java program specifying what to trace;
- find the pid of your target jvm instance;
- add the required classpath to btrace.
Then run it, with:
# ./btrace -cp $YOUR_CLASSPATH Â $JVM_PID MyClassTracer.java
The MyClassTracer.java is something like this (example take from here):
import com.sun.btrace.annotations.*;
import static com.sun.btrace.BTraceUtils.*;
import java.io.File;
// every time new File(String) is called, print the file name
@BTrace
public class HelloBTrace {
@OnMethod(
clazz="java.io.File", method=""
)
public static void onNewFile(File self, String name) {
print("new file ");
println(name);
}
}