被调试程序
@RestController
@RequestMapping("/ch4")
public class Ch4Controller {
@RequestMapping("/arg1")
public String arg1(@RequestParam("name") String name) {
return "hello," + name;
}
}
BTrace脚本
package com.btrace.example;
import com.sun.btrace.AnyType;
import com.sun.btrace.BTraceUtils;
import com.sun.btrace.annotations.BTrace;
import com.sun.btrace.annotations.Kind;
import com.sun.btrace.annotations.Location;
import com.sun.btrace.annotations.OnMethod;
import com.sun.btrace.annotations.ProbeClassName;
import com.sun.btrace.annotations.ProbeMethodName;
@BTrace
public class PrintArgSimple {
@OnMethod(
clazz="com.example.demo.btrace.Ch4Controller",
method="arg1",
location=@Location(Kind.ENTRY)
)
public static void anyRead(@ProbeClassName String pcn, @ProbeMethodName String pmn, AnyType[] args) {
BTraceUtils.printArray(args);
BTraceUtils.println(pcn);
BTraceUtils.println(pmn);
BTraceUtils.println();
}
}
执行BTrace脚本
http://localhost:8088/ch4/arg1?name=333
btrace 19384 C:\Users\LiXinlei\Desktop\btrace\src\com\btrace\example\PrintArgSimple.java
[333, ]
com.example.demo.btrace.Ch4Controller
arg1