Arthas從9月份開源以來,受到廣大Java開發者的支持,Github Star數三個月超過6000,非常感謝用戶支持。同時用戶給Arthas提出了很多建議,其中反映最多的是:
Windows平臺用戶體驗不好
Attach的進程和最終連接的進程不一致
某些環境下沒有安裝Telnet,不能連接到Arthas Server
本地啟動,不需要下載遠程(很多公司安全考慮)
下載速度慢(默認從maven central repository下載)
在Arthas 3.0.5版本裡,我們在用戶體驗方面做了很多改進,下面逐一介紹。
全平臺通用的arthas-bootarthas-boot是新增加的支持全平臺的啟動器,Windows/Mac/Linux下使用體驗一致。下載後,直接java -jar命令啟動:
wget https://alibaba.github.io/arthas/arthas-boot.jarjava -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。
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 Demo3[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/1406718218ClassLoader:+-sun.misc.Launcher$AppClassLoader@5c647e05 +-sun.misc.Launcher$ExtClassLoader@3c1491ceLocation:/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$1implements 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