arthas跟踪代码-线上环境

1.下载arthas全量包

wget https://maven.aliyun.com/repository/public/com/taobao/arthas/arthas-packaging/3.1.1/arthas-packaging-3.1.1-bin.zip

2.上传至生产环境,解压

环境不同不再赘述

 

3.查看对应java/springboot服务的进程PID

ps -ef | grep  -v grep | grep 进程名称

 

4.对上传的arthas解压,

1.创建目录

# mkdir arthas

2.解压

unzip arthas-packaging-3.1.1-bin.zip  -d  arthas

3.执行as.sh  PID

5.进入arthas,启动 as.sh  时附带跟踪的进程PID

 

1.进入目录

cd arthas

2.执行as.sh

./as.sh  PID

3.查看命令

demo:  ./as.sh 24081

# ./as.sh 24081

Arthas script version: 3.1.1

[INFO] JAVA_HOME: /data/program/java8

[INFO] Process 24081 already using port 3658

[INFO] Process 24081 already using port 8563

Arthas home: /root/arthasdemo

Calculating attach execution time...

Attaching to 24081 using version /root/arthasdemo...

 

real 0m0.187s

user 0m0.372s

sys 0m0.085s

Attach success.

telnet connecting to arthas server... current timestamp is 1619318724

Trying 127.0.0.1...

Connected to 127.0.0.1.

Escape character is '^]'.

  ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.                           

 /  O  \ |  .--. ''--.  .--'|  '--'  | /  O  \ '   .-'                          

|  .-.  ||  '--'.'   |  |   |  .--.  ||  .-.  |`.  `-.                          

|  | |  ||  |\  \    |  |   |  |  |  ||  | |  |.-'    |                         

`--' `--'`--' '--'   `--'   `--'  `--'`--' `--'`-----'                          

                                                                                

 

wiki      https://alibaba.github.io/arthas                                      

tutorials https://alibaba.github.io/arthas/arthas-tutorials                     

version   3.1.1                                                                 

pid       24081                                                                 

time      2021-04-23 18:31:59                                                   

 

$ help

 NAME         DESCRIPTION                                                                                                         

 help         Display Arthas Help                                                                                                 

 keymap       Display all the available keymap for the specified connection.                                                      

 sc           Search all the classes loaded by JVM                                                                                

 sm           Search the method of classes loaded by JVM                                                                          

 classloader  Show classloader info                                                                                               

 jad          Decompile class                                                                                                     

 getstatic    Show the static field of a class                                                                                    

 monitor      Monitor method execution statistics, e.g. total/success/failure count, average rt, fail rate, etc.                  

 stack        Display the stack trace for the specified class and method                                                          

 thread       Display thread info, thread stack                                                                                   

 trace        Trace the execution time of specified method invocation.                                                            

 watch        Display the input/output parameter, return object, and thrown exception of specified method invocation              

 tt           Time Tunnel                                                                                                         

 jvm          Display the target JVM information                                                                                  

 ognl         Execute ognl expression.                                                                                            

 mc           Memory compiler, compiles java files into bytecode and class files in memory.                                       

 redefine     Redefine classes. @see Instrumentation#redefineClasses(ClassDefinition...)                                          

 dashboard    Overview of target jvm's thread, memory, gc, vm, tomcat info.                                                       

 dump         Dump class byte array from JVM                                                                                      

 options      View and change various Arthas options                                                                              

 cls          Clear the screen                                                                                                    

 reset        Reset all the enhanced classes                                                                                      

 version      Display Arthas version                                                                                              

 shutdown     Shutdown Arthas server and exit the console                                                                         

 session      Display current session information                                                                                 

 sysprop      Display, and change the system properties.                                                                          

 sysenv       Display the system env.                                                                                             

 history      Display command history                                                                                             

 cat          Concatenate and print files                                                                                         

 pwd          Return working directory name                                                                                       

 mbean        Display the mbean information                 

 

6.查看方法

6.1 查看方法入参、出参

$ watch com.wacai.cn.start.Process process "{params,returnObj}"  

Press Q or Ctrl+C to abort.

Affect(class-cnt:1 , method-cnt:1) cost in 50 ms.

ts=2021-04-25 10:42:15; [cost=1881.502545ms] result=@ArrayList[

    @Object[][isEmpty=false;size=1],

    @Integer[3],

]

ts=2021-04-25 10:42:19; [cost=1.565473ms] result=@ArrayList[

    @Object[][isEmpty=false;size=1],

    @Integer[1],

]

ts=2021-04-25 10:42:29; [cost=4236.004237ms] result=@ArrayList[

    @Object[][isEmpty=false;size=1],

    @Integer[9],

]

 

6.2.查看方法入参【具体参数值】

$ watch com.wacai.cn.start.Process process "{params}"  -x 3

Press Q or Ctrl+C to abort.

Affect(class-cnt:1 , method-cnt:1) cost in 49 ms.

ts=2021-04-25 10:43:30; [cost=5705.660437ms] result=@ArrayList[

    @Object[][

        @HashMap[

            @Long[1619318596]:@String[wacai/wdp/dw/trident.db/missile_user_profile_group_uid_list/user_group_id=17119/snapshot_partition=2021-04-25/part-00024],

            @Long[1619318597]:@String[wacai/wdp/dw/ods.db/ods_loan_gbl_gbl_call_record/dt=2021-04-23/000000_0],

            @Long[1619318598]:@String[wacai/wdp/dw/trident.db/missile_user_profile_group_uid_list/user_group_id=17119/snapshot_partition=2021-04-25/part-00037],

            @Long[1619318599]:@String[wacai/wdp/dw/ods.db/ods_loan_gbl_gbl_call_record/dt=2021-04-23/000002_0],

            @Long[1619318593]:@String[wacai/wdp/dw/trident.db/missile_user_profile_group_uid_list/user_group_id=17119/snapshot_partition=2021-04-25/part-00046],

            @Long[1619318600]:@String[wacai/wdp/dw/ods.db/ods_loan_gbl_gbl_call_record/dt=2021-04-23/000008_0],

        ],

    ],

]

6.3.查看方法出参【具体参数值】

$ watch com.wacai.cn.util.AuditUtil parseLogmessage "{returnObj}" -x 4

Press Q or Ctrl+C to abort.

Affect(class-cnt:1 , method-cnt:1) cost in 49 ms.

ts=2021-04-25 10:55:03; [cost=0.615616ms] result=@ArrayList[

    @HashMap[

        @String[dbTable]:@String[adm_pfm.adm_pfm_jz_vip_buy_stat_ds],

        @String[partName]:@String[dt=2021-02-28],

    ],

]

ts=2021-04-25 10:55:03; [cost=0.121708ms] result=@ArrayList[

    @HashMap[

        @String[dbTable]:@String[ods.ods_edu_edu_order],

        @String[partName]:@String[dt=2020-10-15],

    ],

]

ts=2021-04-25 10:55:03; [cost=0.091988ms] result=@ArrayList[

    @HashMap[

        @String[dbTable]:@String[ods.ods_edu_edu_order],

        @String[partName]:@String[dt=2020-11-17],

    ],

]

6.4.查看方法链路

$ trace com.wacai.cn.util.AuditUtil parseLogmessage 

Press Q or Ctrl+C to abort.

Affect(class-cnt:1 , method-cnt:1) cost in 88 ms.

`---ts=2021-04-25 10:58:07;thread_name=Thread-14;id=2c;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@4e25154f

    `---[0.840664ms] com.wacai.cn.util.AuditUtil:parseLogmessage()

        +---[0.209362ms] org.slf4j.Logger:info() #28

        +---[0.005873ms] java.util.HashMap:<init>() #29

        +---[min=0.001551ms,max=0.001852ms,total=0.003403ms,count=2] java.lang.Integer:<init>() #32

        +---[0.00212ms] java.lang.reflect.Method:invoke() #32

        +---[0.025045ms] java.lang.String:split() #32

        +---[0.005094ms] java.lang.StringBuilder:<init>() #34

        +---[0.01166ms] java.lang.String:split() #34

        +---[min=0.001493ms,max=0.009688ms,total=0.012733ms,count=3] java.lang.StringBuilder:append() #34

        +---[0.00509ms] java.lang.String:trim() #34

        +---[0.004068ms] java.lang.StringBuilder:toString() #34

        +---[0.008252ms] java.util.Map:put() #35

        +---[0.00786ms] java.lang.String:contains() #37

        +---[0.001843ms] java.lang.StringBuilder:<init>() #38

        +---[0.002368ms] java.lang.String:split() #39

        +---[min=0.00152ms,max=0.00158ms,total=0.0031ms,count=2] java.lang.String:contains() #40

        +---[0.001578ms] java.lang.StringBuilder:append() #41

        +---[0.001498ms] java.lang.StringBuilder:append() #42

        +---[0.00494ms] java.lang.StringBuilder:length() #45

        +---[0.016615ms] java.lang.StringBuilder:substring() #45

        `---[0.00156ms] java.util.Map:put() #45

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值