Alibaba 应用诊断利器 Arthas 3.0.5 版本发布:提升全平台用户体验

2018-11-29 21:14:48 +08:00
 hengyunabc

Arthas 从 9 月份开源以来,受到广大 Java 开发者的支持,Github Star 数三个月超过 6000,非常感谢用户支持。同时用户给 Arthas 提出了很多建议,其中反映最多的是:

  1. Windows 平台用户体验不好
  2. Attach 的进程和最终连接的进程不一致
  3. 某些环境下没有安装 Telnet,不能连接到 Arthas Server
  4. 本地启动,不需要下载远程(很多公司安全考虑)
  5. 下载速度慢(默认从 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更强大。

arthas-boot在 attach 成功之后,会启动一个 java telent client 去连接 Arthas Server,用户没有安装 telnet 的情况下也可以正常使用。

优先使用当前目录的 Arthas

在新版本里,默认会从arthas-boot.jaras.sh所在的目录下查找 arthas home,这样子用户全量安装之后,不需要再从远程下载 Arthas。

Attach 之前先检测端口

在之前的版本里,用户困扰最多的是,明明选择了进程 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.

更好的历史命令匹配功能

改进 Web Console 的体验

新增 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

1885 次点击
所在节点    Java
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/512874

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX