Skip to content

Instantly share code, notes, and snippets.

@hhue13
Last active August 27, 2021 15:10
Show Gist options
  • Save hhue13/d392b6719a11963c23e426da196743c3 to your computer and use it in GitHub Desktop.
Save hhue13/d392b6719a11963c23e426da196743c3 to your computer and use it in GitHub Desktop.
Based on a J9 thread dump print out the thread name, Thread-id and used CPU. Invoke it from the command line like: cat javacore.20210827.090629.1350.0004.txt | gawk -f ~/data/projects/pva/getCpuPerThread.awk | sort -n
BEGIN {
FS=" "
threadName = ""
threadId = ""
threadNameRegEx = "/^.*\s+(\".*\")\s+.*/"
cpuTime = -1
print "cpuTime;threadName;threadId"
}
/.*3XMTHREADINFO .*/ { handleThreadInfo() }
/.*3XMCPUTIME .*/ { handleCpuTime() }
###################################################################################
## Get the thread info
###################################################################################
function handleThreadInfo() {
row=$0
threadName=gensub(/^.*\s+(\".*\")\s+.*/, "\\1" , "g", row)
threadId=gensub(/^.*java\/lang\/Thread\:(.*), state.*/, "\\1" , "g", row)
}
###################################################################################
## Total CPU time in column 5
###################################################################################
function handleCpuTime() {
cpuTime=$5
print cpuTime ";" threadName ";" threadId
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment