Btrace安装入门

一.配置环境变量
下载btrace https://github.com/btraceio/btrace
https://github.com/btraceio/btrace/releases/tag/v1.3.11.1
Btrace安装入门
解压文件
Btrace安装入门
新建环境变量:BTRACE_HOME
Btrace安装入门
添加path: %BTRACE_HOME%\bin

二 两种运行脚本的方式
1 在JVisualVM中添加Btrace插件,添加classpath
2 使用命令行btrace <btrace_scipt>
第一种脚本例子 类似于拦截器方式织入代码
controller测试代码
package com.baoge_springboot.springboot_core.web.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ch")
public class CahController {
@RequestMapping("/question")
public String query(@RequestParam(“name”) String name){
return "success: "+name;
}

}
脚本代码
package com.baoge_springboot.springboot_core.common.btrace;

import com.sun.btrace.AnyType;
import com.sun.btrace.BTraceUtils;
import com.sun.btrace.annotations.*;

@BTrace
public class BtraceSimple {
@OnMethod(
//需要拦截的类
clazz = “com.baoge_springboot.springboot_core.web.controller.CahController”,
//需要拦截的方法名
method = “query”,
//拦截位置 进入方法入口
location = @Location(Kind.ENTRY)
)
/**
* @ProbeClassName 要拦截方法类名
*@ProbeMethodName 要拦截方法名
*AnyType[] 方法参数
*/
public static void anyRead(@ProbeClassName String pcm, @ProbeMethodName String pmn, AnyType[] args){
BTraceUtils.printArray(args);
BTraceUtils.println(pcm+","+pmn);
BTraceUtils.println();
}

}
添加架包

	<dependency>
		<groupId>com.sun.tools.btrace</groupId>
		<artifactId>btrace-boot</artifactId>
		<version>1.2.3</version>
	</dependency>
	
	<dependency>
	<groupId>com.sun.tools.btrace</groupId>
	<artifactId>btrace-agent</artifactId>
	<version>1.2.3</version>
	</dependency>
	
	<dependency>
	<groupId>com.sun.tools.btrace</groupId>
	<artifactId>btrace-client</artifactId>
	<version>1.2.3</version>
	</dependency>

外部引入本地jar包方式
Btrace安装入门
VisualVM文档使用参考文档 https://visualvm.github.io/documentation.html
BTrace文档使用
https://github.com/btraceio/btrace

命令运行
进入脚本目录
E:\Store\springboot_core\src\main\java\com\baoge_springboot\springboot_core\common\btrace
Btrace安装入门
查看该目录下的文件
Btrace安装入门

执行
查找pid 命令 jps -l
Btrace安装入门
执行命令 Btrace 进程号 脚本名
Btrace安装入门
访问 查看控制台输出结果:
参数 helloeo!!88
方法名
com.baoge_springboot.springboot_core.web.controller.CahController,query

Btrace安装入门

Java VisualVM 执行方式
首先需要安装插件
Btrace安装入门
启动成功的结果

Btrace安装入门

访问

Btrace安装入门

Btrace安装入门