Skip to content

Commit 0e74f68

Browse files
committed
add -d|--top-delay option
1 parent 5f1c5cc commit 0e74f68

File tree

2 files changed

+39
-28
lines changed

2 files changed

+39
-28
lines changed

docs/java.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,29 @@ Example:
9494
show-busy-java-threads 3 10 # update every 3 seconds, update 10 times
9595

9696
Options:
97-
-p, --pid <java pid> find out the highest cpu consumed threads from the specifed java process,
97+
-p, --pid <java pid> find out the highest cpu consumed threads from the specified java process,
9898
default from all java process.
99-
-c, --count <num> set the thread count to show, default is 5
100-
-a, --append-file <file> specify the file to append output as log
99+
-c, --count <num> set the thread count to show, default is 5.
100+
-a, --append-file <file> specifies the file to append output as log.
101101
-P, --use-ps use ps command to find busy thread(cpu usage) instead of top command,
102102
default use top command, because cpu usage of ps command is expressed as
103103
the percentage of time spent running during the entire lifetime of a process,
104104
this is not ideal.
105-
-s, --jstack-path <path> specify the path of jstack command
106-
-S, --jstack-file-dir <path> specify the dir for storing jstack output files, and keep files.
105+
-d, --top-delay specifies the delay between top samples, default is 0.5 (second).
106+
get thread cpu percentage during this delay interval.
107+
more info see top -d option. eg: -d 1 (1 second).
108+
-s, --jstack-path <path> specifies the path of jstack command.
109+
-S, --jstack-file-dir <path> specifies the dir for storing jstack output files, and keep files.
107110
default store jstack output files at tmp dir, and auto remove after run.
108111
use this option to keep files so as to review jstack later.
109-
-F, --force set jstack to force a thread dump
110-
use when jstack <pid> does not respond (process is hung)
111-
-m, --mix-native-frames set jstack to print both java and native frames (mixed mode)
112-
-l, --lock-info set jstack with long listing. Prints additional information about locks
113-
-h, --help display this help and exit
114-
delay the delay between updates in seconds
115-
count the number of updates
116-
delay/count arguments imitates the style of vmstat command
112+
-F, --force set jstack to force a thread dump.
113+
use when jstack <pid> does not respond (process is hung).
114+
-m, --mix-native-frames set jstack to print both java and native frames (mixed mode).
115+
-l, --lock-info set jstack with long listing. Prints additional information about locks.
116+
-h, --help display this help and exit.
117+
delay the delay between updates in seconds.
118+
count the number of updates.
119+
delay/count arguments imitates the style of vmstat command.
117120
```
118121
119122
### 示例

show-busy-java-threads

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,29 @@ Example:
8383
${PROG} 3 10 # update every 3 seconds, update 10 times
8484
8585
Options:
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.
106109
EOF
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
123126
eval 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
171178
done
172179
count=${count:-5}
173180
use_ps=${use_ps:-false}
181+
top_delay=${top_delay:-0.5}
174182

175183
if [ -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

Comments
 (0)