Skip to content

Instantly share code, notes, and snippets.

@jecyhw
Last active March 3, 2019 09:52
Show Gist options
  • Save jecyhw/f6da8af360e5e52211f741a412e1c15d to your computer and use it in GitHub Desktop.
Save jecyhw/f6da8af360e5e52211f741a412e1c15d to your computer and use it in GitHub Desktop.
btrace示例
import com.sun.btrace.annotations.*;
import static com.sun.btrace.BTraceUtils.*;
@BTrace
public class TracingScript {
@OnMethod(
clazz="java.net.Socket",
method="setImpl",
location=@Location(Kind.RETURN)
)
public static void traceSocket(@Self java.net.Socket socket) {
println(timestamp("HH:mm:ss") + " traceSocket:" + get(field("java.net.Socket", "factory")));
}
@OnMethod(
clazz="java.net.ServerSocket",
method="setImpl",
location=@Location(Kind.RETURN)
)
public static void traceServerSocket(@Self java.net.ServerSocket socket) {
println(timestamp("HH:mm:ss") + " traceServerSocket:" + get(field("java.net.ServerSocket", "factory")));
}
@OnMethod(
clazz="org.apache.thrift.transport.TSocket",
method="initSocket",
location=@Location(Kind.RETURN)
)
public static void traceTSocket(@Self Object obj) {
println(timestamp("HH:mm:ss") + " traceTSocket:" + obj);
}
@OnMethod(
clazz="com.meituan.service.mobile.mtthrift.client.pool.ThriftPoolableObjectFactory",
method="makeObject",
location=@Location(Kind.RETURN)
)
public static void traceThriftPoolableObjectFactory(@Self Object obj) {
println(timestamp("HH:mm:ss") + " traceThriftPoolableObjectFactory:" + obj);
}
@OnMethod(
clazz="com.meituan.service.mobile.mtthrift.client.pool.ThriftPoolableObjectFactory",
method="destroyObject",
location=@Location(Kind.RETURN)
)
public static void traceThriftPoolableObjectFactoryDestroyObject(Object tTransport, @Self Object obj) {
println(timestamp("HH:mm:ss") + " traceThriftPoolableObjectFactoryDestroyObject:" + tTransport);
}
@OnMethod(
clazz="sun.net.NetworkClient",
method="createSocket",
location=@Location(Kind.RETURN)
)
public static void traceNetworkClient(@Return Object obj) {
println(timestamp("HH:mm:ss") + " traceNetworkClient:" + obj);
}
@OnMethod(
clazz="sun.net.NetworkClient",
method="doConnect",
location=@Location(Kind.RETURN)
)
public static void traceNetworkClientDoConnect(String var1, int var2, @Return Object obj) {
println(timestamp("HH:mm:ss") + " traceNetworkClientDoConnect:" + obj + " " + var1 + ":" + var2);
}
@OnMethod(
clazz="sun.net.www.http.HttpClient",
method="openServer",
location=@Location(Kind.RETURN)
)
public static void traceNetworkClientOpenServer(String var1, int var2, @Self Object obj) {
println(timestamp("HH:mm:ss") + " traceNetworkClientOpenServer:" + " " + var1 + ":" + var2 + ";" + obj);
}
@OnMethod(
clazz="com.meituan.service.mobile.mtthrift.client.invoker.MTThriftMethodInterceptor",
method="getConnection",
location=@Location(Kind.RETURN)
)
public static void traceMTThriftMethodInterceptor(Object serverConn, Object clientProxy, String methodName, int timeout) {
println(timestamp("HH:mm:ss") + " traceMTThriftMethodInterceptor:" + " " + serverConn + ";" + clientProxy + ";" + methodName + ";" + timeout);
}
@OnMethod(
clazz="org.apache.commons.pool.impl.GenericObjectPool",
method="addObject",
location=@Location(Kind.RETURN)
)
public static void traceGenericObjectPool(@Self Object obj) {
println(timestamp("HH:mm:ss") + " traceGenericObjectPool:" + " " + obj);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment