Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Jun 10, 2018
1 parent 72101a8 commit 0b03b02
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions show-busy-java-threads
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,15 @@ while true; do
;;
esac
done

count=${count:-5}
use_ps=${use_ps:-false}

update_delay=${1:-0}
[ -z "$1" ] && update_count=1 || update_count=${2:-0}
(( update_count < 0 )) && update_count=0

top_delay=${top_delay:-0.5}
use_ps=${use_ps:-false}

# check the directory of append-file(-a) mode, create if not exsit.
if [ -n "$append_file" ]; then
Expand Down Expand Up @@ -217,10 +223,6 @@ if [ -n "$jstack_file_dir" ]; then
fi
fi

update_delay=${1:-0}
[ -z "$1" ] && update_count=1 || update_count=${2:-0}
(( update_count < 0 )) && update_count=0

################################################################################
# check the existence of jstack command
################################################################################
Expand Down Expand Up @@ -291,13 +293,13 @@ __top_threadId_cpu() {
# HOME="$tmp_store_dir" top -H -b -n 1 -o '%CPU'
# 2. change HOME env var when run top,
# so as to prevent top command output format being change by .toprc user config file unexpectedly
# 3. use option `-d 0.5`(interval 0.5 second) and `-n 2`(show 2 times), and use second time update data
# to get cpu percentage of thread in 0.5 second interval
# 3. use option `-d 0.5`(update interval 0.5 second) and `-n 2`(update 2 times),
# and use second time update data to get cpu percentage of thread in 0.5 second interval
HOME="$tmp_store_dir" top -H -b -d $top_delay -n 2 |
awk '{
if (idx == 3 && $NF == "java") # $NF is command
if (idx == 3 && $NF == "java") # $NF(last field) is command field
# only print 4th text block(idx == 3), aka. process info of second top update
print $1 " " $9 # $1 is thread id, $9 is %cpu
print $1 " " $9 # $1 is thread id field, $9 is %cpu field
if ($0 == "")
idx++
}' | sort -k2,2nr
Expand Down

0 comments on commit 0b03b02

Please sign in to comment.