Last active
August 29, 2015 14:18
-
-
Save aminamid/98809e7ca0b9ba64e41c to your computer and use it in GitHub Desktop.
pstack one liner
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
sed -e ":a;N;s/\(abc\)\n\(def\)/\1\2/;t a;P;D" | |
sed -e ":a;N;s/\n\([^T].*\) .* in \(.*\)/ \2/;t a;P;D" | sed "s/Thread .* (Thread .* (LWP \(.*\))): \(.*\)/\1 \2/; s/ from [^ ]*\($\| \)/ /g; s/@@GLIBC[^ ]*//g; s/ ()\($\| \)/--/g; s/([^)]*)/()/g; s/ \[[^]]\+\]/\[\]/g; s/<[^<>]*>/<>/g; s/<\([^<>]*<>[^<>]*\)\{1,\}>/<<>>/g; s/<\([^<>]*<<>>[^<>]*\)\{1,\}>/<<<>>>/g; s/<\([^<>]*<<<>>>[^<>]*\)\{1,\}>/<<<<>>>>/g; s/ /-/2g " | awk '{print $2}' | sort | uniq -c | sort -nk1 | |
pstack 26459 | sed -e ":a;N;s/\n\([^T].*\) .* in \(.*\)/ \2/;t a;P;D" | sed "s/Thread .* (Thread .* (LWP \(.*\))): \(.*\)/\1 \2/; s/ from [^ ]*\($\| \)/ /g; s/@@GLIBC[^ ]*//g; s/ ()\($\| \)/--/g; s/([^)]*)/()/g; s/ \[[^]]\+\]/\[\]/g; s/<[^<>]*>/{}/g; s/<[^<>]*>/{}/g; s/<[^<>]*>/{}/g;s/<[^<>]*>/{}/g;s/{}/<>/g; s/ /-/2g " | awk '{print $2}' | | |
sort | uniq -c | sort -nk1 | |
pstack $(pgrep mta) | sed -e ":a;N;s/\n\([^T].*\) .* in \(.*\)/ \2/;t a;P;D" | sed -e "s/Thread .* (Thread .* (LWP \(.*\))): \(.*\)/\1 \2/; s/ from [^ ]*\($\| \)/ /g; s/@@GLIBC[^ ]*//g; s/ () /--/g; s/([^)]*)/()/g;" | sed "s/pthread_cond_timedwait/condwait/g; s/SimpleCondition::timedwaitrel_millis()/SCTWmil/g; s/Condition::waitButTimeout/CondWait/g | |
#!/bin/bash | |
# from stackoverflow http://stackoverflow.com/questions/3342889/how-to-measure-separate-cpu-core-usage-for-a-process | |
# Note: These stats are based on process lifetime, not the last X seconds, so | |
# you'll need to restart your process to reset the counter. | |
pids=() | |
while [ $# != 0 ]; do | |
pids=("${pids[@]}" "$1") | |
shift | |
done | |
if [ -z "${pids[0]}" ]; then | |
echo "Usage: $0 <pid1> [pid2] ..." | |
exit 1 | |
fi | |
for pid in "${pids[@]}"; do | |
if [ ! -e /proc/$pid ]; then | |
echo "Error: pid $pid doesn't exist" | |
exit 1 | |
fi | |
done | |
declare -A tmp_ | |
while [ true ]; do | |
declare -A H | |
for pid in "${pids[@]}"; do | |
eval $(pstack $pid | sed -e ":a;N;s/\n\([^T].*\) .* in \(.*\)/ \2/;t a;P;D" | sed -e "s/Thread .* (Thread .* (LWP \(.*\))): \(.*\)/\1 \2/; s/ from [^ ]*\($\| \)/ /g; s/@@GLIBC[^ ]*//g; s/ ()\($\| \)/--/g; s/([^)]*)/()/g;" | sed 's/\(.*\) \(.*\)/ H\["\1"\]="\2"; /g') | |
tmp_["$pid"]="$(ps -p $pid -L -o tid,pid,psr,pcpu,comm,tid | grep -v TID | sed -e "s/ \([^ ]*\)$/\${H[\1]};/; s/.*/echo &/;" )" | |
done | |
for pid in "${pids[@]}"; do | |
eval ${tmp_[$pid]} | sort -rnk4 | head -40 | sort -nk1 | |
done | |
sleep 10 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment