天天看點

Arthas watch指令使用

目錄

屬性周遊深度

1、watch 類全限定名 方法名:周遊深度為1的入參、對象、傳回資訊

2、watch 類全限定名 方法名 -x n:觀察周遊深度為n的入參、對象、傳回資訊

觀察事件點

1、watch 類全限定名 方法名 params -x 2 -b:在方法調用前觀察入參

2、watch 類全限定名 方法名 returnObj -x 2 -s:在方法傳回後觀察傳回值

3、watch 類全限定名 方法名 '{params,throwExp}' -e -x 2:觀察異常資訊

條件表達式過濾

1、watch 類全限定名 方法名 params[0] "params[0]<0"

2、watch 類全限定名 方法名 params 'params.length==1'

3、watch 類全限定名 方法名 "{params,returnObj}" "params[0].equals('XXX')"

格式:watch 類全限定名 方法名 觀察表達式 條件表達式

可以觀察到的資訊:方法入參、方法傳回值、抛出的異常資訊、調用方法的對象

觀察表達式:預設{params, target, returnObj}

觀察事件點

-b 方法調用前(觀察入參時,方法中可能會有修改入參的操作)

-s 方法傳回後

-e 方法抛出異常後

jad demo.MathGame檢視源代碼

Arthas watch指令使用

屬性周遊深度

1、watch 類全限定名 方法名:周遊深度為1的入參、對象、傳回資訊

watch demo.MathGame primeFactors

x 預設為1,等價于 watch demo.MathGame primeFactors -x 1

Arthas watch指令使用

2、watch 類全限定名 方法名 -x n:觀察周遊深度為n的入參、對象、傳回資訊

Arthas watch指令使用
Arthas watch指令使用

觀察事件點

1、watch 類全限定名 方法名 params -x 2 -b:在方法調用前觀察入參

觀察表達式:單個值可以不加"{}",多個值需要加"{a,b,c}"。

Arthas watch指令使用

因為觀察事件點為-b方法調用前,是以傳回值或異常均不存在

Arthas watch指令使用

2、watch 類全限定名 方法名 returnObj -x 2 -s:在方法傳回後觀察傳回值

Arthas watch指令使用

3、watch 類全限定名 方法名 '{params,throwExp}' -e -x 2:觀察異常資訊

-e 方法抛出異常時才會有觸發輸出

Arthas watch指令使用

條件表達式過濾

1、watch 類全限定名 方法名 params[0] "params[0]<0"

過濾出入參<0時的入參

Arthas watch指令使用

2、watch 類全限定名 方法名 params 'params.length==1'

過濾出入參長度=1時的入參

Arthas watch指令使用

3、watch 類全限定名 方法名 "{params,returnObj}" "params[0].equals('XXX')"

過濾出字元串參數的請求

eg:擷取使用者資訊方法

觀察使用者名為“張三”的請求:watch com.zm.MyTest getUser "{params,returnObj}" "params[0].equals('張三')" -x 2

觀察使用者ID為9的請求:watch com.zm.MyTest getUser "{params,returnObj}" "params[1]==9" -x 2

private User getUser(String name, Integer id){};