BTrace示例(三) 拦截构造方法

被调试程序

@RestController
@RequestMapping("/ch4")
public class Ch4Controller {
    
    @RequestMapping("/constructor")
    public User constructor(User user) {
        return user;
    }   

}

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.OnMethod;
import com.sun.btrace.annotations.ProbeClassName;
import com.sun.btrace.annotations.ProbeMethodName;

@BTrace
public class PrintConstructor {
    
    @OnMethod(
            clazz="com.example.demo.User",
            method=""
    )
    public static void anyRead(@ProbeClassName String pcn, @ProbeMethodName String pmn, AnyType[] args) {
        BTraceUtils.println(pcn+","+pmn);
        BTraceUtils.printArray(args);
        BTraceUtils.println();
    }

}

BTrace脚本执行

>btrace -cp C:\Users\LiXinlei\Desktop\demo\target\classes 15368 PrintArgComplex.java
{id=222, name=222, }
222
com.example.demo.btrace.Ch4Controller, arg2

你可能感兴趣的:(BTrace示例(三) 拦截构造方法)