阿里巴巴 arthas教程3

本文介绍:watch的使用

7.watch命令

watch命令,在排查复线线上问题时非常有效。

1. 监控com.runlion.fsp.credit.service.impl.CreditServiceImpl 类的listCreditAndUserOnCondition方法返回值,及方法耗时:

$ watch com.runlion.fsp.credit.service.impl.CreditServiceImpl listCreditAndUserOnCondition returnObj 

然后就会阻塞状态,线上排查问题时,这时就可以去重新触发此方法,查看返回值信息

$ watch com.runlion.fsp.credit.service.impl.CreditServiceImpl listCreditAndUserOnCondition returnObj 
Press Q or Ctrl+C to abort.
Affect(class-cnt:2 , method-cnt:2) cost in 203 ms.
ts=2019-09-03 19:14:48; [cost=364.531509ms] result=@FspPageInfo[
    pageNum=@Integer[1],
    pageSize=@Integer[20],
    total=@Long[234],
    pages=@Integer[12],
    result=@Page[isEmpty=false;size=20],
]
ts=2019-09-03 19:14:48; [cost=403.969714ms] result=@FspPageInfo[
    pageNum=@Integer[1],
    pageSize=@Integer[20],
    total=@Long[234],
    pages=@Integer[12],
    result=@Page[isEmpty=false;size=20],
]

显然,整个结果我们并不满意,我们想看人能读懂的数据。

watch有多个参数:
阿里巴巴 arthas教程3_第1张图片

2. 我们注意最后一个,指定属性遍历深度,刚才的遍历深度没有指定,默认为1,所以没有具体到数据,我们设置为3看一下:

$ watch com.runlion.fsp.credit.service.impl.CreditServiceImpl listCreditAndUserOnCondition returnObj -x 3
$ watch com.runlion.fsp.credit.service.impl.CreditServiceImpl listCreditAndUserOnCondition returnObj -x 3
Press Q or Ctrl+C to abort.
Affect(class-cnt:2 , method-cnt:2) cost in 205 ms.
ts=2019-09-03 19:21:37; [cost=419.18139ms] result=@FspPageInfo[
    pageNum=@Integer[1],
    pageSize=@Integer[20],
    total=@Long[234],
    pages=@Integer[12],
    result=@Page[
        @CreditDetailVo[
            creditId=@String[CRED19090300001871],
            userName=@String[15995055310],
            realName=@String[溧阳市神马机电设备安装有限公司],
            phone=@String[15995055310],
            userProp=@Integer[1],
            userPropStr=@String[供应商],
            userType=@Integer[1],
            userTypeStr=@String[企业],
            productId=@String[LPRO19080800000001],
            productName=@String[自助贷],
            relatedCompanyName=@String[漳平红狮水泥有限公司],
            moneyResourceOrganizationName=null,
            creditTotal=@BigDecimal[46800.00],
            creditUsed=@BigDecimal[0.00],
            creditResidue=@BigDecimal[42545.45],
            deleted=@Integer[0],
            deletedStr=@String[正常],
            gmtCreate=@Date[2019-09-03 16:56:41,000],
            channelUserName=@String[20500030],
        ],
        @CreditDetailVo[
            creditId=@String[CRED19090300001872],
            userName=@String[15995055310],
            realName=@String[溧阳市神马机电设备安装有限公司],
            phone=@String[15995055310],
            userProp=@Integer[1],
            userPropStr=@String[供应商],
            userType=@Integer[1],
            userTypeStr=@String[企业],
            productId=@String[LPRO19080800000002],
            productName=@String[应收账款质押贷],
            relatedCompanyName=@String[漳平红狮水泥有限公司],
            moneyResourceOrganizationName=null,
            creditTotal=@BigDecimal[46800.00],
            creditUsed=@BigDecimal[0.00],
            creditResidue=@BigDecimal[42545.45],
            deleted=@Integer[0],
            deletedStr=@String[正常],
            gmtCreate=@Date[2019-09-03 16:56:41,000],
            channelUserName=@String[20500030],
        ],

3. 我们同时监控入参和出参:

页面请求时设置startTimeF和endTimeF两个参数,然后监控结果:

$ watch com.runlion.fsp.credit.service.impl.CreditServiceImpl listCreditAndUserOnCondition "{params,returnObj}" -x 3
$ watch com.runlion.fsp.credit.service.impl.CreditServiceImpl listCreditAndUserOnCondition "{params,returnObj}" -x 3
Press Q or Ctrl+C to abort.
Affect(class-cnt:2 , method-cnt:2) cost in 183 ms.
ts=2019-09-03 19:29:58; [cost=336.416578ms] result=@ArrayList[
    @Object[][
        @CreditDto[
            creditId=null,
            realName=null,
            phone=null,
            relatedCompanyName=null,
            productId=null,
            deleted=null,
            startTimeF=@Date[2019-08-01 00:00:00,000],
            endTimeF=@Date[2019-09-30 23:59:59,000],
            pageNum=@Integer[1],
            pageSize=@Integer[20],
        ],
    ],
    @FspPageInfo[
        pageNum=@Integer[1],
        pageSize=@Integer[20],
        total=@Long[58],
        pages=@Integer[3],
        result=@Page[
            @CreditDetailVo[CreditDetailVo(creditId=CRED19090300001872, userName=15995055310, realName=溧阳市神马机电设备安装有限公司, phone=15995055310, userProp=1, userPropStr=供应商, userType=1, userTypeStr=企业, productId=LPRO19080800000002, productName=应收账款质押贷, relatedCompanyName=漳平红狮水泥有限公司, moneyResourceOrganizationName=null, creditTotal=46800.00, creditUsed=0.00, creditResidue=42545.45, deleted=0, deletedStr=正常, gmtCreate=Tue Sep 03 16:56:41 CST 2019, channelUserName=20500030)],
            @CreditDetailVo[CreditDetailVo(creditId=CRED19090300001871, userName=15995055310, realName=溧阳市神马机电设备安装有限公司, phone=15995055310, userProp=1, userPropStr=供应商, userType=1, userTypeStr=企业, productId=LPRO19080800000001, productName=自助贷, relatedCompanyName=漳平红狮水泥有限公司, moneyResourceOrganizationName=null, creditTotal=46800.00, creditUsed=0.00, creditResidue=42545.45, deleted=0, deletedStr=正常, gmtCreate=Tue Sep 03 16:56:41 CST 2019, channelUserName=20500030)]
 

4. 观察当前对象中的属性

$ watch com.runlion.fsp.credit.service.impl.CreditServiceImpl listCreditAndUserOnCondition "target" -x 3
Press Q or Ctrl+C to abort.
Affect(class-cnt:2 , method-cnt:2) cost in 189 ms.
ts=2019-09-03 19:34:52; [cost=313.479341ms] result=@CreditServiceImpl[
    log=@Logger[
        serialVersionUID=@Long[5454405123156820674],
        FQCN=@String[ch.qos.logback.classic.Logger],
        name=@String[com.runlion.fsp.credit.service.impl.CreditServiceImpl],
        level=null,
        effectiveLevelInt=@Integer[20000],
        parent=@Logger[
            serialVersionUID=@Long[5454405123156820674],
            FQCN=@String[ch.qos.logback.classic.Logger],
            name=@String[com.runlion.fsp.credit.service.impl],
            level=null,
            effectiveLevelInt=@Integer[20000],
            parent=@Logger[Logger[com.runlion.fsp.credit.service]],
            childrenList=@CopyOnWriteArrayList[isEmpty=false;size=5],
            aai=null,
            additive=@Boolean[true],
            loggerContext=@LoggerContext[ch.qos.logback.classic.LoggerContext[default]],
        ],
        childrenList=null,
        aai=null,
        additive=@Boolean[true],

阿里巴巴 arthas教程3_第2张图片
更具体的watch使用信息,可参考:https://github.com/alibaba/arthas/blob/master/site/src/site/sphinx/watch.md

你可能感兴趣的:((12)...工具相关,(14)...插件)