Created
April 27, 2020 09:13
-
-
Save ChinaXing/c5edf1998ea304411dc4e9fbf3e403ea to your computer and use it in GitHub Desktop.
btrace java agent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -------------- trace script Java source ---------------- # | |
import com.sun.btrace.annotations.*; | |
import static com.sun.btrace.BTraceUtils.*; | |
import com.sun.btrace.AnyType; | |
@BTrace // (trusted=true) | |
public class Test { | |
@OnMethod( | |
clazz="java.net.ServerSocket", | |
method="bind" | |
) | |
public static void m(AnyType[] args){ | |
println("port " + str(args[0])); | |
jstack(); | |
} | |
public static Object getField(Object self, String fld){ | |
return get(field(classOf(self), fld), self); | |
} | |
} | |
# -------- Compile source to .class script ------------ # | |
bin/btracec Test.java # produced Test.class | |
# --------- add Application start's cmdline javaagent use btrace-agent.jar ---------- # | |
java -javaagent:btrace-agent.jar=script=/vol/log/Test.class | |
# --------- See Log ---------------------------------- # | |
the log will located in : /vol/log/Test.class.xxxxxx | |
# eg : Test.class-.default.1587978055966.btrace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment