JVM异常诊断神器Greys实战 - 玩转JVM

Greys是一个JVM进程执行过程中的异常诊断神器。 在不中断程序执行的情况下轻松完成JVM相关问题排查工作。目前Greys仅支持Linux/Unix/Mac上的Java6+,Windows暂时无法支持。

使用场景

例如打logger,开发环境一般有五种情况:
1、异常情况,打error
2、警告情况,打warm
3、非本系统调用入口、任务等,logger入参和结果
4、本系统调用,debug入参和结果
5、必要信息,info一下

而在生产环境,一般不会开启debug日志。这时,出现问题如何debug?没错,用debug诊断神器Greys完美解决。

安装Greys

[root@mvxl52738 tmp]# curl -sLk http://ompc.oss.aliyuncs.com/greys/install.sh|bash
# or 
[root@mvxl52738 tmp]# wget http://ompc.oss.aliyuncs.com/greys/release/greys-stable-bin.zip
[root@mvxl52738 tmp]#  unzip greys-stable-bin.zip
[root@mvxl52738 tmp]# cd greys
[root@mvxl52738 tmp]# sh ./install-local.sh

启动关闭Greys

# ./greys.sh [@IP:PORT]
[root@mvxl52738 ]# greys.sh 57951
                                                        _                    
  ____  ____ _____ _   _  ___ _____ _____ ____  _____ _| |_ ___  ____  _   _ 
 / _  |/ ___) ___ | | | |/___|_____|____ |  _ \(____ (_   _) _ \|    \| | | |
( (_| | |   | ____| |_| |___ |     / ___ | | | / ___ | | || |_| | | | | |_| |
 \___ |_|   |_____)\__  (___/      \_____|_| |_\_____|  \__)___/|_|_|_|\__  |
(_____|           (____/                                              (____/ 
                                              +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                              |v|e|r|s|i|o|n|:|1|.|7|.|6|.|6|
                                              +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
ga?>help
# 查看帮助文档
ga?>shutdown
Greys Server is shut down.

远程连接Greys

远程连接,当然也是可以的。配置对应的ip和端口,就能远程协助了。

[root@mvxl52740 greys]# ./greys.sh @10.18.40.183:3658 
                                                        _                    
  ____  ____ _____ _   _  ___ _____ _____ ____  _____ _| |_ ___  ____  _   _ 
 / _  |/ ___) ___ | | | |/___|_____|____ |  _ \(____ (_   _) _ \|    \| | | |
( (_| | |   | ____| |_| |___ |     / ___ | | | / ___ | | || |_| | | | | |_| |
 \___ |_|   |_____)\__  (___/      \_____|_| |_\_____|  \__)___/|_|_|_|\__  |
(_____|           (____/                                              (____/ 
                                              +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                              |v|e|r|s|i|o|n|:|1|.|7|.|6|.|6|
                                              +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
ga?>
ga?>tt -t -n 3 *OrderReportFacadeImpl *
Press Ctrl+D to abort.
Affect(class-cnt:1 , method-cnt:12) cost in 68 ms.
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+
|    INDEX | PROCESS-ID |            TIMESTAMP |   COST(ms) |   IS-RET |   IS-EXP |          OBJECT |                          CLASS |                         METHOD |
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+
|     1003 |       1003 |  2018-09-15 17:40:24 |         14 |     true |    false |       0x68d36ec |          OrderReportFacadeImpl |            lambda$selectItem$3 |
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+
|     1004 |       1004 |  2018-09-15 17:40:24 |         15 |     true |    false |       0x68d36ec |          OrderReportFacadeImpl |                     selectItem |

常见用法

monitor命令

对匹配class-pattern/method-pattern的类.方法的调用进行监控。

ga?>monitor -c 5  *OrderReportFacadeImpl selectItem
+---------------------+------------------------------------------------------------+------------+-------+---------+------+-----------+------------+------------+------------+
| TIMESTAMP           | CLASS                                                      | METHOD     | TOTAL | SUCCESS | FAIL | FAIL-RATE | AVG-RT(ms) | MIN-RT(ms) | MAX-RT(ms) |
+---------------------+------------------------------------------------------------+------------+-------+---------+------+-----------+------------+------------+------------+
| 2018-09-15 14:55:08 | com.meicloud.ecu.fc.impl.facade.impl.OrderReportFacadeImpl | selectItem | 1     | 1       | 0    | 00.00%    | 22.00      | 22         | 22         |
+---------------------+------------------------------------------------------------+------------+-------+---------+------+-----------+------------+------------+------------+

+---------------------+------------------------------------------------------------+------------+-------+---------+------+-----------+------------+------------+------------+
| TIMESTAMP           | CLASS                                                      | METHOD     | TOTAL | SUCCESS | FAIL | FAIL-RATE | AVG-RT(ms) | MIN-RT(ms) | MAX-RT(ms) |
+---------------------+------------------------------------------------------------+------------+-------+---------+------+-----------+------------+------------+------------+
| 2018-09-15 14:55:13 | com.meicloud.ecu.fc.impl.facade.impl.OrderReportFacadeImpl | selectItem | 3     | 3       | 0    | 00.00%    | 11.67      | 11         | 13         |
+---------------------+------------------------------------------------------------+------------+-------+---------+------+-----------+------------+------------+------------+

trace和ptrace命令

渲染和统计整个调用链路上的所有性能开销和追踪调用链路。但是,动态代理好像追不进去。所以,Spring注入的调用追踪不了。

ga?>ptrace -t  *OrderReportFacadeImpl  *
Press Ctrl+D to abort.
Affect(class-cnt:1 , method-cnt:12) cost in 47 ms.
`---+pTracing for : thread_name="DubboServerHandler-10.18.40.183:20888-thread-21" thread_id=0x21e;is_daemon=true;priority=5;process=1003;
    `---+[36,36ms]com.meicloud.ecu.fc.impl.facade.impl.OrderReportFacadeImpl:selectLog(); index=1006;
        `---[33,17ms]com.meicloud.ecu.fc.impl.facade.impl.OrderReportFacadeImpl:lambda$selectLog$5(); index=1005;
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+
|    INDEX | PROCESS-ID |            TIMESTAMP |   COST(ms) |   IS-RET |   IS-EXP |          OBJECT |                          CLASS |                         METHOD |
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+
|     1005 |       1003 |  2018-09-15 15:03:54 |         16 |     true |    false |       0x68d36ec |          OrderReportFacadeImpl |             lambda$selectLog$5 |
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+
|     1006 |       1003 |  2018-09-15 15:03:54 |         20 |     true |    false |       0x68d36ec |          OrderReportFacadeImpl |                      selectLog |
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+

tt命令(重点掌握)

时间隧道命令记录下当时方法调用的所有入参和返回值、抛出的异常

# 记录下当前方法的每次调用环境现场
ga?>tt -t -n 3 *OrderReportFacadeImpl *
Press Ctrl+D to abort.
Affect(class-cnt:1 , method-cnt:12) cost in 70 ms.
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+
|    INDEX | PROCESS-ID |            TIMESTAMP |   COST(ms) |   IS-RET |   IS-EXP |          OBJECT |                          CLASS |                         METHOD |
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+
|     1008 |       1005 |  2018-09-15 16:49:28 |        189 |    false |     true |       0x68d36ec |          OrderReportFacadeImpl |            lambda$selectItem$3 |
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+
|     1009 |       1006 |  2018-09-15 16:49:28 |        192 |     true |    false |       0x68d36ec |          OrderReportFacadeImpl |                     selectItem |

ga?>tt -l
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+
|    INDEX | PROCESS-ID |            TIMESTAMP |   COST(ms) |   IS-RET |   IS-EXP |          OBJECT |                          CLASS |                         METHOD |
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+
|     1001 |       1001 |  2018-09-15 15:02:10 |         15 |     true |    false |       0x68d36ec |          OrderReportFacadeImpl |            lambda$selectItem$3 |
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+
|     1002 |       1001 |  2018-09-15 15:02:10 |         17 |     true |    false |       0x68d36ec |          OrderReportFacadeImpl |                     selectItem |
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+
|     1003 |       1002 |  2018-09-15 15:02:46 |         13 |     true |    false |       0x68d36ec |          OrderReportFacadeImpl |            lambda$selectItem$3 |
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+
|     1004 |       1002 |  2018-09-15 15:02:46 |         14 |     true |    false |       0x68d36ec |          OrderReportFacadeImpl |                     selectItem |
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+
|     1005 |       1003 |  2018-09-15 15:03:54 |         16 |     true |    false |       0x68d36ec |          OrderReportFacadeImpl |             lambda$selectLog$5 |
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+
|     1006 |       1003 |  2018-09-15 15:03:54 |         20 |     true |    false |       0x68d36ec |          OrderReportFacadeImpl |                      selectLog |
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+
|     1007 |       1004 |  2018-09-15 16:44:45 |         14 |     true |    false |       0x68d36ec |          OrderReportFacadeImpl |                   sendItem2SAP |
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+
|     1008 |       1005 |  2018-09-15 16:49:28 |        189 |    false |     true |       0x68d36ec |          OrderReportFacadeImpl |            lambda$selectItem$3 |
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+
|     1009 |       1006 |  2018-09-15 16:49:28 |        192 |     true |    false |       0x68d36ec |          OrderReportFacadeImpl |                     selectItem |
+----------+------------+----------------------+------------+----------+----------+-----------------+--------------------------------+--------------------------------+

# 查看调用信息
ga?>tt -i 1006 -x 3


# 查看异常信息
ga?>tt -i 1008 -x 3
+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
|           INDEX | 1008                                                                                                                                                   |
+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
|      PROCESS-ID | 1005                                                                                                                                                   |
+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
|      GMT-CREATE | 2018-09-15 16:49:28                                                                                                                                    |
+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
|        COST(ms) | 189                                                                                                                                                    |
+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
|          OBJECT | 0x68d36ec                                                                                                                                              |
+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
|           CLASS | com.meicloud.ecu.fc.impl.facade.impl.OrderReportFacadeImpl                                                                                             |
+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
|          METHOD | lambda$selectItem$3                                                                                                                                    |
+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
|       IS-RETURN | false                                                                                                                                                  |
+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
|    IS-EXCEPTION | true                                                                                                                                                   |
+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
|   PARAMETERS[0] | OrderReportRequest(reportId=null, reportIdList=null, orderSubId=null, orderId=null, shopIdList=[1], startTime=Mon Sep 03 16:49:15 CST 2018, endTime=Sa |
|                 | t Sep 15 16:49:20 CST 2018, clientIdList=null, skuTypeList=null, packingId=null, companyCodeList=null, salesTypeList=[], statusList=[], applyId=null,  |
|                 | exceptionType=0)                                                                                                                                       |
+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
|   PARAMETERS[1] | 0                                                                                                                                                      |
+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
|   PARAMETERS[2] | 10                                                                                                                                                     |
+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
|   PARAMETERS[3] | CommonResponse(result=null)                                                                                                                            |
+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
| THROW-EXCEPTION | org.springframework.jdbc.BadSqlGrammarException:                                                                                                       |
|                 | ### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'shop_id' in 'where clause'             |
|                 | ### The error may exist in file [/apps/zoomlion/ecu-fc-sales/tomcat-9008/webapps/fc-sales/WEB-INF/classes/sqlmaps/fcsqlmaps/custom/CustomOrderReportMa |
|                 | pper.xml]                                                                                                                                              |
|                 | ### The error may involve com.meicloud.ecu.fc.impl.model.dao.fc.custom.CustomOrderReportMapper.selectByEntity-Inline                                   |
|                 | ### The error occurred while setting parameters                                                                                                        |
|                 | ### SQL: SELECT  count(*)  FROM f_order_report AS item LEFT OUTER JOIN f_order_report_extend AS extend ON (item.report_id = extend.report_id) WHERE (( |
|                 | (1 = 1) AND (shop_id IN ( ? ))) AND (consign_time >= ( ? ))) AND (consign_time < ( ? ))                                                                |
|                 | ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'shop_id' in 'where clause'                                       |
|                 | ; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'shop_id' in 'where clause'        |
|                 |     at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:237)                    |
|                 |     at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)               |
|                 |     at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)                                  |
|                 |     at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)                                                 |
|                 |     at com.sun.proxy.$Proxy22.selectList(Unknown Source)                                                                                               |
|                 |     at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:198)                                                                   |
|                 |     at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119)                                                                    |
|                 |     at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)                                                                            |
|                 |     at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)                                                                               |
|                 |     at com.sun.proxy.$Proxy23.selectByEntity(Unknown Source)                                                                                           |
|                 |     at com.meicloud.ecu.fc.impl.service.impl.OrderReportServiceImpl.selectItem(OrderReportServiceImpl.java:224)                                        |
|                 |     at com.meicloud.ecu.fc.impl.service.impl.OrderReportServiceImpl$$FastClassBySpringCGLIB$$60343937.invoke()                              |
|                 |     at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)                                                                        |
|                 |     at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:629)                                     |
|                 |     at com.meicloud.ecu.fc.impl.service.impl.OrderReportServiceImpl$$EnhancerBySpringCGLIB$$9a3e9305.selectItem()                           |
|                 |     at com.meicloud.ecu.fc.impl.facade.impl.OrderReportFacadeImpl.lambda$selectItem$3(OrderReportFacadeImpl.java:122)                                  |
|                 |     at com.meicloud.ecu.fc.impl.utils.RespPackUtil.execInvokeService(RespPackUtil.java:31)                                                             |
|                 |     at com.meicloud.ecu.fc.impl.facade.impl.OrderReportFacadeImpl.selectItem(OrderReportFacadeImpl.java:121)                                           |
|                 |     at com.alibaba.dubbo.common.bytecode.Wrapper4.invokeMethod(Wrapper4.java)                                                                          |
|                 |     at com.alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:46)                                           |
|                 |     at com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:72)                                                           |
|                 |     at com.alibaba.dubbo.config.invoker.DelegateProviderMetaDataInvoker.invoke(DelegateProviderMetaDataInvoker.java:36)                                |
|                 |     at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:53)                                                                    |
|                 |     at com.alibaba.dubbo.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:64)                                                                    |
|                 |     at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)                                                    |
|                 |     at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75)                                                                   |
|                 |     at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)                                                    |
|                 |     at com.alibaba.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:42)                                                                        |
|                 |     at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)                                                    |
|                 |     at com.alibaba.dubbo.rpc.protocol.dubbo.filter.TraceFilter.invoke(TraceFilter.java:78)                                                             |
|                 |     at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)                                                    |
|                 |     at com.alibaba.dubbo.rpc.filter.ContextFilter.invoke(ContextFilter.java:61)                                                                        |
|                 |     at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)                                                    |
|                 |     at com.alibaba.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:132)                                                                       |
|                 |     at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)                                                    |
|                 |     at com.alibaba.dubbo.rpc.filter.ClassLoaderFilter.invoke(ClassLoaderFilter.java:38)                                                                |
|                 |     at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)                                                    |
|                 |     at com.alibaba.dubbo.rpc.filter.EchoFilter.invoke(EchoFilter.java:38)                                                                              |
|                 |     at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)                                                    |
|                 |     at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:98)                                                               |
|                 |     at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:98)                           |
|                 |     at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:170)                               |
|                 |     at com.alibaba.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:52)                                                              |
|                 |     at com.alibaba.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:81)                                          |
|                 |     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)                                                                 |
|                 |     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)                                                                 |
|                 |     at java.lang.Thread.run(Thread.java:748)                                                                                                           |
|                 | Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'shop_id' in 'where clause'                                       |
|                 |     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)                                                                           |
|                 |     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)                                                    |
|                 |     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)                                            |
|                 |     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)                                                                                 |
|                 |     at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)                                                                                            |
|                 |     at com.mysql.jdbc.Util.getInstance(Util.java:384)                                                                                                  |
|                 |     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)                                                                                  |
|                 |     at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4232)                                                                                      |
|                 |     at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4164)                                                                                      |
|                 |     at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615)                                                                                           |
|                 |     at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)                                                                                        |
|                 |     at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2838)                                                                                 |
|                 |     at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)                                                                   |
|                 |     at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1307)                                                                           |
|                 |     at sun.reflect.GeneratedMethodAccessor99.invoke(Unknown Source)                                                                                    |
|                 |     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                                                           |
|                 |     at java.lang.reflect.Method.invoke(Method.java:498)                                                                                                |
|                 |     at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:62)                                                  |
|                 |     at com.sun.proxy.$Proxy59.execute(Unknown Source)                                                                                                  |
|                 |     at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:59)                                           |
|                 |     at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:73)                                             |
|                 |     at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:60)                                                                       |
|                 |     at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)                                                                |
|                 |     at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)                                                                            |
|                 |     at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)                                                                       |
|                 |     at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77)                                                                       |
|                 |     at sun.reflect.GeneratedMethodAccessor97.invoke(Unknown Source)                                                                                    |
|                 |     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                                                           |
|                 |     at java.lang.reflect.Method.invoke(Method.java:498)                                                                                                |
|                 |     at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)                                                                                 |
|                 |     at com.github.pagehelper.PageHelper.intercept(PageHelper.java:211)                                                                                 |
|                 |     at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:60)                                                                                          |
|                 |     at com.sun.proxy.$Proxy56.query(Unknown Source)                                                                                                    |
|                 |     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)                                                     |
|                 |     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)                                                     |
|                 |     at sun.reflect.GeneratedMethodAccessor163.invoke(Unknown Source)                                                                                   |
|                 |     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                                                           |
|                 |     at java.lang.reflect.Method.invoke(Method.java:498)                                                                                                |
|                 |     at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)                                                 |
|                 |     ... 43 more                                                                                                                                        |
+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
|           STACK | thread_name="DubboServerHandler-10.18.40.183:20888-thread-39" thread_id=0x239;is_daemon=true;priority=5;                                               |
|                 |     @com.meicloud.ecu.fc.impl.facade.impl.OrderReportFacadeImpl.lambda$selectItem$3(OrderReportFacadeImpl.java:124)                                    |
|                 |         at com.meicloud.ecu.fc.impl.utils.RespPackUtil.execInvokeService(RespPackUtil.java:31)                                                         |
|                 |         at com.meicloud.ecu.fc.impl.facade.impl.OrderReportFacadeImpl.selectItem(OrderReportFacadeImpl.java:121)                                       |
|                 |         at com.alibaba.dubbo.common.bytecode.Wrapper4.invokeMethod(Wrapper4.java:-1)                                                                   |
|                 |         at com.alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:46)                                       |
|                 |         at com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:72)                                                       |
|                 |         at com.alibaba.dubbo.config.invoker.DelegateProviderMetaDataInvoker.invoke(DelegateProviderMetaDataInvoker.java:36)                            |
|                 |         at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:53)                                                                |
|                 |         at com.alibaba.dubbo.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:64)                                                                |
|                 |         at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)                                                |
|                 |         at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75)                                                               |
|                 |         at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)                                                |
|                 |         at com.alibaba.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:42)                                                                    |
|                 |         at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)                                                |
|                 |         at com.alibaba.dubbo.rpc.protocol.dubbo.filter.TraceFilter.invoke(TraceFilter.java:78)                                                         |
|                 |         at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)                                                |
|                 |         at com.alibaba.dubbo.rpc.filter.ContextFilter.invoke(ContextFilter.java:61)                                                                    |
|                 |         at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)                                                |
|                 |         at com.alibaba.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:132)                                                                   |
|                 |         at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)                                                |
|                 |         at com.alibaba.dubbo.rpc.filter.ClassLoaderFilter.invoke(ClassLoaderFilter.java:38)                                                            |
|                 |         at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)                                                |
|                 |         at com.alibaba.dubbo.rpc.filter.EchoFilter.invoke(EchoFilter.java:38)                                                                          |
|                 |         at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)                                                |
|                 |         at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:98)                                                           |
|                 |         at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:98)                       |
|                 |         at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:170)                           |
|                 |         at com.alibaba.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:52)                                                          |
|                 |         at com.alibaba.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:81)                                      |
|                 |         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)                                                             |
|                 |         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)                                                             |
|                 |         at java.lang.Thread.run(Thread.java:748)                                                                                                       |
+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+



# 重跑一次。
# 当你少少做了一些调整之后,你可能需要前端系统重新触发一次你的调用,此时得求爷爷告奶奶的需要前端配合联调的同学再次发起一次调用。而有些场景下,这个调用不是这么好触发的。
# tt命令由于保存了当时调用的所有现场信息,所以我们可以自己主动对一个INDEX编号的时间片自主发起一次调用,从而解放你的沟通成本。此时你需要-p参数。
ga?>tt -i 1006 -p

watch命令(tt命令已经包含了它)

能方便的让你观察到指定方法的调用情况。能观察到的范围为:返回值、抛出异常、入参,通过编写OGNL表达式进行对应变量的查看。

表达式核心变量

public class Advice {

    // 本次调用类所在的ClassLoader 
    private final ClassLoader loader; 
    // 本次调用类的Class引用
    private final Class clazz;
    // 本次调用方法反射引用
    private final GaMethod method;
    // 本次调用类的实例
    private final Object target;
    // 本次调用参数列表,这是一个数组,如果方法是无参方法则为空数组
    private final Object[] params;
    // 本次调用返回的对象。当且仅当isReturn==true成立时候有效,
    // 表明方法调用是以正常返回的方式结束。
    // 如果当前方法无返回值void,则值为null
    private final Object returnObj;
    // 本次调用抛出的异常。当且仅当isThrow==true成立时有效,
    // 表明方法调用是以抛出异常的方式结束。
    private final Throwable throwExp;
    private final boolean isBefore;
    private final boolean isThrow;
    private final boolean isReturn;

    // getter/setter  
}  

stack命令 (tt命令已经包含了它)

很多时候我们都知道一个方法被执行,但这个方法被执行的路径非常多。或者你根本就不知道这个方法是从那里被执行了,正在郁闷,正在彷徨。此时你需要的是stack命令。

详情参考:https://github.com/oldmanpushcart/greys-anatomy

你可能感兴趣的:(JVM异常诊断神器Greys实战 - 玩转JVM)