一.下載安裝arthas
wget https://alibaba.github.io/arthas/arthas-boot.jar
二.啟動,退出,停止
1.啟動方法
java -jar arthas-boot.jar
2.退出當前指定的某一個arthas的命令
Q 或者 Ctrl+C
3.退出arthas[只能退出當前會話,arthas server並未停止執行]
exit 或者 quit
退出后可以通過 java -jar arthas-boot.jar 重連 arthas server服務
4.完全退出arthas server
使用 stop
5.儀表盤
dashboard
堆內存信息
heap 堆內存
ps_eden_space : 對象被創建的時候首先存放的區域
ps_survivor_space : eden space內存區域中經過垃圾回收后沒有被回收的對象
ps_old_gen: 存放新生代中經過多次垃圾回收仍然存活的對象(上面兩個都是新生代)
nonheap: 非堆內存(通常說的棧內存)
code_cash: 存放JIT所編譯的機器碼
metaspace: 永久代
三.trace使用,查看方法內一級子方法調用耗時【往下的調用鏈路】
1.基礎使用示例:【也可以看出來整個調用棧中哪行拋出異常了throws Exception】
trace 類路徑 方法名
trace com.test.ClassA methodB
2.如果本方法調用次數很多,則只想捕獲10次 的調用 就退出Q
trace 類路徑 方法名 run -n 10
3.tracem默認不展示JDK方法調用耗時,如果想打印出來,需要顯式設置 --skipJDKMethod false
trace --skipJDKMethod false 類路徑 方法名
4.匹配多個類或多個函數
trace -E com.test.ClassA|org.test.ClassB method1|method2|method3
5.排查時間大於2ms的調用
trace com.test.ClassA methodB '#cost > 2'
四.stack使用,查看方法被調用的 調用鏈 【往上的調用鏈路】
1.基本使用示例:
stack com.test.ClassA methodB
五. 反編譯
1. 查看具體 某個線程的 調用堆棧
thread PID
2.查看源碼
查看某個類的源碼
jad com.test.ClassA
查看某個類某個方法的源碼
jad com.test.ClassA 方法A
3.只查看源碼
jad --source-only com.test.ClassA
4.
六.查看具體函數
1.基礎使用示例:
sm com.test.ClassA
sm com.test.ClassA methodA
2.查看某個函數的詳細信息 加上屬性 -d
sm -d com.test.ClassA methodA
七.查看JVM已經加載的類信息
1.具體某個類的JVM加載信息 【如果它是接口,還會把實現類打印出來】
sc -d com.test.ClassA
2.正則匹配JVM加載類的信息
sc -d com.test.Class*
或者
sc -d com.test.*B
八.動態實時監控接口
1.動態實時監控接口出入參和異常信息 層級是3層,撈取5次請求
watch com.test.ClassA methodA '{params,returnObj,throwExp}' -v -n 5 -x 3 '1==1'
2.同上,但是指定入參的第二個參數等於true的
watch com.test.ClassA methodA '{params,returnObj,throwExp}' 'params[1] == true' -v -n 5 -x 3 '1==1'
3.
九.查看類的靜態成員變量
1.查看類的靜態成員變量 層級是3層
getstatic com.test.ClassA staticA -x 3
十.查看某個Spring管理的Bean的屬性值
1.監聽到攔截器請求的一個下標,得到一個數字
tt -t -n 1 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter invokeHandlerMethod
2.使用得到的下標進行替換,從上下文中獲取到該Bean,就可以執行該Bean的方法了
用得到的數字替換1002,taskExecutor就是bean的name, getBean("taskExecutor")之后就可以.該Bean提供的方法,或者直接查看該Bean的屬性值 taskExecutor 是舉例的一個Bean的name,可以是xxx,也可以是你自己的Bean的name
tt -i 1002 -w 'target.getApplicationContext().getBean("taskExecutor").getThreadPoolExecutor().getQueue().size()'
3.或者直接查看該Bean的屬性值,查看3層
tt -i 1002 -w 'target.getApplicationContext().getBean("taskExecutor")' -x 3
十一.