Skip to content

Instantly share code, notes, and snippets.

@2sbsbsb
Created August 15, 2012 21:57
Show Gist options
  • Save 2sbsbsb/3364047 to your computer and use it in GitHub Desktop.
Save 2sbsbsb/3364047 to your computer and use it in GitHub Desktop.
BTrace script for profiling method
/* BTrace Script Template */
import com.sun.btrace.annotations.*;
import static com.sun.btrace.BTraceUtils.*;
import com.sun.btrace.Profiler;
@BTrace
public class TracingScript {
// Initiate the profiler instance
public static Profiler p = com.sun.btrace.BTraceUtils.Profiling.newProfiler();
@OnMethod(clazz="com.test.TestRunner", method="commonMethod", location=@Location(value=Kind.ENTRY))
public static void onEnter(@ProbeMethodName(fqn=true) String methodFqn){
Profiling.recordEntry(p, methodFqn);
}
@OnMethod(clazz="com.test.TestRunner", method="commonMethod", location=@Location(value=Kind.RETURN))
public static void onExit(@Duration long dur, @ProbeMethodName(fqn=true) String methodFqn) {
Profiling.recordExit(p, methodFqn,dur);
}
// Print this method on any user event
@OnEvent()
public static void showDataEvent() {
Profiling.printSnapshot("User event", p);
}
// Print one min is elapsed
@OnTimer(36000)
public static void showDataTimer() {
Profiling.printSnapshot("",p);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment