
Arthas 从 9 月份开源以来,受到广大 Java 开发者的支持,Github Star 数三个月超过 6000,非常感谢用户支持。同时用户给 Arthas 提出了很多建议,其中反映最多的是:
在 Arthas 3.0.5 版本里,我们在用户体验方面做了很多改进,下面逐一介绍。
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-boot.jar和as.sh所在的目录下查找 arthas home,这样子用户全量安装之后,不需要再从远程下载 Arthas。
在之前的版本里,用户困扰最多的是,明明选择了进程 A,但是实际连接到的却是进程 B。
原因是之前 attach 了进程 B,没有执行shutdown,下次再执行时,还是连接到进程 B。
在新版本里,做了改进:
$ 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 --telnet-port argument. [ERROR] Or try to shutdown the process 1680 using the telnet port first. 新版本对键盘Up/Down有了更好的匹配机制,试用有惊喜:)
比如执行了多次 trace,但是在命令行输入 trace 后,想不起来之前 trace 的具体类名,那么按Up,可以很轻松地匹配到之前的历史命令,不需要辛苦翻页。
新版本增加了history命令
改进对 Windows 的字体支持
之前 Windows 下面使用的是非等宽字体,看起来很难受。新版本里统一为等宽字体。
增大字体,不再伤害眼睛

sysenv 命令和 sysprop 类似,可以打印 JVM 的环境变量。
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 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 类有可能会失败。新版本做了修复。比如
$ 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尝试下。
详细的 Release Note: https://github.com/alibaba/arthas/releases/tag/arthas-all-3.0.5