Created
August 28, 2012 10:05
-
-
Save emres/3496817 to your computer and use it in GitHub Desktop.
Prints information about the Java threads that consumes most of the CPU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Prints information about the Java threads that consumes most of the CPU | |
# Derived from the information given in the blog entry at | |
# | |
# http://nurkiewicz.blogspot.be/2012/08/which-java-thread-consumes-my-cpu.html | |
# | |
# Changelog: | |
# | |
# - Removed the `top', `perl', and `grep' dependencies. | |
# - Used a single command chain (instead of two, as done in the original blog | |
# entry) to assign two columns (process id and thread id) to an array variable. | |
# | |
# TO DO: | |
# | |
# - Remove `sort' dependency and use --sort of `ps' (variations of --sort=cpu, pcpu, c | |
# + / - did not sort according to CPU utilization). More research required for less | |
# dependency. | |
# | |
# - More testing required (as usual). | |
IDS=($(ps -fLC java | sort -rnk5 | head -n1 | cut -d' ' -f9,13)) | |
PID=${IDS[0]} | |
NID=$(printf "%x" ${IDS[1]}) | |
jstack $PID | grep -A500 $NID | grep -m1 "^$" -B 500 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment