arthas的安装和使用小结

本文介绍了如何在Linux和Windows上安装arthas,包括下载、解压和运行步骤。此外,详细讲解了arthas的常用命令,如watch、jad、trace、thread、sc、monitor、getstatic、sysprop、redefine、stack和tt,这些命令用于方法监控、性能分析、调试和系统属性修改。arthas作为局部调试工具,与VisualVM互补,更专注于细粒度的调试和问题排查。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一.1.Linux下载安装arthas
     https://blog.youkuaiyun.com/minicto/article/details/82906220
     tar -zvxf arthas.tar.gz 
     cd arthas
     ./install-local.sh 
  
   2.windows下载安装arthas
     https://alibaba.github.io/arthas/install-detail.html#arthas-boot
     解压
     java -jar arthas-boot.jar
     选择一个需要监控的进程ID回车
  
   注意事项: 只支持jdk6(+) 以上版本,否则下面命令执行不成功
  
二.命令使用
    1.示例代码
    package com.arthas;
    import java.util.UUID;
    public class Test {
        /**
        *
        * @return
        */
       public static String uuid(){
          return UUID.randomUUID().toString().replaceAll("-", "");
       }

       public static void main(String[] args) {

           while(true){
               System.out.println("uuid = " + uuid()); 
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
       } 
    }

    2.watch 
      watch -f com.arthas.Test uuid returnObj   查看方法uuid的返回值(可以实时看到此方法的返回值)
      watch -f com.arthas.Test uuid params
      watch -f com.arthas.Test uuid "params,returnObj" "params[0].equals('wangwei')" -x 3 -b  满足条件才打印(-b(调用前)、 -e(异常时)、-s(返回后)、-f(结束后))
      
    3.jad
      jad com.arthas.Test 反编译Test.class并实时显示

    4.trace
      trace com.arthas.Test uuid  监控uuid方法内部所有方法的执行效率(可以列出内部各方法执行时间,并且支持设置条件打印,如耗时超过某值、入参是某值时等等)
      trace com.arthas.Test uuid #cost>100 只打印内部方法执行耗时超过100毫秒的方法
      
    5.thread
      thread 查看线程的CPU占比

    6.sc sm 快速搜索类和方法信息
      sc *.Test    
    
    7.monitor 监测方法的调用次数、成功次数等
      monitor -c 10 com.arthas.Test uuid  统计10秒内uuid方法被调用的次数,成功失败次数等
      
    8.getstatic *.Checker pool  //注意,查不到常量
      9.sysprop java.version 1.7baba  修改系统属性
    10.redefine——加载外部的.class文件,redefine到JVM里 
    11.stack com.arthas.Test uuid 查看当前方法的调用路径
    12.tt——方法执行数据的时空隧道,记录下指定方法每次调用的入参和返回信息,并能对这些不同的时间下调用进行观测 
    
总结一下就是:
     VisualVM和Arthas可以相辅相成,前者更像一个全局监测官,监控整体运作情况!
     而后者更像一个局部调试官,可监测方法,甚至可细化到方法执行前后的参数等,所以它更常用于调试排查!    
    
    
    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值