首页   快速返回

arthas watch 使用     所属分类 arthas 浏览量 84
https://alibaba.github.io/arthas/watch                                                                                           


watch -h

 USAGE:                                                                                                                             
   watch [-b] [-e] [-x $value] [-f] [-h] [-n $value] [-E] [-M $value] [-s] class-pattern method-pattern express [condition-expre 
 ss]                                                                                                                                
                                                                                                                                    
 SUMMARY:                                                                                                                           
   Display the input/output parameter, return object, and thrown exception of specified method invocation                           
   The express may be one of the following expression (evaluated dynamically):                                                      
           target : the object                                                                                                      
            clazz : the object's class                                                                                              
           method : the constructor or method                                                                                       
           params : the parameters array of method                                                                                  
     params[0..n] : the element of parameters array                                                                                 
        returnObj : the returned object of method                                                                                   
         throwExp : the throw exception of method                                                                                   
         isReturn : the method ended by return                                                                                      
          isThrow : the method ended by throwing exception                                                                          
            #cost : the execution time in ms of method invocation                                                                   
 Examples:                                                                                                                          
   watch -b org.apache.commons.lang.StringUtils isBlank params                                                                      
   watch -f org.apache.commons.lang.StringUtils isBlank returnObj                                                                   
   watch org.apache.commons.lang.StringUtils isBlank '{params, target, returnObj}' -x 2                                             
   watch -bf *StringUtils isBlank params                                                                                            
   watch *StringUtils isBlank params[0]                                                                                             
   watch *StringUtils isBlank params[0] params[0].length==1                                                                         
   watch *StringUtils isBlank params '#cost>100'                                                                                    
   watch -E -b org\.apache\.commons\.lang\.StringUtils isBlank params[0]                                                            
                                                                                                                                    
 WIKI:                                                                                                                              
   https://alibaba.github.io/arthas/watch                                                                                           
                                                                                                                                    
 OPTIONS:                                                                                                                           
 -b, --before                                Watch before invocation                                                                
 -e, --exception                             Watch after throw exception                                                            
 -x, --expand                          Expand level of object (1 by default)                                                  
 -f, --finish                                Watch after invocation, enable by default                                              
 -h, --help                                  this help                                                                              
 -n, --limits                          Threshold of execution times   最大执行次数
                                                         
 -E, --regex                                 Enable regular expression to match (wildcard matching by default)                      
 -M, --sizeLimit                     Upper size limit in bytes for the result (10 * 1024 * 1024 by default)                 
 -s, --success                               Watch after successful invocation                                                      
  class-pattern                             The full qualified class name you want to watch                                        
  method-pattern                            The method name you want to watch                                                      
  express                                 the content you want to watch, written by ognl.                                        
                                             Examples:                                                                              
                                               params                                                                               
                                               params[0]                                                                            
                                               'params[0]+params[1]'                                                                
                                               '{params[0], target, returnObj}'                                                     
                                               returnObj                                                                            
                                               throwExp                                                                             
                                               target                                                                               
                                               clazz                                                                                
                                               method                                                                               
                                                                                                                                    
 condition-express                         Conditional expression in ognl style, for example:                                     
                                               TRUE  : 1==1                                                                         
                                               TRUE  : true                                                                         
                                               FALSE : false                                                                        
                                               TRUE  : 'params.length>=0'                                                           
                                               FALSE : 1==2                                                                         
                                                              
                                                              
                                                              
OGNL  Object Graph Navigation Language


方法执行数据观测
观察指定方法的调用情况。 返回值、抛出异常、入参,通过编写 OGNL 表达式进行相应变量的查看。
 
watch 命令定义了4个观察事件点,即 -b 方法调用前,-e 方法异常后,-s 方法返回后,-f 方法结束后
4个观察事件点 -b、-e、-s 默认关闭,-f 默认打开,当指定观察点被打开后,在相应事件点会对观察表达式进行求值并输出

 
watch demo.MathGame primeFactors "{params[0],throwExp}" -e -x 2

-e 抛出异常时才触发

watch demo.MathGame primeFactors '{params, returnObj}' '#cost>200' -x 2

#cost>200(单位ms) 耗时大于200ms时才会输出 

watch demo.MathGame primeFactors 'target'

target 当前对象 查看当前对象中的属性 

watch demo.MathGame primeFactors 'target.illegalArgumentCount'


-x 参数说明
-x, --expand                          Expand level of object (1 by default)  

public static void run(HttpServletRequest request, Map< String, Object> context) throws Exception {
http://127.0.0.1:8080/api.jsp?error=&msg=hello


watch dyyx.util.WebUtil run '{params[1],throwExp}' 

ts=2020-01-03 12:05:08; [cost=1.150441ms] result=@ArrayList[
    @TreeMap[isEmpty=false;size=2],
    null,
]



-x 2  可看到map里具体的值

watch dyyx.util.WebUtil run '{params[1],throwExp}' -x 2

ts=2020-01-03 12:05:16; [cost=0.66692ms] result=@ArrayList[
    @TreeMap[
        @String[result]:@String[hello],
        @String[type]:@String[echo],
    ],
    null,
]


异常观察
http://127.0.0.1:8080/api.jsp?error=error&msg=hello
watch dyyx.util.WebUtil run '{params[1],throwExp}' -x 2

ts=2020-01-03 12:06:31; [cost=0.201315ms] result=@ArrayList[
    @TreeMap[
        @String[type]:@String[echo],
    ],
    java.lang.RuntimeException: error
	at dyyx.util.WebUtil.run_echo(WebUtil.java:343)
	at dyyx.util.WebUtil.run(WebUtil.java:297)
	at org.apache.jsp.api_jsp._jspService(api_jsp.java:51)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:428)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
	at org.eclipse.jetty.server.Server.handle(Server.java:370)
	at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)
	at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:971)
	at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1033)
	at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)
	at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
	at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:667)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
	at java.lang.Thread.run(Thread.java:745)
,
]

上一篇     下一篇
zookeeper使用场景

arthas使用

编程心法

arthas tt 使用

arthas OGNL 使用

zookeeper内部原理