arthas 用法

  • java -jar arthas-boot.jar  启动  选择需要监控的pid编号
  • dashboard  可以查看线程,内存,GC,以及Runtime信息
    ID                     NAME                                                               GROUP                                        PRIORITY               STATE                 %CPU                   TIME                  INTERRUPTED            DAEMON                
    162                    Timer-for-arthas-dashboard-50e06196-7685-4d1f-aadd-d93f6c90fb1a    system                                       10                     RUNNABLE              35                     0:0                   false                  true                  
    54                     TaskAcceptor-127.0.0.1                                       eurekaTaskExecutors                          5                      TIMED_WAITING         11                     0:7                   false                  true                  
    65                     SimplePauseDetectorThread_1                                        main                                         5                      TIMED_WAITING         10                     0:6                   false                  true                  
    66                     SimplePauseDetectorThread_2                                        main                                         5                      TIMED_WAITING         10                     0:6                   false                  true                  
    64                     SimplePauseDetectorThread_0                                        main                                         5                      TIMED_WAITING         8                      0:6                   false                  true                  
    32                     TaskAcceptor-target_127.0.0.1                                eurekaTaskExecutors                          5                      TIMED_WAITING         7                      0:6                   false                  true                  
    18                     SimplePauseDetectorThread_0                                        system                                       9                      TIMED_WAITING         1                      0:0                   false                  true                  
    44                     TaskBatchingWorker-target_127.0.0.1-10                       eurekaTaskExecutors                          5                      TIMED_WAITING         1                      0:0                   false                  true                  
    45                     TaskBatchingWorker-target_127.0.0.1-11                       eurekaTaskExecutors                          5                      TIMED_WAITING         1                      0:0                   false                  true                  
    47                     TaskBatchingWorker-target_127.0.0.1-13                       eurekaTaskExecutors                          5                      TIMED_WAITING         1                      0:0                   false                  true                  
    50                     TaskBatchingWorker-target_127.0.0.1-16                       eurekaTaskExecutors                          5                      TIMED_WAITING         1                      0:0                   false                  true                  
    51                     TaskBatchingWorker-target_127.0.0.1-17                       eurekaTaskExecutors                          5                      TIMED_WAITING         1                      0:0                   false                  true                  
    52                     TaskBatchingWorker-target_127.0.0.1-18                       eurekaTaskExecutors                          5                      TIMED_WAITING         1                      0:0                   false                  true                  
    53                     TaskBatchingWorker-target_127.0.0.1-19                       eurekaTaskExecutors                          5                      TIMED_WAITING         1                      0:0                   false                  true                  
    39                     TaskBatchingWorker-target_127.0.0.1-5                        eurekaTaskExecutors                          5                      TIMED_WAITING         1                      0:0                   false                  true                  
    41                     TaskBatchingWorker-target_127.0.0.1-7                        eurekaTaskExecutors                          5                      TIMED_WAITING         1                      0:0                   false                  true                  
    42                     TaskBatchingWorker-target_127.0.0.1-8                        eurekaTaskExecutors                          5                      TIMED_WAITING         1                      0:0                   false                  true                  
    19                     Abandoned connection cleanup thread                                main                                         5                      TIMED_WAITING         0                      0:0                   false                  true                  
    88                     Attach Listener                                                    system                                       9                      RUNNABLE              0                      0:0                   false                  true                  
    23                     ContainerBackgroundProcessor[StandardEngine[Tomcat]]               main                                         5                      TIMED_WAITING         0                      0:0                   false                  true                  
    87                     DestroyJavaVM                                                      main                                         5                      RUNNABLE              0                      0:8                   false                  false                 
    57                     Eureka-CacheFillTimer                                              main                                         5                      TIMED_WAITING         0                      0:0                   false                  true                  
    26                     Eureka-DeltaRetentionTimer                                         main                                         5                      TIMED_WAITING         0                      0:0                   false                  true                  
    27                     Eureka-EvictionTimer                                               main                                         5                      TIMED_WAITING         0                      0:0                   false                  true                  
    31                     Eureka-JerseyClient-Conn-Cleaner2                                  main                                         5                      TIMED_WAITING         0                      0:0                   false                  true                  
    28                     Eureka-MeasureRateTimer                                            main                                         5                      TIMED_WAITING         0                      0:0                   false                  true                  
    30                     Eureka-MeasureRateTimer                                            main                                         5                      TIMED_WAITING         0                      0:0                   false                  true                  
    56                     Eureka-PeerNodesUpdater                                            main                                         5                      TIMED_WAITING         0                      0:0                   false                  true                  
    3                      Finalizer                                                          system                                       8                      WAITING               0                      0:0                   false                  true                  
    99                     HikariPool-1 housekeeper                                           main                                         5                      TIMED_WAITING         0                      0:0                   false                  true                  
    Memory                                                    used               total              max                 usage              GC                                                                                                                                     
    heap                                                      52M                187M               267M                19.54%             gc.ps_scavenge.count                                                79                                                                 
    ps_eden_space                                             6M                 78M                96M                 6.38%              gc.ps_scavenge.time(ms)                                             732                                                                
    ps_survivor_space                                         0K                 512K               512K                0.00%              gc.ps_marksweep.count                                               40                                                                 
    ps_old_gen                                                46M                108M               200M                23.03%             gc.ps_marksweep.time(ms)                                            6671                                                               
    nonheap                                                   103M               115M               -1                  89.95%                                                                                                                                                    
    code_cache                                                14M                22M                240M                5.91%                                                                                                                                                     
    metaspace                                                 79M                82M                -1                  96.25%                                                                                                                                                    
    compressed_class_space                                    10M                10M                1024M               1.01%                                                                                                                                                     
    direct                                                    80K                80K                -                   100.00%                                                                                                                                                   
    mapped                                                    0K                 0K                 -                   NaN%                                                                                                                                                      
                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                  
    Runtime                                                                                                                                                                                                                                                                       
    os.name                                                                                                                                Linux                                                                                                                                  
    os.version                                                                                                                             2.6.32-431.el6.x86_64                                                                                                                  
    java.version                                                                                                                           1.8.0_65                                                                                                                               
    java.home                                                                                                                              /opt/jdk1.8.0_65/jre                                                                                                                   
    systemload.average                                                                                                                     0.00                                                                                                                                   
    processors                                                                                                                             8                                                                                                                                      
    uptime                                                                                                                                 4395s                   
  • jad home.spring.boot.demo.ControllerDemo    反编译工具

  •  watch home.spring.boot.demo.ControllerDemo print "{params,returnObj,throwExp,target}" > /Data/logs/w.log &   

    ts=2020-06-05 14:42:40; [cost=5.958944ms] result=@ArrayList[
        @Object[][isEmpty=false;size=1],
        null,
        @NullPointerException[java.lang.NullPointerException: id is invalid],
        @ControllerDemo[home.spring.boot.demo.ControllerDemo@20f5281c],
    ]
    ts=2020-06-05 14:42:41; [cost=6.750126ms] result=@ArrayList[
        @Object[][isEmpty=false;size=1],
        null,
        @NullPointerException[java.lang.NullPointerException: id is invalid],
        @ControllerDemo[home.spring.boot.demo.ControllerDemo@20f5281c],
    ]
    ts=2020-06-05 14:42:41; [cost=5.961589ms] result=@ArrayList[
        @Object[][isEmpty=false;size=1],
        null,
        @NullPointerException[java.lang.NullPointerException: id is invalid],
        @ControllerDemo[home.spring.boot.demo.ControllerDemo@20f5281c],
    ]
    ts=2020-06-05 14:42:44; [cost=9.147448ms] result=@ArrayList[
        @Object[][isEmpty=false;size=1],
        @String[hello SpringBoot!],
        null,
        @ControllerDemo[home.spring.boot.demo.ControllerDemo@20f5281c],
    ]
    
  • tt -t home.spring.boot.demo.ControllerDemo print -n 10 > /Data/logs/test.log &

    Affect(class count: 1 , method count: 1) cost in 72 ms, listenerId: 4
     INDEX            TIMESTAMP                                 COST(ms)             IS-RET          IS-EXP           OBJECT                         CLASS                                                          METHOD
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     1010             2020-06-05 13:57:29                       45.979413            false           true             0x20f5281c                     ControllerDemo                                                 print
     1011             2020-06-05 13:57:29                       16.911348            false           true             0x20f5281c                     ControllerDemo                                                 print
     1012             2020-06-05 13:57:29                       7.881976             false           true             0x20f5281c                     ControllerDemo                                                 print
     1013             2020-06-05 13:57:29                       6.822336             false           true             0x20f5281c                     ControllerDemo                                                 print
     1014             2020-06-05 13:57:29                       7.321216             false           true             0x20f5281c                     ControllerDemo                                                 print
     1015             2020-06-05 13:57:29                       9.011788             false           true             0x20f5281c                     ControllerDemo                                                 print
     1016             2020-06-05 13:57:30                       9.791365             false           true             0x20f5281c                     ControllerDemo                                                 print
     1017             2020-06-05 13:57:30                       7.251141             false           true             0x20f5281c                     ControllerDemo                                                 print
     1018             2020-06-05 13:57:30                       7.149456             false           true             0x20f5281c                     ControllerDemo                                                 print
     1019             2020-06-05 13:57:30                       7.756823             false           true             0x20f5281c                     ControllerDemo                                                 print
    Command execution times exceed limit: 10, so command will exit. You can set it with -n option.
    
  •  tt --play -i 1019   回放上面的统计的细节信息

    [arthas@19358]$ tt --play -i 1019
     RE-INDEX         1019                                                                                                                                                                                                                                                        
     GMT-REPLAY       2020-06-05 14:46:10                                                                                                                                                                                                                                         
     OBJECT           0x20f5281c                                                                                                                                                                                                                                                  
     CLASS            home.spring.boot.demo.ControllerDemo                                                                                                                                                                                                                        
     METHOD           print                                                                                                                                                                                                                                                       
     PARAMETERS[0]    @String[8]                                                                                                                                                                                                                                                  
     IS-RETURN        false                                                                                                                                                                                                                                                       
     IS-EXCEPTION     true                                                                                                                                                                                                                                                        
     THROW-EXCEPTION  java.lang.NullPointerException: id is invalid                                                                                                                                                                                                               
                      	at home.spring.boot.demo.ControllerDemo.print(ControllerDemo.java:87)                                                                                                                                                                                      
                      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                                                                                                                                                                                             
                      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)                                                                                                                                                                           
                      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                                                                                                                                                                   
                      	at java.lang.reflect.Method.invoke(Method.java:497)                                                                                                                                                                                                        
                      	at com.taobao.arthas.core.advisor.ArthasMethod.invoke(ArthasMethod.java:156)                                                                                                                                                                               
                      	at com.taobao.arthas.core.command.monitor200.TimeTunnelCommand.processPlay(TimeTunnelCommand.java:481)                                                                                                                                                     
                      	at com.taobao.arthas.core.command.monitor200.TimeTunnelCommand.process(TimeTunnelCommand.java:280)                                                                                                                                                         
                      	at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.process(AnnotatedCommandImpl.java:82)                                                                                                                                                    
                      	at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.access$100(AnnotatedCommandImpl.java:18)                                                                                                                                                 
                      	at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:111)                                                                                                                                     
                      	at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:108)                                                                                                                                     
                      	at com.taobao.arthas.core.shell.system.impl.ProcessImpl$CommandProcessTask.run(ProcessImpl.java:372)                                                                                                                                                       
                      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)                                                                                                                                                                                 
                      	at java.util.concurrent.FutureTask.run(FutureTask.java:266)                                                                                                                                                                                                
                      	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)                                                                                                                                   
                      	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)                                                                                                                                          
                      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)                                                                                                                                                                         
                      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)                                                                                                                                                                         
                      	at java.lang.Thread.run(Thread.java:745)
  • trace工具来统计各步骤调用的耗时

    [arthas@19358]$ trace home.spring.boot.demo.ControllerDemo print
    Press Q or Ctrl+C to abort.
    Affect(class count: 1 , method count: 1) cost in 113 ms, listenerId: 8
    `---ts=2020-06-05 14:47:22;thread_name=http-nio-1111-exec-2;id=49;is_daemon=true;priority=5;TCCL=org.springframework.boot.web.embedded.tomcat.TomcatEmbeddedWebappClassLoader@4c548fbf
        `---[-5.869706408793622E9ms] home.spring.boot.demo.ControllerDemo:print()
            `---[-5.869706411278678E9ms] home.spring.boot.demo.ControllerDemo$1:<init>() #54
                `---[-5.869706411593806E9ms] home.spring.boot.service.mybatis.MybaitisService:findById() #70
                    `---[-5.86970643135107E9ms] home.spring.boot.redis.RedisService:setKey() #79
                        `---[2.043958ms] home.spring.boot.event.EventPublishService:eventPublish() #90

    trace com.ytao.service.UserServiceImpl getUser '#cost > 1'   过滤总耗时小于1毫秒的记录
  • redefine 实现热部署

    [arthas@19358]$ sc -d *ControllerDemo
     class-info        home.spring.boot.demo.ControllerDemo                                                                                                                                                                                                                       
     code-source       file:/home/dev/boot.test-1.0-SNAPSHOT.jar!/BOOT-INF/classes!/                                                                                                                                                                                              
     name              home.spring.boot.demo.ControllerDemo                                                                                                                                                                                                                       
     isInterface       false                                                                                                                                                                                                                                                      
     isAnnotation      false                                                                                                                                                                                                                                                      
     isEnum            false                                                                                                                                                                                                                                                      
     isAnonymousClass  false                                                                                                                                                                                                                                                      
     isArray           false                                                                                                                                                                                                                                                      
     isLocalClass      false                                                                                                                                                                                                                                                      
     isMemberClass     false                                                                                                                                                                                                                                                      
     isPrimitive       false                                                                                                                                                                                                                                                      
     isSynthetic       false                                                                                                                                                                                                                                                      
     simple-name       ControllerDemo                                                                                                                                                                                                                                             
     modifier          public                                                                                                                                                                                                                                                     
     annotation        org.springframework.web.bind.annotation.RestController                                                                                                                                                                                                     
     interfaces                                                                                                                                                                                                                                                                   
     super-class       +-java.lang.Object                                                                                                                                                                                                                                         
     class-loader      +-org.springframework.boot.loader.LaunchedURLClassLoader@37bba400                                                                                                                                                                                          
                         +-sun.misc.Launcher$AppClassLoader@33909752                                                                                                                                                                                                              
                           +-sun.misc.Launcher$ExtClassLoader@59470966                                                                                                                                                                                                            
     classLoaderHash   37bba400      
    
    上述命令获取 classLoaderHash
    
    redefine -c 37bba400 /Data/logs/ControllerDemo.class

    redefine 会有局限性  增加代码的时候可能会报下面的异常

[arthas@19358]$ redefine -c 37bba400 /Data/logs/Metrics.class 
redefine error! java.lang.UnsupportedOperationException: class redefinition failed: attempted to add a method

猜你喜欢

转载自blog.csdn.net/ma_ru_long/article/details/106570228