之前也整理了,经过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