BTrace示例(九) 捕获同名方法

被调试程序

@RestController
@RequestMapping("/ch4")
public class Ch4Controller {
    
    @RequestMapping("/same1")
    public String same(@RequestParam("name")String name) {
        return "hello, " + name;
    }

    @RequestMapping("/same2")
    public String same(@RequestParam("name")String name,@RequestParam("id")int id) {
        return "hello, " + name + ", " + id;
    }

}

BTrace脚本

  • 通过方法参数区分;
package com.btrace.example;
import com.sun.btrace.BTraceUtils;
import com.sun.btrace.annotations.BTrace;
import com.sun.btrace.annotations.OnMethod;
import com.sun.btrace.annotations.ProbeClassName;
import com.sun.btrace.annotations.ProbeMethodName;

@BTrace
public class PrintSame {
    
    @OnMethod(
            clazz="com.example.demo.btrace.Ch4Controller",
            method="same"
    )
    public static void anyRead(@ProbeClassName String pcn, @ProbeMethodName String pmn, String name) {
        BTraceUtils.println(pcn+","+pmn + "," + name);
        BTraceUtils.println();
    }

}

你可能感兴趣的