生产调试工具:Arthas 使用笔记

文章目录

简介

ArthasAlibaba 在 2018 年 9 月开源的 Java 诊断工具。支持 JDK6+, 采用命令行交互模式,提供 Tab 自动补全,可以方便的定位和诊断线上程序运行问题。

开源地址:https://github.com/alibaba/arthas

官方文档:https://arthas.aliyun.com/doc/

安装

安装分为全量安装和非全量安装,非全量安装会在第一次使用时自动下载依赖。

首先介绍全量安装方式:

  1. 安装zip和unzip

    [root@localhost ~]# yum install -y zip unzip
    
  2. 下载全量安装包

    [root@localhost ~]# wget https://maven.aliyun.com/repository/public/com/taobao/arthas/arthas-packaging/3.3.6/arthas-packaging-3.3.6-bin.zip
    
  3. 解压安装包

    [root@localhost ~]# unzip arthas-packaging-3.3.6-bin.zip -d /usr/local/arthas
    
  4. 启动

    [root@localhost ~]# cd /usr/local/arthas/
    [root@localhost arthas]# java -jar arthas-boot.jar 
    [INFO] arthas-boot version: 3.3.6
    [INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
    
    * [1]: 42405 qixi-emp-1.0-SNAPSHOT.jar
      1
      [INFO] arthas home: /usr/local/arthas
      [INFO] Try to attach process 42405
      [INFO] Attach process 42405 success.
      [INFO] arthas-client connect 127.0.0.1 3658
      ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.                           
       /  O  \ |  .--. ''--.  .--'|  '--'  | /  O  \ '   .-'                          
      |  .-.  ||  '--'.'   |  |   |  .--.  ||  .-.  |`.  `-.                          
      |  | |  ||  |\  \    |  |   |  |  |  ||  | |  |.-'    |                         
      `--' `--'`--' '--'   `--'   `--'  `--'`--' `--'`-----'                          
                                                                                    
    
    wiki      https://alibaba.github.io/arthas                                      
    tutorials https://alibaba.github.io/arthas/arthas-tutorials                     
    version   3.3.6                                                                 
    pid       42405                                                                 
    time      2020-07-15 13:26:58
    
    [arthas@42405]$ 
    

使用

dashboard: 概览程序的 线程、内存、GC、运行环境信息

thread: 查看所有线程信息

thread 12: 查看线程id为12的线程信息

thread -b: 查找死锁

sc: 查看已加载的类的信息

# 查看信息
[arthas@17178]$ sc com.qixi.emp.controller.EmpController 

# 查看类的详细信息
[arthas@17178]$ sc -d com.qixi.emp.controller.EmpController

# 支持模糊搜索
[arthas@17178]$ sc com.qixi.emp.controller.*

# 查看类的字段信息
[arthas@30154]$ sc -d -f com.qixi.emp.controller.EmpController

jad: 反编译类的信息

[arthas@17178]$ jad com.qixi.emp.controller.EmpController 

ognl: 执行ognl表达式

官网说明:https://alibaba.github.io/arthas/ognl.html#ognl

示例:

# 调用静态函数(调用之后输出了方法的返回值)
[arthas@30154]$ ognl '@java.lang.System@out.println("Hello World")'
null

getstatic: 查看类的静态属性的值

[arthas@30154]$ getstatic com.qixi.arthas.service.impl.TestServiceImpl hashSet

heapdump: 把堆导出成一个文件

​ 然后就可以用java的图形化分析工具分析这个文件了

Java提供了jmap命令可到类似效果:

例如:

jmap -histo [pid] | head -20

查看占内存最高的对象类型(列出前20行)慎重使用,会导出堆内存,堆内存大的时候会使生产环境卡顿很久。

jmap -dump:live,format=b,file=pid.hprof [pid]
将java内存堆栈导出为一个文件

redefine: 热替换class

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值