Created
September 16, 2012 22:19
-
-
Save ahgittin/3734619 to your computer and use it in GitHub Desktop.
script to run jstack but just show those threads which are active ... a poor man's profiler, or how to make eclipse beach ball slightly more exciting :)
This file contains 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 | |
jstack $@ | awk ' | |
function onTraceBegin() { | |
onTraceEnd() | |
data["lineCount"]=0 | |
data["head"]=$0 | |
} | |
function onTraceEnd() { | |
if ("head" in data) { | |
if (data["active"] && "topClass" in data) { | |
print data["head"] | |
for (l=1; l<=data["lineCount"]; l++) { print lines[l] } | |
print "" | |
} | |
} | |
delete lines | |
delete data | |
} | |
function startsWith(whole,prefix) { | |
return (substr(whole,1,length(prefix))==prefix); | |
} | |
{ | |
if (!match($0,"[^\\s]")) onTraceEnd(); | |
else if (substr($0,1,1)=="\"") onTraceBegin(); | |
else if ("head" in data) { | |
lc = ++data["lineCount"]; | |
lines[lc]=$0 | |
if (lc==1) { | |
state=data["state"]=$2; | |
data["active"] = !(state=="WAITING" || state=="BLOCKED" || state=="TIMED_WAITING") | |
} | |
if ($1=="at") { | |
if ("topClass" in data) { | |
} else { | |
data["topClass"] = $0; | |
tc = $2; | |
if (data["active"]) { | |
if (startsWith(tc,"java.net") || startsWith(tc,"sun.nio")) data["active"]=false; | |
} | |
} | |
} | |
} | |
} | |
END { | |
onTraceEnd(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment