BTrace动态日志跟踪

BTrace:是一个VisualVM插件,本身也是可以独立运行的程序。作用是:不停止目标程序运行的前提下,通过HotSpot虚拟机的HotSwap技术动态加入原本并不存在的调试代码。

 

package test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Test {
	public  int add(int a,int b) {
		return a + b;
		
	}
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Test test = new Test();
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		for(int i=0;i<10;i++) {
			reader.readLine();
			int a = (int) Math.round(Math.random() * 1000);
			int b = (int) Math.round(Math.random() * 1000);
			System.out.println(test.add(a, b));
		}
		
	}

}

打开jvisualvm.exe。运行上面程序后,选中红色框进程,右键“Trace Application...”

输入调试代码后,点击“start”按钮后稍等片刻,编译完成后,在程序运行时,在OUTPUT会输出调试信息。

/* put your code here */
    @OnMethod(clazz="test.Test",method="add",location=@Location(Kind.RETURN))
    public static void func(@Self test.Test instance,int a,int b,@Return int result){
        println("调用堆栈:");
        jstack();
        println(strcat("方法参数A:", str(a)));
        println(strcat("方法参数B:", str(b)));
        println(strcat("方法结果:", str(result)));
    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值