使用阿里开源的工具Arthas打印堆栈日志,需要下载jar包 arthas-boot.jar。
- 启动Java应用程序。
- 启动jar包 arthas-boot.jar。
- 选择要监控的进程。
- 运行命令监控想要查看调用链的方法。格式:stack 包名.类名 方法名。
- 让程序跑起来,可以看到这个方法的调用链。
$ java -jar arthas-boot.jar
[INFO] arthas-boot version: 3.6.6
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 18240 org.jetbrains.idea.maven.server.RemoteMavenServer36
[2]: 2672 org.jetbrains.jps.cmdline.Launcher
[3]: 20276
[4]: 18888 spring.orm.withXML.MainClass
[5]: 20488
[6]: 20968 C:\Users\lixiaomeng\.arthas\lib\3.6.6\arthas\arthas-core.jar
[7]: 2348 C:\Users\lixiaomeng\.arthas\lib\3.6.6\arthas\arthas-core.jar
4
[INFO] arthas home: C:\Users\lixiaomeng\.arthas\lib\3.6.6\arthas
[INFO] Try to attach process 18888
stack org.springframework.orm.hibernate3.HibernateAccessor flushIfNecessary
[INFO] Attach process 18888 success.
[INFO] arthas-client connect 127.0.0.1 3658
,---. ,------. ,--------.,--. ,--. ,---. ,---.
/ O \ | .--. ''--. .--'| '--' | / O \ ' .-'
| .-. || '--'.' | | | .--. || .-. |`. `-.
| | | || |\ \ | | | | | || | | |.-' |
`--' `--'`--' '--' `--' `--' `--'`--' `--'`-----'
wiki https://arthas.aliyun.com/doc
tutorials https://arthas.aliyun.com/doc/arthas-tutorials.html
version 3.6.6
main_class
pid 18888
time 2022-11-07 21:05:00
IfNecessary88]$ stack org.springframework.orm.hibernate3.HibernateAccessor flush
Press Q or Ctrl+C to abort.
Affect(class count: 2 , method count: 1) cost in 130 ms, listenerId: 1
ts=2022-11-07 21:05:02;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@18b4aac2
@org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary()
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:407)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:339)
at spring.orm.withXML.dao.EmployeeDaoImpl.save(EmployeeDaoImpl.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-2)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at com.sun.proxy.$Proxy21.save(null:-1)
at spring.orm.withXML.MainClass.main(MainClass.java:33)
ts=2022-11-07 21:05:02;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@18b4aac2
@org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary()
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:407)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:912)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:904)
at spring.orm.withXML.dao.EmployeeDaoImpl.getAllEmployee(EmployeeDaoImpl.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-2)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at com.sun.proxy.$Proxy21.getAllEmployee(null:-1)
at spring.orm.withXML.MainClass.main(MainClass.java:35)
session (89ba3d4b-ac1f-4db8-8325-4078f5849137) is closed because server is going to shutdown.
注意
java -jar arthas-boot.jar 在运行过程中需要下载依赖到 用户目录/.arthas 文件夹,因此在无法联网的情况下可以先把依赖包下载好放到文件夹下面。