服务端类:
package test;
public class BTraceServer {
public String sayHello(int i) {
return "参数" + i;
}
public static void main(String[] args) throws InterruptedException {
BTraceServer bt = new BTraceServer();
int i = 0;
while (true) {
System.err.println(bt.sayHello(i++));
Thread.sleep(1000);
}
}
}
客户端类:
package test;
import com.sun.btrace.BTraceUtils;
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.Return;
import com.sun.btrace.annotations.Self;
@BTrace
public class BTraceTest {
@OnMethod(clazz="test.BTraceServer", method="sayHello",
location=@Location(Kind.RETURN))
public static void onSayHello(@Self BTraceServer s, int param, @Return String ret){
BTraceUtils.print(param);
BTraceUtils.println(ret);
}
}
1、将服务端类打成jar包;
2、btrace执行btrace -classpath D:\doc\btrace\btrace-bin\build\test.jar 【PID】 BTraceTest.java