@@ -83,26 +83,29 @@ Example:
8383 ${PROG} 3 10 # update every 3 seconds, update 10 times
8484
8585Options:
86- -p, --pid <java pid> find out the highest cpu consumed threads from the specifed java process,
86+ -p, --pid <java pid> find out the highest cpu consumed threads from the specified java process,
8787 default from all java process.
88- -c, --count <num> set the thread count to show, default is 5
89- -a, --append-file <file> specify the file to append output as log
88+ -c, --count <num> set the thread count to show, default is 5.
89+ -a, --append-file <file> specifies the file to append output as log.
9090 -P, --use-ps use ps command to find busy thread(cpu usage) instead of top command,
9191 default use top command, because cpu usage of ps command is expressed as
9292 the percentage of time spent running during the entire lifetime of a process,
9393 this is not ideal.
94- -s, --jstack-path <path> specify the path of jstack command
95- -S, --jstack-file-dir <path> specify the dir for storing jstack output files, and keep files.
94+ -d, --top-delay specifies the delay between top samples, default is 0.5 (second).
95+ get thread cpu percentage during this delay interval.
96+ more info see top -d option. eg: -d 1 (1 second).
97+ -s, --jstack-path <path> specifies the path of jstack command.
98+ -S, --jstack-file-dir <path> specifies the dir for storing jstack output files, and keep files.
9699 default store jstack output files at tmp dir, and auto remove after run.
97100 use this option to keep files so as to review jstack later.
98- -F, --force set jstack to force a thread dump
99- use when jstack <pid> does not respond (process is hung)
100- -m, --mix-native-frames set jstack to print both java and native frames (mixed mode)
101- -l, --lock-info set jstack with long listing. Prints additional information about locks
102- -h, --help display this help and exit
103- delay the delay between updates in seconds
104- count the number of updates
105- delay/count arguments imitates the style of vmstat command
101+ -F, --force set jstack to force a thread dump.
102+ use when jstack <pid> does not respond (process is hung).
103+ -m, --mix-native-frames set jstack to print both java and native frames (mixed mode).
104+ -l, --lock-info set jstack with long listing. Prints additional information about locks.
105+ -h, --help display this help and exit.
106+ delay the delay between updates in seconds.
107+ count the number of updates.
108+ delay/count arguments imitates the style of vmstat command.
106109EOF
107110
108111 exit $exit_code
@@ -118,7 +121,7 @@ uname | grep '^Linux' -q || fatal "Error: $PROG only support Linux, not support
118121# parse options
119122# ###############################################################################
120123
121- readonly ARGS=` getopt -n " $PROG " -a -o p:c:a:s:S:PFmlh -l count:,pid:,append-file:,jstack-path:,jstack-file-dir:,use-ps,force,mix-native-frames,lock-info,help -- " $@ " `
124+ readonly ARGS=` getopt -n " $PROG " -a -o p:c:a:s:S:Pd:Fmlh -l count:,pid:,append-file:,jstack-path:,jstack-file-dir:,use-ps,top-delay: ,force,mix-native-frames,lock-info,help -- " $@ " `
122125[ $? -ne 0 ] && usage 1
123126eval set -- " ${ARGS} "
124127
@@ -148,6 +151,10 @@ while true; do
148151 use_ps=true
149152 shift
150153 ;;
154+ -d|--top-delay)
155+ top_delay=" $2 "
156+ shift 2
157+ ;;
151158 -F|--force)
152159 force=-F
153160 shift
@@ -171,6 +178,7 @@ while true; do
171178done
172179count=${count:- 5}
173180use_ps=${use_ps:- false}
181+ top_delay=${top_delay:- 0.5}
174182
175183if [ -n " $jstack_file_dir " -a -e " $jstack_file_dir " ]; then
176184 if [ ! -d " $jstack_file_dir " ]; then
@@ -310,7 +318,7 @@ __top_threadId_cpu() {
310318 # so as to prevent top command output format being change by .toprc user config file unexpectedly
311319 # 3. use option `-d 0.1`(interval 0.1 second) and `-n 2`(show 2 times), and use second time update data
312320 # to get cpu percentage of thread in 0.1 second interval
313- HOME=" $tmp_store_dir " top -H -b -d 0.1 -n 2 |
321+ HOME=" $tmp_store_dir " top -H -b -d $top_delay -n 2 |
314322 awk ' {
315323 if (idx == 3 && $0 != "")
316324 # only print 4th text block
0 commit comments