侧边栏壁纸
  • 累计撰写 58 篇文章
  • 累计创建 67 个标签
  • 累计收到 1 条评论

Arthas 常用命令

lihaocheng
2022-07-07 / 0 评论 / 0 点赞 / 1,011 阅读 / 522 字
温馨提示:
晚上记得开启夜间模式哦

一、安装、启动

1. 下载 jar 启动

官方下载

java -jar arthas-boot.jar

二、常用命令

1.dashboard

可以查看面板
arthas1

2.thread 线程

SUMMARY:                                                                                                                                                                      
   Display thread info, thread stack                                                                                                                                           
                                                                                                                                                                               
 EXAMPLES:                                                                                                                                                                     
   thread                                                                                                                                                                      
   thread 51                                                                                                                                                                   
   thread -n -1                                                                                                                                                                
   thread -n 5                                                                                                                                                                 
   thread -b
   //                                                                                                                                                                   
   thread -i 2000     
   //状态为 BLOCKED 的线程                                                                                                                                                         
   thread --state BLOCKED                                                                                                                                                      
                                                                                                                                                                               
 WIKI:                                                                                                                                                                         
   https://arthas.aliyun.com/doc/thread                                                                                                                                        
                                                                                                                                                                               
 OPTIONS:                                                                                                                                                                      
     --all                                                 Display all thread results instead of the first page                                                                
 -h, --help                                                this help                                                                                                           
 -b, --include-blocking-thread                             Find the thread who is holding a lock that blocks the most number of threads.                                       
     --lockedMonitors                                      Find the thread info with lockedMonitors flag, default value is false.                                              
     --lockedSynchronizers                                 Find the thread info with lockedSynchronizers flag, default value is false.                                         
 -i, --sample-interval <value>                             Specify the sampling interval (i案例了n ms) when calculating cpu usage.                                                   
     --state <value>                                       Display the thead filter by the state. NEW, RUNNABLE, TIMED_WAITING, WAITING, BLOCKED, TERMINATED is optional.      
 -n, --top-n-threads <value>                               The number of thread(s) to show, ordered by cpu utilization, -1 to show all.                                        
 <id>                                                      Show thread stack          

3.JVM

jvm

4. jad 反编译

例如反编译 com.lhc 包下的 TestController.java

jad com.lhc.TestController

就可以得到反编译结果

5.watch

watch com.lhc.TestController download

watch 可以很直观的看出某个方法中每个地方的执行时间。
例如在排查某个接口/方法慢的时候,可以使用 watch 来找出时间占用最长的地方。

6.monitor 监控

monitor -c 5 com.lhc.TestController download

monitor 提供了 失败率、平均 RT 两个关键指标
arthas2

7.trace 调用追踪

哪些方法调用到了这个函数?

trace com.lhc.TestController download

如果只想找到一个,可以加 -n 1 参数

trace com.lhc.TestController download -n 1

默认情况下,trace 不会包含 jdk 里的函数调用,如果希望 trace jdk 里的函数,需要显式设置 --skipJDKMethod false

8.热更新 retransform

加载编译之后的 class 文件。
这里需要注意,新函数是不支持热更新的。

9.火焰图

开始采样 --event 用于指定要采样的事件,默认对 CPU 采样

profiler start --event alloc

停止采样

profiler stop

继续采样

profiler resume

三、其他

Arthas 学习非常推荐通过案例进行学习,官方也提供了案例.

0

评论区