Skip to content

Instantly share code, notes, and snippets.

@ChinaXing
Created April 27, 2020 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChinaXing/c5edf1998ea304411dc4e9fbf3e403ea to your computer and use it in GitHub Desktop.
Save ChinaXing/c5edf1998ea304411dc4e9fbf3e403ea to your computer and use it in GitHub Desktop.
btrace java agent
# -------------- 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