Skip to content

Commit 0b03b02

Browse files
committed
code cleanup
1 parent 72101a8 commit 0b03b02

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

show-busy-java-threads

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,15 @@ while true; do
187187
;;
188188
esac
189189
done
190+
190191
count=${count:-5}
191-
use_ps=${use_ps:-false}
192+
193+
update_delay=${1:-0}
194+
[ -z "$1" ] && update_count=1 || update_count=${2:-0}
195+
(( update_count < 0 )) && update_count=0
196+
192197
top_delay=${top_delay:-0.5}
198+
use_ps=${use_ps:-false}
193199

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

220-
update_delay=${1:-0}
221-
[ -z "$1" ] && update_count=1 || update_count=${2:-0}
222-
(( update_count < 0 )) && update_count=0
223-
224226
################################################################################
225227
# check the existence of jstack command
226228
################################################################################
@@ -291,13 +293,13 @@ __top_threadId_cpu() {
291293
# HOME="$tmp_store_dir" top -H -b -n 1 -o '%CPU'
292294
# 2. change HOME env var when run top,
293295
# so as to prevent top command output format being change by .toprc user config file unexpectedly
294-
# 3. use option `-d 0.5`(interval 0.5 second) and `-n 2`(show 2 times), and use second time update data
295-
# to get cpu percentage of thread in 0.5 second interval
296+
# 3. use option `-d 0.5`(update interval 0.5 second) and `-n 2`(update 2 times),
297+
# and use second time update data to get cpu percentage of thread in 0.5 second interval
296298
HOME="$tmp_store_dir" top -H -b -d $top_delay -n 2 |
297299
awk '{
298-
if (idx == 3 && $NF == "java") # $NF is command
300+
if (idx == 3 && $NF == "java") # $NF(last field) is command field
299301
# only print 4th text block(idx == 3), aka. process info of second top update
300-
print $1 " " $9 # $1 is thread id, $9 is %cpu
302+
print $1 " " $9 # $1 is thread id field, $9 is %cpu field
301303
if ($0 == "")
302304
idx++
303305
}' | sort -k2,2nr

0 commit comments

Comments
 (0)