@@ -187,9 +187,15 @@ while true; do
187187 ;;
188188 esac
189189done
190+
190191count=${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+
192197top_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.
195201if [ -n " $append_file " ]; then
@@ -217,10 +223,6 @@ if [ -n "$jstack_file_dir" ]; then
217223 fi
218224fi
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