VisualVM + BTrace

 

VisualVM下载地址:http://visualvm.github.io/download.html

解压后打开bin目录下的visualvm.exe

选择Tool-->Plugins,选择插件安装

测试代码

复制代码
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class BTraceTest {
    public int add(int a,int b){
        return a+b;
    }
    public static void main(String[] args) throws IOException {
        BTraceTest test=new BTraceTest();
        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));
        }
    }
}
复制代码

运行测试代码,在visualVM中右键选择应用-->Trace Application

 

即可出现Btrace窗口

 

 在这里可以编辑代码

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

点击Start即可开启

返回BTraceTest输入回车,观察两边的控制台信息

 

 

 

posted @   uptothesky  阅读(260)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· [AI/GPT/综述] AI Agent的设计模式综述
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
点击右上角即可分享
微信分享提示