美文网首页
使用arthas定位耗时CPU的线程

使用arthas定位耗时CPU的线程

作者: 十毛tenmao | 来源:发表于2021-10-18 23:44 被阅读0次

在分析CPU占用率很高的线程以及问题定位时,一般都是使用top和jstack命令,但是整个过程比较慢,确实使用arthas就可以非常快速地定位到耗时最快的线程

使用arthas

https://arthas.aliyun.com/doc/quick-start.html

curl -O https://arthas.aliyun.com/arthas-boot.jar
java -jar arthas-boot.jar

定位CPU占用率最高的线程

  • 按照CPU使用率排序,并展示前n个线程
thread -n {number}
[arthas@1]$ thread -n 1
"arthas-command-execute" Id=8286 cpuUsage=0.4% deltaTime=0ms time=22ms 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:206)
    at com.taobao.arthas.core.command.monitor200.ThreadCommand.process(ThreadCommand.java:122)
    at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.process(AnnotatedCommandImpl.java:82)
    at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.access$100(AnnotatedCommandImpl.java:18)
    at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:111)
    at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:108)
    at com.taobao.arthas.core.shell.system.impl.ProcessImpl$CommandProcessTask.run(ProcessImpl.java:385)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    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)
  • 展示指定线程的线程栈
thread [pid]
[arthas@1]$ thread 3422
"grpc-default-executor-2" Id=3422 TIMED_WAITING on java.util.concurrent.SynchronousQueue$TransferStack@56b72395
    at sun.misc.Unsafe.park(Native Method)
    -  waiting on java.util.concurrent.SynchronousQueue$TransferStack@56b72395
    at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
    at java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:460)
    at java.util.concurrent.SynchronousQueue$TransferStack.transfer(SynchronousQueue.java:362)
    at java.util.concurrent.SynchronousQueue.poll(SynchronousQueue.java:941)
    at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1073)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

为什么有时候CPU使用率排第一的线程状态是WAITING?

在定位问题的时候,发现CPU使用率最高的线程的状态是WAITING,一个在等待的线程怎么可能占用CPU呢? 实际上这是因为CPU使用率的计算是通过采样的方式得到的,并不是当前时刻的CPU使用率,所以原因是在进入WAITING之前,占用了很多的CPU

相关文章

  • 使用arthas定位耗时CPU的线程

    在分析CPU占用率很高的线程以及问题定位时,一般都是使用top和jstack命令,但是整个过程比较慢,确实使用ar...

  • CPU%100问题排查

    1、找到最耗CPU的进程2、找到最耗CPU的线程3、查看堆栈,定位线程,定位对应代码 步骤一、找到最耗CPU的进程...

  • cpu使用率过高问题排查步骤

    1、查看cpu占用情况 2、查看占用资源最高的进程的线程情况 3、通过以上线程CPU切片查找耗时最多CPU占用最大...

  • day18 多线程 2018-08-08

    多线程类似于同时执行多个不同程序,可以将耗时任务搁置到后台运行, 提高CPU利用率python中多线程的使用方法:...

  • 线上java程序CPU占用过高问题排查

    top 命令查看CPU、内存等使用情况 定位问题线程 ps -mp pid -o THREAD,tid,time ...

  • 如何定位消耗CPU最多的线程

    如何定位消耗CPU最多的线程查看哪个进程占用CPU最高top进程里所有线程的cpu消耗情况top -Hp 转换线...

  • 你知道有哪些情况会导致app卡顿,分别可以用什么方法来避免?

    分cpu卡和gpu卡顿。 主线程耗时操作线程爆炸滑动页面渲染卡顿(离屏渲染)图像渲染解码 查看xcode的cpu占...

  • UNTITLED

    JVM 1、CPU占用过多如何定位 top 定位哪个进程对CPU占用最高(获取进程ID) ps 定位哪个线程引起C...

  • 多线程的基本概念的理解

    模拟耗时操作 耗时操作对UI的影响 : 会卡死UI / 界面 / 主线程 如何解决耗时操作卡死主线程? 使用多线程...

  • 多线程之一

    处理耗时操作:不使用多线程 在iOS开发中,经常会遇到一些耗时操作,如果不使用多线程,将耗时操作放在主线程中,将会...

网友评论

      本文标题:使用arthas定位耗时CPU的线程

      本文链接:https://www.haomeiwen.com/subject/aiuooltx.html