概述
使用场景介绍(常用总结)
1.展示当前最忙的前N个线程并打印堆栈
[arthas@106752]$ thread -n 3
"System Clock" Id=17 cpuUsage=2.02% deltaTime=4ms time=20590539ms TIMED_WAITING on java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@28a1bb09
at sun.misc.Unsafe.park(Native Method)
- waiting on java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@28a1bb09
....
"arthas-command-execute" Id=142 cpuUsage=0.87% deltaTime=1ms time=10225ms RUNNABLE
at sun.management.ThreadImpl.dumpThreads0(Native Method)
at sun.management.ThreadImpl.getThreadInfo(ThreadImpl.java:448)
at com.taobao.arthas.core.command.monitor200.ThreadCommand.processTopBusyThreads(ThreadCommand.java:199)
...
2.找出当前阻塞其他线程的线程(只支持synchronized)
有时候我们发现应用卡住了, 通常是由于某个线程拿住了某个锁, 并且其他线程都在等待这把锁造成的。
为了排查这类问题, arthas提供了thread -b, 一键找出那个罪魁祸首
[arthas@106752]$ thread -b
No most blocking thread found!
3.查看当前JVM信息
[arthas@106752]$ jvm
THREAD
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
COUNT(JVM当前活跃的线程数) 98
DAEMON-COUNT(JVM当前活跃的守护线程数) 56
PEAK-COUNT(从JVM启动开始曾经活着的最大线程数) 102
STARTED-COUNT(从JVM启动开始总共启动过的线程次数) 135
DEADLOCK-COUNT(JVM当前死锁的线程数) 0
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FILE-DESCRIPTOR
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
MAX-FILE-DESCRIPTOR-COUNT(JVM进程最大可以打开的文件描述符数) 65535
OPEN-FILE-DESCRIPTOR-COUNT(JVM当前打开的文件描述符数)
4.线上反编译
[arthas@106752]$jad com.secusoft.xxxx.service.impl.xxxxxServiceImpl
ClassLoader:
+-org.springframework.boot.loader.LaunchedURLClassLoader@47f37ef1
+-sun.misc.Launcher$AppClassLoader@18b4aac2
+-sun.misc.Launcher$ExtClassLoader@445b84c0
Location:
file:/root/web/xxxx/xxxx-2.1.2-SNAPSHOT.jar!/BOOT-INF/classes!/
public String xxxxxx(String id, String type, int localPort) {
/*165*/ String url = "";
xxxxDto xxxdto = this.xxxMapper.getById(id);
/*168*/ if (xxxdto != null) {
/*169*/ url = this.checkHlsUtis.convertPlayUrl(id, type);
}
/*172*/ return url;
}
5.输出当前方法被调用的调用路径
[arthas@106752]$ stack com.secusoft.xxxx.service.impl.xxxxxServiceImpl xxxxxx
Press Q or Ctrl+C to abort.
Affect(class count: 3 , method count: 3) cost in 459 ms, listenerId: 23
ts=2021-03-27 14:24:57;thread_name=http-nio-8009-exec-1;id=3c;is_daemon=true;priority=5;TCCL=org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedWebappClassLoader@13658f29
@com.secusoft.xxxx.service.impl.xxxxxServiceImpl.xxxxxx()
at com.secusoft.xxxx.service.impl.xxxxxServiceImpl$$FastClassBySpringCGLIB$$9f40ac0c.invoke(<generated>:-1)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
....
ts=2021-03-27 14:24:57;thread_name=http-nio-8009-exec-1;id=3c;is_daemon=true;priority=5;TCCL=org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedWebappClassLoader@13658f29
@com.secusoft.xxxx.service.impl.xxxxxServiceImpl$$EnhancerBySpringCGLIB$$bc4fd5c7.xxxxxx()
at com.secusoft.xxxx.service.impl.xxxxxServiceImpl$$FastClassBySpring
....
at com.secusoft.xxxx.service.impl.xxxxxServiceImpl$$EnhancerBySpringCGLIB$$ab6177ed.xxxxxx(<generated>:25)
at com.secusoft.xxxx.controller.xxxController.getUrl(xxxController.java:413)
at com.secusoft.xxxx.controller.xxxController$$FastClassBySpringCGLIB$$1eecdca2.invoke(<generated>:-1)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
6.诊断线上方法执行异常 对入参结果监控
watch 监控起流核心方法 xxxxxx
[arthas@19715]$ watch com.secusoft.xxxx.service.impl.xxxxxServiceImpl xxxxxx "{params,returnObj}" -x 2
Press Q or Ctrl+C to abort.
Affect(class count: 3 , method count: 1) cost in 413 ms, listenerId: 4
method=com.secusoft.xxxx.service.impl.xxxxxServiceImpl.xxxxxx location=AtExit
ts=2021-03-24 15:43:38; [cost=1042.500795ms] result=@ArrayList[
@Object[][
@xxxxVO[xxxxVO{appId='125412', id='34020000001320000127', type=''}],
],
@String[55Camera 08],
]
7.诊断线上方法执行过慢诊断
trace 根据起流方法判断耗时
[arthas@19715]$ trace com.secusoft.xxxx.service.impl.xxxxxServiceImpl xxxxxx
Press Q or Ctrl+C to abort.
Affect(class count: 3 , method count: 1) cost in 659 ms, listenerId: 5
`---ts=2021-03-24 15:47:04;thread_name=stream-control-%dpool-20-thread-10;id=86e;is_daemon=false;priority=5;TCCL=org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedWebappClassLoader@aaf1e32
`---[1092.334566ms] com.secusoft.xxxx.service.impl.xxxxxServiceImpl:xxxxxx()
+---[0.032045ms] com.secusoft.xxxx.model.vo.xxxxVO:getxxx() #378
+---[0.04669ms] com.secusoft.xxxx.model.vo.xxxxVO:getxxx() #379
+---[2.411973ms] com.secusoft.xxxx.mapper.CatalogMapper:selectOne() #382
+---[0.83488ms] com.secusoft.xxxx.mapper.xxxMapper:getxxxByxxx() #385
+---[0.021067ms] com.secusoft.xxxx.model.vo.xxxxVO:getTime() #387
+---[0.014321ms] com.secusoft.xxxx.model.vo.xxxxVO:getType() #388
+---[0.033491ms] com.secusoft.xxxx.model.vo.xxxxVO:getLocalPort() #389
+---[0.020003ms] com.secusoft.xxxx.model.vo.xxxxVO:getxxx() #390
+---[0.013023ms] com.secusoft.xxxx.model.vo.xxxxVO:getxxx() #392
....
8.线上关键方法监控
monitor 监控方法执行
[arthas@19715]$ monitor -c 5 com.secusoft.xxxx.service.impl.xxxxxServiceImpl xxxxxx
Press Q or Ctrl+C to abort.
Affect(class count: 3 , method count: 1) cost in 409 ms, listenerId: 6
timestamp class method total success fail avg-rt(m fail-rate
s)
-----------------------------------------------------------------------------------------------------------------------------------------
2021-03-24 15:53:06 com.secusoft.xxxx.service. xxxxxx 1 1 0 2045.22 0.00%
impl.xxxxxServiceImpl
timestamp class method total success fail avg-rt(m fail-rate
s)
-----------------------------------------------------------------------------------------------------------------------------------------
2021-03-24 15:53:11 com.secusoft.xxxx.service. xxxxxx 0 0 0 0.00 0.00%
impl.xxxxxServiceImpl
timestamp class method total success fail avg-rt(m fail-rate
s)
-----------------------------------------------------------------------------------------------------------------------------------------
2021-03-24 15:53:16 com.secusoft.xxxx.service. xxxxxx 1 1 0 1021.23 0.00%
impl.xxxxxServiceImpl
timestamp class method total success fail avg-rt(m fail-rate
s)
-----------------------------------------------------------------------------------------------------------------------------------------
2021-03-24 15:53:21 com.secusoft.xxxx.service. xxxxxx 0 0 0 0.00 0.00%
impl.xxxxxServiceImpl
最后
以上就是诚心镜子为你收集整理的Arthas的基础使用(二)的全部内容,希望文章能够帮你解决Arthas的基础使用(二)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复