Skip to content

Commit 7894528

Browse files
committed
refactor(show-busy-java-threads): extract timestamp var to avoid inconsistency ⌚️
1 parent 31e1087 commit 7894528

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

bin/show-busy-java-threads

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,9 @@ cleanupWhenExit() {
376376
trap cleanupWhenExit EXIT
377377

378378
headInfo() {
379+
local timestamp=$1
379380
colorPrint "0;34;42" ================================================================================
380-
printf '%s\n' "$(date "+%Y-%m-%d %H:%M:%S.%N") [$((update_round_num + 1))/$update_count]: $(printCallingCommandLine)"
381+
printf '%s\n' "$timestamp [$((update_round_num + 1))/$update_count]: $(printCallingCommandLine)"
381382
colorPrint "0;34;42" ================================================================================
382383
echo
383384
}
@@ -567,17 +568,18 @@ printStackOfThreads() {
567568
}
568569

569570
main() {
570-
local update_round_num
571+
local update_round_num timestamp
571572
# if update_count <= 0, infinite loop till user interrupted (eg: CTRL+C)
572573
for ((update_round_num = 0; update_count <= 0 || update_round_num < update_count; ++update_round_num)); do
573574
((update_round_num > 0)) && {
574575
sleep "$update_delay"
575576
normalOutput
576577
}
577578

578-
[[ -n "$append_file" || -n "$store_dir" ]] && headInfo |
579+
timestamp=$(date "+%Y-%m-%d %H:%M:%S.%N")
580+
[[ -n "$append_file" || -n "$store_dir" ]] && headInfo "$timestamp" |
579581
tee ${append_file:+-a "$append_file"} ${store_dir:+-a "$store_file_prefix$PROG"} >/dev/null
580-
((update_count != 1)) && headInfo
582+
((update_count != 1)) && headInfo "$timestamp"
581583

582584
if [ "$cpu_sample_interval" = 0 ]; then
583585
findBusyJavaThreadsByPs

0 commit comments

Comments
 (0)