我的arthas使用学习过程

我的arthas使用学习过程

在我的aliyun服务器安装jdk

#3.安装 JDK
yum install -y java-1.8.0-openjdk*

后台运行demo程序

nohup java -jar math-game.jar > log.file 2>&1 &

# 上面的2 和 1 的意思如下:
0    标准输入(一般是键盘)
1    标准输出(一般是显示屏,是用户终端控制台)
2    标准错误(错误信息输出)

将运行的jar 错误日志信息输出到log.file文件中,然后(>&1)就是继续输出到标准输出(前面加的&,是为了让系统识别是标准输出),最后一个&,表示在后台运行。

下载arthas

curl -O https://arthas.aliyun.com/arthas-boot.jar

运行arthas

java -jar arthas-boot.jar

运行后控制台会列出现在在跑的进程:
[INFO] arthas-boot version: 3.6.1
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 12588 math-game.jar
备注:
执行该程序(arthas-boot.jar)的用户需要和目标进程(math-game.jar)具有相同的权限
如果attach不上目标进程,可以查看~/logs/arthas/ 目录下的日志

这里我们输入1,按回车,让arthas关联该进程12588

使用1:查看仪表盘

dashboard 查看仪表盘(包含内存信息,线程信息等,系统变量信息等)
按ctrl+c可以中断执行

ID NAME                GROUP     PRIORI STATE %CPU   DELTA TIME   INTER DAEMON 
49 Timer-for-arthas-da system    5      RUNNA 0.32   0.015 0:0.01 false true   
-1 C1 CompilerThread1  -         -1     -     0.28   0.014 0:2.39 false true   
-1 C2 CompilerThread0  -         -1     -     0.23   0.011 0:2.78 false true   
-1 VM Periodic Task Th -         -1     -     0.08   0.004 0:1.94 false true   
47 arthas-NettyHttpTel system    5      RUNNA 0.06   0.003 0:0.11 false true   
1  main                main      5      TIMED 0.02   0.000 0:0.79 false false  
-1 VM Thread           -         -1     -     0.01   0.000 0:0.63 false true   
2  Reference Handler   system    10     WAITI 0.0    0.000 0:0.00 false true   
3  Finalizer           system    8      WAITI 0.0    0.000 0:0.00 false true   

Memory           used  total max  usage GC                                     
heap             44M   84M   419M       gc.copy.count       20                 
eden_space       9M    23M   115M 8.53% gc.copy.time(ms)    206                
survivor_space   0K    2944K 1478 0.00% gc.marksweepcompact 3                  
                             4K         .count                                 
tenured_gen      35M   58M   289M       gc.marksweepcompact 233                
nonheap          47M   50M   -1         .time(ms)                              
code_cache       6M    8M    240M 2.87%  

Runtime                                                                        
os.name                                 Linux                                  
os.version                              3.10.0-957.21.3.el7.x86_64  

使用2:查看线程堆栈

输入thread 1 查看线程id为1的线程堆栈

[arthas@12588]$ thread 1 
"main" Id=1 TIMED_WAITING
    at java.lang.Thread.sleep(Native Method)
    at java.lang.Thread.sleep(Thread.java:342)
    at java.util.concurrent.TimeUnit.sleep(TimeUnit.java:386)
    at demo.MathGame.main(MathGame.java:17)

使用3:反编译线上代码

jad demo.MathGame

// demo.MathGame是全限定类名

使用4:通过watch来查看函数执行的返回值

watch demo.MathGame primeFactors returnObj

退出Arthas

quit或exit退出当前连接

使用4:通过watch来查看函数执行的返回值

watch demo.MathGame primeFactors returnObj

退出Arthas

quit或exit退出当前连接

stop完全退出arthas

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值