HelloWorld类:
package my.app.test;
import java.util.Random;
public class HelloWorld {
public static void main(String[] args) throws Exception {
//CaseObject object = new CaseObject();
while (true) {
Random random = new Random();
execute(random.nextInt(4000));
//object.execute(random.nextInt(4000));
}
}
public static Integer execute(int sleepTime) {
try {
Thread.sleep(sleepTime);
} catch (Exception e) {
}
System.out.println("helloworld execute thread sleep time is=>"+sleepTime);
return 0;
}
}
TraceHelloWorld跟踪类
package btrace;
import static com.sun.btrace.BTraceUtils.println;
import static com.sun.btrace.BTraceUtils.str;
import static com.sun.btrace.BTraceUtils.strcat;
import static com.sun.btrace.BTraceUtils.timeMillis;
import com.sun.btrace.annotations.BTrace;
import com.sun.btrace.annotations.Kind;
import com.sun.btrace.annotations.Location;
import com.sun.btrace.annotations.OnMethod;
import com.sun.btrace.annotations.ProbeClassName;
import com.sun.btrace.annotations.ProbeMethodName;
import com.sun.btrace.annotations.TLS;
@BTrace
public class TraceHelloWorld {
@TLS
private static long startTime = 0;
@OnMethod(clazz = "my.app.test.HelloWorld", method = "execute")
public static void startMethod(){
startTime = timeMillis();
}
@OnMethod(clazz = "my.app.test.HelloWorld", method = "execute", location = @Location(Kind.RETURN))
public static void endMethod(){
println(strcat("the class method execute time=>", str(timeMillis()-startTime)));
println("-------------------------------------------");
}
@OnMethod(clazz = "my.app.test.HelloWorld", method = "execute", location = @Location(Kind.RETURN))
public static void traceExecute(@ProbeClassName String name,@ProbeMethodName String method,int sleepTime){
println(strcat("the class name=>", name));
println(strcat("the class method=>", method));
println(strcat("the class method params=>", str(sleepTime)));
}
}
btrace pid TraceHelloWorld(全路径)