知识库
并发编程
  • 分类
  • 标签
  • 归档
友情连接

luoliang

吾生也有涯,知也无涯
并发编程
  • 分类
  • 标签
  • 归档
友情连接
  • 类加载子系统
  • JVM的整体结构
  • JVM的垃圾回收
  • arthas排查问题
    • 简介
    • 使用技巧
      • 安装IDEA插件
      • 反编译操作 jad
      • watch
      • trace
      • thread 排查线程问题
      • dashboard
  • jvm
weiluoliang
2024-04-12
目录

arthas排查问题

# 简介

1.arthas可以帮助你定位性能问题:某个方法很慢,你想知道方法中调用各子方法的耗时,2.假如你怀疑运维是否发布了最新版本的代码到生产环境,那么arthas的jad命令可以直接反编译某个类,即可确认跑的代码是不是你最新的代码。

官方文档地址: https://arthas.aliyun.com/

# 使用技巧

# 安装IDEA插件

命令太多了,有了IDEA插件,使用更高效

Settings ---> plugins ---> 搜索 : arthas idea

使用的方式: 在类中点击鼠标右键

# 反编译操作 jad

你可以反编译一个类,也可以只反编译一个类中的某个方法。

  1. 编译一个类,在idea中某个类上操作

获得一个命令:

jad --source-only com.xxx.xxx.app.xxx.xxx.service.impl.AgentStatisticsExportServiceImpl 
1
  • jad : 反编译命令

  • --source-only : 只打印出来的代码,不

  • xxx.AgentStatisticsExportServiceImpl 指定要编译的类

在机器上去执行该命令

# 1. 下载 arthas-boot.jar
curl -O https://arthas.aliyun.com/arthas-boot.jar
# 2. 启动 arthas-boot.jar
java -jar arthas-boot.jar
# 找到你的程序 
1
2
3
4
5

我这里的是 【12】,控制台输入 12 ,即可进入当前的进程

12
[INFO] arthas home: /root/.arthas/lib/3.7.2/arthas
[INFO] Try to attach process 6479
[INFO] Attach process 6479 success.
[INFO] arthas-client connect 127.0.0.1 3658
  ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.                           
 /  O  \ |  .--. ''--.  .--'|  '--'  | /  O  \ '   .-'                          
|  .-.  ||  '--'.'   |  |   |  .--.  ||  .-.  |`.  `-.                          
|  | |  ||  |\  \    |  |   |  |  |  ||  | |  |.-'    |                         
`--' `--'`--' '--'   `--'   `--'  `--'`--' `--'`-----'                          

wiki       https://arthas.aliyun.com/doc                                        
tutorials  https://arthas.aliyun.com/doc/arthas-tutorials.html                  
version    3.7.2                                                                
main_class                                                                      
pid        6479                                                                 
time       2024-04-12 14:03:33                                                  

[arthas@6479]$ jad --source-only xxx.AgentStatisticsAggrServiceImpl 
反编译结果: 略..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

# watch

查看方法的入参和返回值

watch demo.MathGame primeFactors -x 2

Affect(class count: 1 , method count: 1) cost in 91 ms, listenerId: 1
method=demo.MathGame.primeFactors location=AtExceptionExit
ts=2024-04-12 14:58:58; [cost=1.454144ms] result=@ArrayList[
    @Object[][
        @Integer[-31968],
    ],
    @MathGame[
        random=@Random[java.util.Random@7eda2dbb],
        illegalArgumentCount=@Integer[64],
    ],
    null,
]
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# trace

查看方法执行路径并统计耗时

[arthas@31382]$ trace demo.MathGame run

Affect(class count: 1 , method count: 1) cost in 54 ms, listenerId: 2
`---ts=2024-04-12 15:00:12;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@70dea4e
    `---[0.398429ms] demo.MathGame:run()
        `---[17.46% 0.069566ms ] demo.MathGame:primeFactors() #24 [throws Exception]

1
2
3
4
5
6
7

# thread 排查线程问题

# 查看最繁忙的三个线程 
thread -n 3 

# 查看指定线程的堆栈 thread id 
 thread 20  
 
# thread -i, 指定采样时间间隔
thread -n 3 -i 1000   # 列出 1000ms 内最忙的 3 个线程栈
 
# thread -b, 找出当前阻塞其他线程的线程
thread -b 
1
2
3
4
5
6
7
8
9
10
11

# dashboard

当前系统的实时数据面板, 线程,内存,运行环境,数据实时更新

[arthas@31382]$ dashboard  
1
上次更新: 2024/04/22, 10:37:52
JVM的垃圾回收

← JVM的垃圾回收

最近更新
01
Linux常用命令
09-04
02
SpringBoot启动脚本
08-31
03
安装监控grafana
08-30
更多文章>
Theme by Vdoing | Copyright © 2022-2024 Evan Xu | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式