阿里开源项目arthas安装使用

时间:2023-03-08 17:36:48

文档地址

https://alibaba.github.io/arthas/install-detail.html

开始安装

  1. 我本地就装window版本了,下载zip包
  2. 按照快速入门,编译demo程序,运行watch后

    阿里开源项目arthas安装使用 可以看到watch可以直接拿到正在运行的方法返回值
  3. dashboard命令用来查看进程基本信息

    阿里开源项目arthas安装使用

    4.monitor -c 5 Demo hehe
import java.util.*;

public class Demo {

	   public static void main(String[] args) {
List<String> list = new ArrayList<String>();
list.add("a");
list.add("b"); List<String> list2 = new ArrayList<String>();
list2.add("c");
list2.add("d"); int len = add(list, list2);
} private static int add(List<String> list, List<String> list2) {
int i = 100;
while (i >= 0) {
try {
hehe(i);
Thread.sleep(2000);
} catch (Throwable t) {
t.printStackTrace();
}
i--;
} list.addAll(list2);
return list.size();
} private static void hehe(int i) {
if (i == 0) {
throw new RuntimeException("ZERO");
}
haha(i);
} private static void haha(int i){ }
}

阿里开源项目arthas安装使用

可以看出monitor可以查看方法调用频率和成功失败情况

5. trace Demo hehe

阿里开源项目arthas安装使用

它展示的是方法的深层次调用和调用时间

6. watch Demo hehe {params[0],throwExp} -e

阿里开源项目arthas安装使用

观察方法执行入参

7. tt -t Demo hehe

阿里开源项目arthas安装使用

记录方法调用信息,支持事后查看方法调用的参数,返回值,抛出的异常等信息,仿佛穿越时空隧道回到调用现场一般。

8. classloader

阿里开源项目arthas安装使用

当前系统中有多少类加载器,以及每个加载器加载的类数量

9. jad Demo

阿里开源项目arthas安装使用

可以看到,改命令能反编译类,线上看代码不是梦,个人觉得这个最实用了

10. sc -d Demo

阿里开源项目arthas安装使用

查看类的继承关系等

11. stack Demo

阿里开源项目arthas安装使用

查看栈信息