-
Notifications
You must be signed in to change notification settings - Fork 2
/
Misc.java
85 lines (62 loc) · 2.95 KB
/
Misc.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import java.lang.reflect.Field;
import com.sun.btrace.AnyType;
@BTrace
public class DemoTracer2 {
//JDK的类这样写就行
private static Field fdFiled = field("java.io,FileInputStream", "fd");
//非JDK的类,要给出ClassLoader,否则ClassNotFound
private static Field portField = field(classForName("com.vip.demo.MyObject", contextClassLoader()), "port");
@TLS
private static int port = -1;
@OnMethod(clazz="+com.vip.demo.Filter", method="doFilter")
@OnMethod(clazz="@javax.jws.WebService", method="@javax.jws.WebMethod")
@OnMethod(clazz="java.net.ServerSocket", method="<init>")
@OnMethod( clazz="java.net.ServerSocket", method="bind" )
public static mythond(){
}
@OnMethod(clazz = "java.net.ServerSocket", method = "getLocalPort", location = @Location(Kind.RETURN))
public static void onGetLocalPort(@Return int port, @Duration long duration) {
println(strcat(strcat(probeClass, "."), probeMethod));
}
@OnMethod(clazz = "java.net.ServerSocket", method = "bind", location = @Location(Kind.ERROR))
public static void onBind(Throwable exception, @Duration long duration){
}
@OnMethod(clazz = "java.net.ServerSocket", method = "bind", location = @Location(value = Kind.CALL, clazz = "/.*/", method = "/.*/", where = Where.AFTER))
public static void onBind2(@Self Object self, @TargetInstance Object instance, @TargetMethodOrField String method, @Duration long duration) {
}
@OnMethod(clazz = "/javax\\.swing\\..*/", method = "/.*/", location = @Location(value = Kind.CALL, clazz = "/.*/", method = "/.*/", where = Where.AFTER))
public static void onBind3(@Self Object self, @TargetInstance Object instance, @TargetMethodOrField String method,
@Duration long duration) {
}
@OnMethod(clazz = "java.net.ServerSocket", location = @Location(value = Kind.LINE, line = 363))
public static void onBind4() {
println("socket bind reach line:363");
}
@OnMethod(clazz = "java.io.File", method = "createTempFile", location = @Location(value = Kind.RETURN))
public static void o(@Self Object self, String prefix, String suffix, @Return AnyType result) {
}
public static void onChannelRead(@Self Object self) {
println("port:" + getInt(portField, self));
}
@OnMethod(clazz = "java.net.ServerSocket", method = "<init>")
public static void onServerSocket(int p) {
port = p;
}
@OnMethod(clazz = "java.net.ServerSocket", method = "<init>", location = @Location(Kind.RETURN))
public static void onSockReturn() {
println("server socket at " + port);
}
@OnMethod(clazz = "+com.vip.demo.Filter", method = "doFilter", location = @Location(Kind.RETURN))
public static void onDoFilter2(@ProbeClassName String pcn, @Duration long duration) {
if (duration > 1000000) {
println(pcn + ",duration:" + (duration / 100000));
}
}
@OnMethod(clazz = "java.lang.System", method = "gc")
public static void onSystemGC() {
println("entered System.gc()");
jstack();
println(strcat(strcat(probeClass, "."), probeMethod));
println(probeClass + '.' + probeMethod);
}
}