Arthas 从 9 月份开源以来,受到广大 Java 开发者的支持,Github Star 数三个月超过 6000,非常感谢用户支持。同时用户给 Arthas 提出了很多建议,其中反映最多的是:
- Windows 平台用户体验不好
- Attach 的进程和最终连接的进程不一致
- 某些环境下没有安装 Telnet,不能连接到 Arthas Server
- 本地启动,不需要下载远程(很多公司安全考虑)
- 下载速度慢(默认从 maven central repository 下载)
在 Arthas 3.0.5 版本里,我们在用户体验方面做了很多改进,下面逐一介绍。
全平台通用的 arthas-boot
arthas-boot是新增加的支持全平台的启动器,Windows/Mac/Linux 下使用体验一致。下载后,直接java -jar命令启动:
wget https://alibaba.github.io/arthas/arthas-boot.jar java -jar arthas-boot.jar arthas-boot的功能比以前的as.sh更强大。
-
比如下载速度比较慢,可以指定阿里云的镜像。
java -jar arthas-boot.jar --repo-mirror aliyun --use-http -
比如可以通过
session-timeout指定超时时间:java -jar arthas-boot.jar --session-timeout 3600 -
更多的功能可以通过
java -jar arthas-boot.jar -h查看
arthas-boot在 attach 成功之后,会启动一个 java telent client 去连接 Arthas Server,用户没有安装 telnet 的情况下也可以正常使用。
优先使用当前目录的 Arthas
在新版本里,默认会从arthas-boot.jar和as.sh所在的目录下查找 arthas home,这样子用户全量安装之后,不需要再从远程下载 Arthas。
- 用户可以更方便地集成到自己的基础镜像,或者 docker 镜像里
- 对安全要求严格的公司,不用再担心从远程下载的问题
Attach 之前先检测端口
在之前的版本里,用户困扰最多的是,明明选择了进程 A,但是实际连接到的却是进程 B。
原因是之前 attach 了进程 B,没有执行shutdown,下次再执行时,还是连接到进程 B。
在新版本里,做了改进:
- 在 attach 之前,检测使用 3658 端口的进程
- 在 Attach 时,如果端口和进程不匹配,会打印出 ERROR 信息
$ java -jar arthas-boot.jar [INFO] Process 1680 already using port 3658 [INFO] Process 1680 already using port 8563 * [1]: 1680 Demo [2]: 35542 [3]: 82334 Demo 3 [ERROR] Target process 82334 is not the process using port 3658, you will connect to an unexpected process. [ERROR] If you still want to attach target process 82334, Try to set a different telnet port by using --telnt-port argument. [ERROR] Or try to shutdown the process 1680 using the telnet port first. 更好的历史命令匹配功能
-
新版本对键盘
Up/Down有了更好的匹配机制,试用有惊喜:)比如执行了多次 trace,但是在命令行输入 trace 后,想不起来之前 trace 的具体类名,那么按
Up,可以很轻松地匹配到之前的历史命令,不需要辛苦翻页。 -
新版本增加了
history命令
改进 Web Console 的体验
-
改进对 Windows 的字体支持
之前 Windows 下面使用的是非等宽字体,看起来很难受。新版本里统一为等宽字体。
-
增大字体,不再伤害眼睛

新增 sysenv 命令
sysenv 命令和 sysprop 类似,可以打印 JVM 的环境变量。
新增 ognl 命令
ognl 命令提供了单独执行 ognl 脚本的功能。可以很方便调用各种代码。
比如执行多行表达式,赋值给临时变量,返回一个 List:
$ ognl '#value1=@System@getProperty("java.home"), #value2=@System@getProperty("java.runtime.name"), {#value1, #value2}' @ArrayList[ @String[/opt/java/8.0.181-zulu/jre], @String[OpenJDK Runtime Environment], ] watch 命令打印耗时,更方便定位性能瓶颈
之前 watch 命令只支持打印入参返回值等,新版本同时打印出调用耗时,可以很方便定位性能瓶颈。
$ watch demo.MathGame primeFactors 'params[0]' Press Ctrl+C to abort. Affect(class-cnt:1 , method-cnt:1) cost in 22 ms. ts=2018-11-29 17:53:54; [cost=0.131383ms] result=@Integer[-387929024] ts=2018-11-29 17:53:55; [cost=0.132368ms] result=@Integer[-1318275764] ts=2018-11-29 17:53:56; [cost=0.496598ms] result=@Integer[76446257] ts=2018-11-29 17:53:57; [cost=4.9617ms] result=@Integer[1853966253] 改进类搜索匹配功能,更好支持 lambda 和内部类
之前的版本里,在搜索 lambda 类时,或者反编绎 lambda 类有可能会失败。新版本做了修复。比如
$ jad Test$$Lambda$1/1406718218 ClassLoader: +-sun.misc.Launcher$AppClassLoader@5c647e05 +-sun.misc.Launcher$ExtClassLoader@3c1491ce Location: /tmp/classes /* * Decompiled with CFR 0_132. * * Could not load the following classes: * Test * Test$$Lambda$1 */ import java.lang.invoke.LambdaForm; import java.util.function.Consumer; final class Test$$Lambda$1 implements Consumer { private Test$$Lambda$1() { } @LambdaForm.Hidden public void accept(Object object) { Test.lambda$0((Integer)((Integer)object)); } } 更好的 tab 自动补全
改进了很多命令的tab自动补全功能,有停顿时,可以多按tab尝试下。
Release Note
详细的 Release Note: https://github.com/alibaba/arthas/releases/tag/arthas-all-3.0.5
