6

linux线上CPU100%排查

 2 years ago
source link: https://segmentfault.com/a/1190000040763437
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

如何定位是哪个服务进程导致CPU过载,哪个线程导致CPU过载,哪段代码导致CPU过载 .

找出系统中占用CPU最高的线程PID

  • -c 显示服务完整的路径和名称
> top -c

image-20210509230435723

  • 不要退出top,直接输入P(必须大写),让CPU利用率从大到小排列

比如找到的进程ID是1584

找到最耗CPU的线程

一个进程下面一般会有很多的线程,每个线程对CPU的使用率也是不一样的,我们需要找到最耗CPU的线程ID

top -Hp 1584 ,显示一个进程的线程运行信息列表

  • H打印线程信息
  • p指定pid

image-20210509230929685

同样不要退出top,键入P (大写p),线程按照CPU使用率排序

比如我们找到CPU使用率使用率最高的线程ID是1592

将线程PID转化为16进制

> printf "%x" 1592
638
> jstack 1584 | grep ‘0x638’ -C5 --color

这样就可以找到引起CPU使用率过高的问题代码位置。

原文链接:https://rumenz.com/rumenbiji/...
微信公众号:入门小站


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK