java cpu多线程测试_检测最耗cpu的线程的脚本

之前也整理了,经过4年改进,现在功能丰富和完善程度很高了,可以看看试试,哈哈

用于快速排查Java的CPU性能问题(top us值过高),自动查出运行的Java进程中消耗CPU多的线程,并打印出其线程栈,从而确定导致性能问题的方法调用。

用法

show-busy-java-threads.sh

# 从 所有的 Java进程中找出最消耗CPU的线程(缺省5个),打印出其线程栈。

show-busy-java-threads.sh -c

show-busy-java-threads.sh -c -p

# -F选项:执行jstack命令时加上-F选项(强制jstack),一般情况不需要使用

show-busy-java-threads.sh -p -F

show-busy-java-threads.sh -s

# 对于sudo方式的运行,JAVA_HOME环境变量不能传递给root,

# 而root用户往往没有配置JAVA_HOME且不方便配置,

# 显式指定jstack命令的路径就反而显得更方便了

show-busy-java-threads.sh -a

# 记录到文件以方便回溯查看

show-busy-java-threads.sh []

# 多次执行;这2个参数的使用方式类似vmstat命令

##############################

# 注意:

##############################

# 如果Java进程的用户 与 执行脚本的当前用户 不同,则jstack不了这个Java进程。

# 为了能切换到Java进程的用户,需要加sudo来执行,即可以解决:

sudo show-busy-java-threads.sh

# 帮助信息

$ show-busy-java-threads.sh -h

Usage: show-busy-java-threads.sh [OPTION]… [delay [count]]

Find out the highest cpu consumed threads of java, and print the stack of these threads.

Example:

show-busy-java-threads.sh # show busy java threads info

show-busy-java-threads.sh 1 # update every 1 seconds, (stop by eg: CTRL+C)

show-busy-java-threads.sh 3 10 # update every 3 seconds, update 10 times

Options:

-p, –pid find out the highest cpu consumed threads from the specifed java process,

default from all java process.

-c, –count set the thread count to show, default is 5

-a, –append-file specify the file to append output as log

-s, –jstack-path specify the path of jstack command

-F, –force set jstack to force a thread dump(use jstack -F option)

-h, –help display this help and exit

delay the delay between updates in seconds

count the number of updates

delay/count arguments imitates style of vmstat command

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值