Btrace拦截行号
被拦截对象(Btrace只能在本地运行)
拦截行号的btrace脚本
import com.sun.btrace.AnyType;
import com.sun.btrace.BTraceUtils;
import com.sun.btrace.annotations.*;
@BTrace
public class PrintArgsSimple {
@OnMethod(
clazz = "mooc.birdsky.java.performance.Controller.BtraceController" ,
location = @Location(value=Kind.LINE,line=12)
)
public static void line(@ProbeClassName String pcn, @ProbeMethodName String pmn,int line){
BTraceUtils.println("line:"+line);
BTraceUtils.println("pcn"+pcn);
BTraceUtils.println("pmn"+pmn);
}
}
运行btrace脚本
btrac 311 /Users/wangsen/java/performance/src/main/java/mooc/birdsky/java/performance/btrace/PrintArgsSimple.java
运行结果
pcn:mooc.birdsky.java.performance.Controller.BtraceController
pmn:hello
line:12
line=-1,拦截全部行
curl http://localhost:8080/btrace/exception
运行结果打印19、20、22、25。
line:19
pcnmooc.birdsky.java.performance.Controller.BtraceController
pmnexception
line:20
pcnmooc.birdsky.java.performance.Controller.BtraceController
pmnexception
line:22
pcnmooc.birdsky.java.performance.Controller.BtraceController
pmnexception
line:25
pcnmooc.birdsky.java.performance.Controller.BtraceController
高级专题
- 复杂对象:btrace -cp 设置classpath
- 环境变量:clazz和method都支持正则表达式。
网友评论