btrace跟踪接口调用时间
可用来定位是否http接口过慢问题,最好在服务出问题才使用该方法定位
进入到/root/tool/btrace/bin
用jps查看MetadataServerLauncher 进程号 ./btrace 进程号 HttpServiceProbe.java
./btrace 29633 HttpServiceProbe.java
输出结果:
[root@tsung3924 bin]# ./btrace 29633 HttpServiceProbe.java entering HttpService com.snda.youni.wine.metadata.service.HttpService.get http://10.192.10.1 leaving HttpService com.snda.youni.wine.metadata.service.HttpService.get Time taken (sec) 0.00796 entering HttpService com.snda.youni.wine.metadata.service.HttpService.get http://10.192.10.1 leaving HttpService com.snda.youni.wine.metadata.service.HttpService.get Time taken (sec) 0.008272 entering HttpService com.snda.youni.wine.metadata.service.HttpService.get http://10.192.10.1 leaving HttpService com.snda.youni.wine.metadata.service.HttpService.get Time taken (sec) 0.008154 entering HttpService com.snda.youni.wine.metadata.service.HttpService.get http://10.192.10.1 leaving HttpService com.snda.youni.wine.metadata.service.HttpService.get Time taken (sec) 0.008569
HttpServiceProbe 示例,监控其它类可自己修改
import static com.sun.btrace.BTraceUtils.*;
import com.sun.btrace.annotations.*;
import java.util.*;
import java.lang.*;
@BTrace class HttpServiceProbe {
@OnMethod(clazz = "com.snda.youni.wine.metadata.service.HttpService", method = "get")
public void onGet(@ProbeClassName String pcn,
@ProbeMethodName String pmn) {
print("entering HttpService ");
println(Strings.strcat(Strings.strcat(pcn, "."), pmn));
}
@OnMethod(clazz = "com.snda.youni.wine.metadata.service.HttpService", method = "get", location = @Location(Kind.RETURN))
public void onGetReturn(@ProbeClassName String pcn,
@ProbeMethodName String pmn, @Duration long d,java.util.Map paraMap,java.lang.String url) {
println(url);
print("leaving HttpService ");
println(Strings.strcat(Strings.strcat(pcn, "."), pmn));
println(Strings.strcat("Time taken (sec) ", Strings.str(d / 1000000000.0)));
println("==========================");
}