Quick Start:
- Download BTrace from here
- Extract the release to a directory e.g.
~/btrace
- Write a BTrace program. There are many samples present in the
samples
directory. Here is one of mine: the program below prints a message whenever the target program calls theArrayList.add()
method.
import com.sun.btrace.annotations.*; import static com.sun.btrace.BTraceUtils.*; import java.util.*; @BTrace public class ArrayListTrace { // @OnMethod annotation tells where to probe. // In this example, we are interested in entry // into the ArrayList.add() method. @OnMethod( clazz="java.util.ArrayList", method="add"; ) // print out what was added public static void alert(@Self ArrayList self, Object o) { print("ADDED "); println(o); } }
javac -cp "~/btrace/build/*" ArrayListTrace.java
~/btrace/bin/btrace -cp ".:~/btrace/build/*" <PID> ArrayListTrace.classUseful BTrace Programs:
Here are a few useful BTrace programs I have used in the past:
- OnThrow: Prints out the stack trace of an exception whenever a Throwable is created. This way you can capture all exceptions, even those that have been swallowed.
- LogTracer: Prints out log messages.
- AllMethods: Prints out the name of every method entered.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.