2121
2222# NOTE: DO NOT declare var PROG as readonly, because its value is supplied by subshell.
2323PROG=" $( basename " $0 " ) "
24+ readonly PROG
2425readonly PROG_VERSION=' 2.5.0-dev'
2526# choosing between $0 and BASH_SOURCE
2627# https://stackoverflow.com/a/35006505/922688
@@ -35,6 +36,7 @@ readonly -a COMMAND_LINE=("${BASH_SOURCE[0]}" "$@")
3536#
3637# NOTE: DO NOT declare var USER as readonly, because its value is supplied by subshell.
3738USER=" $( whoami) "
39+ readonly USER
3840
3941# ###############################################################################
4042# util functions
@@ -219,6 +221,7 @@ ARGS=$(
219221 echo
220222 usage 1
221223}
224+ readonly ARGS
222225eval set -- " ${ARGS} "
223226
224227count=5
@@ -265,7 +268,7 @@ while true; do
265268 shift
266269 ;;
267270 -l | --lock-info)
268- more_lock_info =-l
271+ lock_info =-l
269272 shift
270273 ;;
271274 -h | --help)
@@ -281,16 +284,19 @@ while true; do
281284 esac
282285done
283286
284- update_delay=${1:- 0}
287+ readonly count cpu_sample_interval force mix_native_frames lock_info
288+ readonly update_delay=${1:- 0}
285289isNonNegativeFloatNumber " $update_delay " || die " update delay($update_delay ) is not a non-negative float number!"
286290
287291[ -z " $1 " ] && update_count=1 || update_count=${2:- 0}
288292isNaturalNumber " $update_count " || die " update count($update_count ) is not a natural number!"
293+ readonly update_count
289294
290295if [ -n " $pid_list " ]; then
291296 pid_list=" ${pid_list// [[:space:]]/ } " # delete white space
292297 isNaturalNumberList " $pid_list " || die " pid(s)($pid_list ) is illegal! example: 42 or 42,99,67"
293298fi
299+ readonly pid_list
294300
295301# check the directory of append-file(-a) mode, create if not exist.
296302if [ -n " $append_file " ]; then
@@ -307,6 +313,7 @@ if [ -n "$append_file" ]; then
307313 fi
308314 fi
309315fi
316+ readonly append_file
310317
311318# check store directory(-S) mode, create directory if not exist.
312319if [ -n " $store_dir " ]; then
@@ -317,6 +324,7 @@ if [ -n "$store_dir" ]; then
317324 mkdir -p " $store_dir " || die " fail to create directory $store_dir (specified by option -S, for storing output files)!"
318325 fi
319326fi
327+ readonly store_dir
320328
321329isNonNegativeFloatNumber " $cpu_sample_interval " || die " cpu sample interval($cpu_sample_interval ) is not a non-negative float number!"
322330
@@ -349,13 +357,15 @@ elif command -v jstack &>/dev/null; then
349357else
350358 die " jstack NOT found by JAVA_HOME(${JAVA_HOME:- not set} ) setting and PATH!${nl} Use -s option set jstack path manually."
351359fi
360+ readonly jstack_path
352361
353362# ###############################################################################
354363# biz logic
355364# ###############################################################################
356365
357366# NOTE: DO NOT declare var run_timestamp as readonly, because its value is supplied by subshell.
358367run_timestamp=" $( date " +%Y-%m-%d_%H:%M:%S.%N" ) "
368+ readonly run_timestamp
359369readonly uuid=" ${PROG} _${run_timestamp} _${$} _${RANDOM} "
360370
361371readonly tmp_store_dir=" /tmp/${uuid} "
@@ -520,7 +530,7 @@ printStackOfThreads() {
520530 local jstackFile=" ${store_file_prefix} $(( update_round_num + 1 )) _jstack_${pid} "
521531 [ -f " ${jstackFile} " ] || {
522532 # shellcheck disable=SC2206
523- local -a jstack_cmd_line=(" $jstack_path " ${force} $mix_native_frames $more_lock_info ${pid} )
533+ local -a jstack_cmd_line=(" $jstack_path " ${force} $mix_native_frames $lock_info ${pid} )
524534 if [ " ${user} " == " ${USER} " ]; then
525535 # run without sudo, when java process user is current user
526536 logAndRun " ${jstack_cmd_line[@]} " > " ${jstackFile} "
0 commit comments